Java : JAX-WS 2.0 Client with JAXB unmarshaller

This page last changed on Sep 27, 2006 by Kees de Kooter

Intro

JAX-WS 2.0 aka JSR-224 is the Web Services specification of the JEE 5 stack. The documentation of Sun is very limited, they basically assume you just generate all code using one of their tools. Here is an attempt to describe a manual-code-centric approach.

Dependencies


    <dependency>
      <groupId>javax.xml</groupId>
      <artifactId>jaxb-api</artifactId>
      <version>2.0</version>
    </dependency>
    <dependency>
      <groupId>javax.xml</groupId>
      <artifactId>jaxb-impl</artifactId>
      <version>2.0.2</version>
    </dependency>
    <dependency>
      <groupId>javax.xml.ws</groupId>
      <artifactId>jaxws-api</artifactId>
      <version>2.0</version>
    </dependency>
    <dependency>
      <groupId>com.sun.xml</groupId>
      <artifactId>jaxws-rt</artifactId>
      <version>2.0.1</version>
    </dependency>
    <dependency>
      <groupId>com.sun.xml</groupId>
      <artifactId>jaxws-tools</artifactId>
      <version>2.0.1</version>
    </dependency>
    <dependency>
      <groupId>javax.xml.soap</groupId>
      <artifactId>saaj-api</artifactId>
      <version>1.3</version>
    </dependency>
    <dependency>
      <groupId>com.sun.xml.messaging.saaj</groupId>
      <artifactId>saaj-impl</artifactId>
      <version>1.3</version>
    </dependency>
    <dependency>
      <groupId>com.sun.xml.stream.buffer</groupId>
      <artifactId>streambuffer</artifactId>
      <version>0.1</version>
    </dependency>

Unfortunately the Maven repository is not up-to-date on these libraries so you have to do a lot of mvn install:install-file (sad).

JAX-WS uses StAX, so you also need to include a StAX implementation. I picked stax-1.2.0.

Basic Client Code with JAXB binding

After days of surfing I concluded that JAX-WS is so poorly documented that I do not have a clue of how to use it. I reverted to writing and the SOAP message myself. I turned out be take only a couple of lines of code. And it enabled me to use my own custom marshaller.

SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();

SOAPMessage message = messageFactory.createMessage();

Document document = documentBuilder.newDocument();

jaxbMarshaller.marshalToNode(payload, document);

message.getSOAPBody().addDocument(document);

SOAPConnection connection = connectionFactory.createConnection();
SOAPMessage response = connection.call(message, url);

Todos

Clean up the list of dependencies now that JAX-WS is not being used.

Resources