Web Services Experiences in Java

nationmattedSoftware and s/w Development

Nov 10, 2012 (4 years and 8 months ago)

192 views

Web Services

Experiences

Machiel Jansen


Vrije Universiteit (VU)

Amsterdam

Building web services in Java

Prior Experience: none.


Using NetBeans IDE:

Making Webservives on the fly


IDE generates stubs and hooks

Provides container and servlets


Pro’s and cons
-

SUN

Pro’s:

No need to write WSDL

Write application and ”publish” it as
webservice.

Cons:

Sun webservices want the Sun Application
Server


not in GT4.



Apache Axis

Axis can be easy.


Deploy your webservice rapidly (jws):


All public methods are available


But: Not configurable





Keep to global return datatypes

Apache Axis

Two approaches:


Start building application, or class library.


Let Axis generate WSDL
(?wsdl)


Write WSDL


Use WSDL2Java to generate stubs (clients)


and hooks (services)

Axis server side

More difficult side of WS

Serialize your datastructures:


Easy when you stick to:


Global types (int, double, String, array etc.)


Java beans (set and get methods)


Otherwise: write custom serializers.

Wrapping existing application

Execute application from Java.


(use runTime)

Redirect the output.

Deploy as webservice.


Wrapping existing application

public int run(String cmd, Writer out) throws IOException {

RunTime r = Runtime.getRuntime();

Process p = r.exec(cmd);


FileIO.copyFile(new InputStreamReader(p.getInputStream( )),

out, true);

try { p.waitFor( ); // wait for process to complete


} catch (InterruptedException e) {


return
-
1; }


return p.exitValue( );


}

WS Clients


3 types

Stub based


(easy: use
WSDL2Java
)


Service endpoint is static

Dynamic proxy


Service endpoint dynamically at runtime

Dynamic Invocation Interface (DII)


Discover services at runtime then invoke
methods


Clients
-

DII

Axis user guide uses Call object (DII) in
examples.


WSRF and GT4 examples uses stubs.





I used a DII client


should you?

DYNAMIC BUT HARDER THAN STUBS

// Register your (un)serializer



call.registerTypeMapping(Result.class, qm, new
org.apache.axis.encoding.ser.BeanSerializerFactory(Result.class, qm),


new org.apache.axis.encoding.ser.BeanDeserializerFactory(Result.class,
qm));



call.registerTypeMapping(Result[].class, ar,


new org.apache.axis.encoding.ser.ArraySerializerFactory(),


new org.apache.axis.encoding.ser.ArrayDeserializerFactory());

WSRF and GT4

Working on it.


You can work with GT4: use the WSCore library.

http://www
-
128.ibm.com/developerworks/edu/gr
-
dw
-
gr
-
eclipseide
-
i.html


Note: GT4 WSRF is a little different from Apache WSRF



GT4 uses GAR files and JNDI deployment.




Eclipse has a GT4 plugin…



What we would have liked…

INDEXER/

SEARCHER

CLIENT

NODE

NODE

NODE

Use Resource aware WS’s

on different nodes to process

indexes and search queries



WS on some nodes.

Use SRB or local storage.

user and system resources.


What we would like


part 2

Scenario taken from:

Building a grid using Web services standards.


http://www
-
128.ibm.com/developerworks/edu/gr
-
dw
-
gr
-
movie1
-
i.html?S_TACT=105AGX07&S_CMP=HP



Questions

How do we make good use of GT4


the WS enabled part?

How do we get access to GT4?

How are WS’s (best) used in PoC infrastructure?

Why use WS’s at all?

Why can’t we use a WS outside the PoC? Does it matter?


Technical hurdles still to take:


More experience in WSRF


Writing (de)serializers for custom datatypes.