File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes JAX-RPC and JAX-WS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "JAX-RPC and JAX-WS" Watch "JAX-RPC and JAX-WS" New topic
Author

JAX-RPC and JAX-WS

Andrew Black
Greenhorn

Joined: Sep 08, 2005
Posts: 6
I want to get a JSP (or rather Java code called by a JSP) to get data from a SOAP service. It has been suggested that JAX-RPC might be useful.
Two questions
- are there other aproaches worht considering
- I notice that JAX-RPC is being superceded by JAX-WS. What are the relative merits.

Any pointers would be useful


Andrew Black<br />London
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41863
    
  63
The other Java API to consider might be SAAJ, which operates on a lower level than JAX-RPC. You can find links to further material on both in the Web Services FAQ.

JAX-WS is a newer version (read: more features etc.) than JAX-RPC, but a final version has not been released yet. E.g., the popular Axis SOAP engine does not support it. I would stay away from it for the time being. Once it does get released, I would expect JAX-WS to be backwards-compatible with JAX-RPC, though, so any WS you develop today should run with little or no changes in JAX-WS.


Ping & DNS - my free Android networking tools app
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12785
    
    5
I have found some toolkits to be extrememly bulky - for example I created a client with the JWSDP version 1.6 and found that to support it on the customer's machine would take 10 meg of jar files.
Since the request format was always the same, I created a simple template that filled a couple of variables into constant Strings and sent it with a URLConnection. Grabbing the returned stream and parsing into plain XML was no problem.
At this point I am trying to use XPath to get the returned data, if that doesnt work, I'll use regular DOM methods.
Bill
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Ulf pretty much summed it up.

However while you can, you may want to forget, at least subconciously, about the "RPC" in JAX-RPC.
Think of it as JAX-WS 1.1 vs JAX-WS 2.0 (just don't actually say it out loud, you'll confuse people).
Doug Kohlert's Blog: JAX-RPC 2.0 renamed to JAX-WS 2.0
In the arena of RPC, SOAP Web services are fairly heavy-weight - if people keep using Web services for trivial RPC calls we'll end up with a copy of "Bitter Web Services" besides "Bitter EJB" on the bookshelf.

Sun's reference implementations (not for production use) of the APIs can be found in the Java Web Service Developer Packs.
Java Technology and Web Services Archives
JWSDP 1.6 (JAX-RPC 1.1)
JWSDP 2.0 (JAX-RPC 2.0)

Axis has its own JAX-RPC 1.1 implementation, just as many commercial application servers do.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by William Brogden:
At this point I am trying to use XPath to get the returned data, if that doesnt work, I'll use regular DOM methods.


As SUN seems bent on including JAXB in the Enterprise Platform you might as well try it. I got the JWSDP 1.6 JAXB 1.0 samples working with with just JSE 5.0 (1.5.02) and the following libraries from the JWSDP 1.6 distribution.
jaxb\lib\jaxb-api.jar
jaxb\lib\jaxb-impl.jar
jaxb\lib\jaxb-libs.ja
jaxb\lib\jaxb-xjc.jar (you only need this one to compile the bindings & ant task)
jwsdp-shared\lib\relaxngDatatype.jar
jwsdp-shared\lib\xsdlib.jar
(after which I stumbled on the JAXB Project site)

It's easier to work with than the other options, especially if you can live with the classes as generated. It takes a little longer if you want to customize the bindings.
SDN Article: Java Architecture for XML Binding (JAXB)
[ February 21, 2006: Message edited by: Peer Reynders ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12785
    
    5
I finally got the XPath approach to work after some frustration. The expression I ended up with typically looks like:


Which is used in an XPath statement like:

where soapResp is the org.w3c.dom.Document of the entire SOAP message and xpath is an XPath instance. By using a different expression String I can pull any returned data from the message. This approach results in a jar file to send to my customer that is only 11k in size and needs only Java 1.5 to run.

Harold's book _Processing XML with Java_ also uses SOAP message examples for xpath (ch16).
Bill
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by William Brogden:
I finally got the XPath approach to work after some frustration
...
Harold's book _Processing XML with Java_ also uses SOAP message examples for xpath (ch16).
Bill


Unfortunately there aren't many examples of XPath 1.0 being used on documents that use namespaces!
Fortunately with the JDK 1.5 XPath expressions with expanded-names are much easier if you supply a class implementing the
NamespaceContext Interface.
See selectNodeIterator() problem
[ February 22, 2006: Message edited by: Peer Reynders ]
Andrew Black
Greenhorn

Joined: Sep 08, 2005
Posts: 6
Thanks for the answers everyone. I am becoming clearer but I still don't understand the relationsship between JAXB and and RPC.
For example the tutorial I found on Suns site mentions JAXB but not RPC

Cheers
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12785
    
    5
Unfortunately there aren't many examples of XPath 1.0 being used on documents that use namespaces!
Fortunately with the JDK 1.5 XPath expressions with expanded-names are much easier if you supply a class implementing the

AHA!
THAT was why I had to use the "/descendant::" approach and the direct addressing of soap namespaced elements failed!
Just another example of why I love the Ranch - thanks Peer!
Bill
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Andrew Black:
but I still don't understand the relationsship between JAXB and and RPC.

JAXB is heavily used by JAX-WS 2.0. It's basically a code generator that looks at a specified XML Schema Definition and builds a Java unmarshaller, marshaller and object model to manipulate the information of XML documents that adhere to that schema.

It is part of the earlier JWSDPs as JAXB is one of the (by Sun) recommended technologies for XML document manipulation - in addition to SAX and DOM. JAXB is easier to use than SAX and may not require as much memory as DOM.

Lately StAX has been thrown into the mix � it�s a "Pull-Parser" while SAX is a "Push-Parser". Basically SAX tells you through "events" that it parsed the next item and you better do something with the information now - all the parsing is routed through one central event handler - with StAX you tell it when you are ready to process the next bit, so in addition to whatever you data you store your location within your logic also defines your parsing state.

Then of course there is TRaX that can help you with your XSLT work. Many of these XML manipulation technologies are joined under the JAXP umbrella.
JAXP 1.2 (XML 1.0, XML namespaces, XML Schema, XSLT 1.0 (TRaX), SAX 2.0, DOM Level 2)
JAXP 1.3 (XML 1.1, XML namespaces, XML Schema, XSLT 1.0 (TRaX), XPath 1.0, XInclude 1.0, DOM Level 3, SAX 2.0.2)
(Elliotte Rusty Harold's Processing XML with Java is a great resource.)

All these XML manipulation technologies are necessary as the primary purpose of SOAP Web Services is the exchange of (potentially large) XML documents which have to be created and later processed. RPC in the SOAP context is more of a "convenience feature" - the top level element of the SOAP payload isn't actually an XML document, it's simply an element representing a "message" to an operation that should process the contents of that "message" element.

Remember the expansion of the SOAP acronym "Simple Object Access Protocol" has been officially dropped - for a good reason. It's neither simple nor has it anything do with objects - its all about moving XML data in a controlled manner (with the inherent overhead). Those who try to use SOAP Web Services as a remoting mechanism for their ordinary (fine-grain) Java objects are likely to find the disappointment that was experienced by those who tried to do the same with EJB.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by William Brogden:
Just another example of why I love the Ranch - thanks Peer!
Bill

I had a hunch you might like that.
Glad to be of help.
 
 
subject: JAX-RPC and JAX-WS