<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MyArch &#187; JAX-WS</title>
	<atom:link href="http://myarch.com/category/jax-ws/feed" rel="self" type="application/rss+xml" />
	<link>http://myarch.com</link>
	<description>Builds and bytes</description>
	<lastBuildDate>Sat, 17 Mar 2012 14:13:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Will JAX-WS Become the Primary Mechanism for Invoking RESTful Services?</title>
		<link>http://myarch.com/will-jax-ws-become-the-primary-mechanism-for-invoking-restful-services</link>
		<comments>http://myarch.com/will-jax-ws-become-the-primary-mechanism-for-invoking-restful-services#comments</comments>
		<pubDate>Sun, 03 Jun 2007 01:15:40 +0000</pubDate>
		<dc:creator>Alexander Ananiev</dc:creator>
				<category><![CDATA[JAX-WS]]></category>
		<category><![CDATA[Web services]]></category>

		<guid isPermaLink="false">http://myarch.com/will-jax-ws-become-the-primary-mechanism-for-invoking-restful-services</guid>
		<description><![CDATA[Developers working with REST and XML/HTTP services have traditionally used light-weight APIs, such as java.net classes or Apache HttpClient. Web services APIs provided by JAX-RPC were SOAP and "enterprise" only and they required J2EE libraries. The situation changed with the release of JAX-WS and its inclusion into Java SE 6. JAX-WS supports RESTful services; also, [...]]]></description>
			<content:encoded><![CDATA[ <p>
Developers working with REST and XML/HTTP services have traditionally used light-weight APIs, such as java.net classes or <a href="http://jakarta.apache.org/commons/httpclient/">Apache HttpClient</a>. Web services APIs provided  by JAX-RPC were SOAP and "enterprise" only and  they required J2EE libraries. The situation changed with the release of JAX-WS and its inclusion into Java SE 6. JAX-WS supports RESTful services; also, its <a href="http://java.sun.com/javase/6/docs/api/javax/xml/ws/Dispatch.html">Dispatch interface</a> allows clients to work with XML directly as opposed to having to use object mapping or completely unwieldy SAAJ API. A nice example of using JAX-WS to implement a client for a RESTful service is available in <a href="http://weblogs.java.net/blog/mhadley/archive/2006/01/restful_web_ser.html ">Mark Hadley's blog</a>.
</p>
<p>
However, I don't think that JAX-WS is going to become the primary way of implementing RESTful clients just yet. In many situations, HttpClient provides more flexibility and control over HTTP calls.
</p>
<p>

For example, it is very straightforward to turn on basic authentication for a client using HttpClient APIs:
<span id="more-61"></span>
<code>
<pre>
 HttpState httpState =httpClient.getState();
 httpState.setCredentials( AuthScope.ANY, 
     new UsernamePasswordCredentials(username, password));
 // Set the authentication header on the first request, don't wait for 401
 httpClient.getParams().setAuthenticationPreemptive(true);
        
 postMethod.setDoAuthentication(true);
</pre>
</code>
<p>

Implementing the same requirement in JAX-WS is not a big deal either:
<code>
<pre>

Map<String, Object> requestContext = dispatcher.getRequestContext();
requestContext.put(BindingProvider.USERNAME_PROPERTY, username); 
requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
</pre>
</code>
<p>

However, it is not clear how to tell the client to set basic authentication header on the very request in case of the service does not issue 401 basic authentication challenge (which is pretty common). It is also not clear if there is a way to change authentication scheme (say, to digest) or authentication scope. 
</p>
<p>

There are also other examples that demonstrate that in attempt to abstract the details of the transport protocol JAX-WS limits capabilities of the clients. 
</p>
<p>
However, using JAX-WS REST capabilities still makes sense for applications that use both SOAP and RESTfull services. This allows developers to use consistent API for both types of services. Also, in some instances, a service provider may initially implement a service using XML/HTTP and later decide to switch to SOAP, say, to be able to use some of the WS-* specifications (this is actually a fairly common situation within an enterprise). In this case, using JAX-WS will certainly make the transition easier for the clients. 

]]></content:encoded>
			<wfw:commentRss>http://myarch.com/will-jax-ws-become-the-primary-mechanism-for-invoking-restful-services/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Create JAX-WS Service in 5 Minutes (Tutorial)</title>
		<link>http://myarch.com/create-jax-ws-service-in-5-minutes</link>
		<comments>http://myarch.com/create-jax-ws-service-in-5-minutes#comments</comments>
		<pubDate>Thu, 19 Apr 2007 04:17:38 +0000</pubDate>
		<dc:creator>Alexander Ananiev</dc:creator>
				<category><![CDATA[JAX-WS]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Web services]]></category>

		<guid isPermaLink="false">http://myarch.com/create-jax-ws-service-in-5-minutes</guid>
		<description><![CDATA[This is a brief tutorial describing how to create a Web service using WSDL and annotations. The approach presented here allows you to design and implement your WSDL/Schema and Java classes independently without having to generate anything. You can then use annotations to map Java classes to appropriate WSDL and Schema elements. Since JAXB and [...]]]></description>
			<content:encoded><![CDATA[<p>
This is a brief tutorial describing how to create a Web service using WSDL and annotations. 
The approach presented here allows you to design and implement your WSDL/Schema and Java classes
independently without having to generate anything. You can then use annotations 
to map Java classes to appropriate WSDL and Schema elements. 
<br />Since JAXB and JAX-WS have sensible defaults, the number of annotations can be kept
to the minimum. 
</p>
<p>
In my opinion, it is always best to develop WSDL and schemas by hand to ensure that the
service contract is appropriately defined and also that the schema
can be re-used (by other services) and extended if necessary. I do not recommend using annotations 
for automatically producing WSDL and schemas at runtime as this leads to
simplistic schemas and WSDLs.
</p>
<p>
Generating classes from WSDL/schema sometimes makes sense, say in situations 
when you have to use a pre-defined schema. However, as with any code generation,
it creates a maitainance problem especially if there is a need to put behavior 
into generated classes. So it is desirable to be able to evolve object model and 
service implementation classes independently
from WSDL/schemas. You can do it quite easily by following the steps below. 
</p>
<p>
Even though I use the word "create" when describing some of the steps, the same approach 
will also work for updates or refactoring caused by changes in 
service requirements. 
</p>
<p>
The steps are the following:
</p>
<ul>
<li>
Design your service interface. In our case the service has a single "add" operation that accepts
a "person" document, adds it to a database and returns back the status:
<br /> <code>public String add( Person person )</code> 
</li>
<li>
Design your data/object model. In our case Person class has three fields  
(ssn, firstName, lastName) and the list of addresses. 
Real world examples will certainly be more complex, but this is good enough for our purposes.
</li>
<li>
Define XML schema based on your object model. 
Use strict datatypes where possible. For example, we use 
<code>xsd:token</code> instead of <code>xsd:string</code> since "token" does not allow 
carriage return, tabs, and leading spaces: 
</li>
<code>
  <pre>
    &lt;xsd:element name="person"&gt;
        &lt;xsd:complexType &gt;
            &lt;xsd:sequence&gt;
                &lt;xsd:element name="ssn" type="xsd:token" 
                        minOccurs="1" maxOccurs="1"/&gt;
                &lt;xsd:element name="firstName" type="xsd:token" 
                        minOccurs="1" maxOccurs="1"/&gt;
                &lt;xsd:element name="lastName" type="xsd:token" 
                        minOccurs="1" maxOccurs="1" /&gt;
                &lt;xsd:element name="address" type="Address" 
                        minOccurs="1" maxOccurs="unbounded"/&gt; 
            &lt;/xsd:sequence&gt;
        &lt;/xsd:complexType&gt;
    &lt;/xsd:element&gt;
  </pre>
</code>
<p>
<a href="/files/jaxws_tutorial/person.xsd">Complete schema file</a>
</p>

<li>
Create an XML file for your schema so you can test the schema. 
You can generate an XML instance document 
automatically from Eclipse (assuming you're using <a href="http://www.eclipse.org/webtools/main.php">
Eclipse Web Tool Platform</a>) 
by right-clicking on the schema in navigator and selecting "generate". 
Test the schema by changing data and making sure that you're getting correct 
validation errors.
</li>
<p>
<a href="/files/jaxws_tutorial/person.xml">Sample XML file</a>
</p>
<li>
  Create WSDL. Our WSDL imports the schema that we just created. 
  Note that the WSDL target namespace is different from the schema namespace since the 
  same schema can be reused by different WSDLs: 
</li>
<code>
  <pre>
    &lt;wsdl:definitions 
          targetNamespace="http://personservice" 
          xmlns="http://personservice" 
          xmlns:pers="http://person"
          xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
          xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
          xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" 
          xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  
      &lt;wsdl:types&gt;
            &lt;xsd:import namespace="http://person" 
                    schemaLocation="person.xsd" /&gt;
            &lt;!-- Return value --&gt;
            &lt;xsd:element name="status" type="xsd:string" /&gt;
      &lt;/wsdl:types&gt;
      ...
  </pre>
</code>
<p>
<a href="/files/jaxws_tutorial/personService.wsdl">Complete WSDL file</a>
</p>
  <li>
  Create your object model classes and annotate them with appropriate JAXB annotations:
  </li>
<code>
  <pre>
    // By default JAXB uses getters/setters for marshaling/unmarshaling
    // Using fields access allows us not to define getters/setters for 
    // all mapped instance variables.
    @XmlAccessorType(XmlAccessType.FIELD)
    // We need to provide the namespace, otherwise it defaults to
    // the package name
    @XmlRootElement(namespace="http://person")
    public class Person {
    
        // we only need annotations for variables that don't match 
        // element names
        private String ssn;
        private String firstName;
        private String lastName;
        
        @XmlElement(name = "address")
        protected List&lt;Address&gt; addresses;
      ...
  </pre>
</code>
<p>
<a href="/files/jaxws_tutorial/Person.java">Person class</a>
<br />
<a href="/files/jaxws_tutorial/Address.java">Address class</a>
</p>
<li>
  Create ObjectFactory class. This class is required by JAXB and it 
  should contain factory methods for all JAXB-mapped classes. ObjectFactory 
  must resides in the same package with object model classes. 
</li>
<code>
  <pre>
    @XmlRegistry
    public class ObjectFactory {
    
        public Person createPerson() {
            return new Person();
        }
        
        public Address createAddress() {
            return new Address();
        }
    }
  </pre>
</code>
<p>
<a href="/files/jaxws_tutorial/ObjectFactory.java">ObjectFactory class</a>
</p>

<li>
Create Web Service implementation class. Note that with JAX-WS 
Service Endpoint Interface (SEI) is optional, so all you need is an implementation class:
</li>
<code>
  <pre>
      @WebService(
              // all values must match corresponding attributes 
              // and elements of the WSDL file
          
              // Name of the port type in WSDL
              name="PersonService",
              // Target namespace of WSDL, could be 
              // different from the schema namespace
              targetNamespace="http://personservice",
              serviceName="PersonServicePorts",
              portName="PersonService",
              // the file must be available to Web container
              wsdlLocation="WEB-INF/wsdl/PersonService.wsdl"
      )
      
      /*
       * We'are using "bare" style since "add" operation 
       * takes only one argument, person document. Therefore, there 
       * is no need to "wrap" it by nesting it inside operation element.
       * Note that "wrapped" style is the default.
       */
      @SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.BARE)
      
      public class PersonService {
          
          @WebResult(name = "status")
          public String add( Person person ) {
              
              System.out.println("Adding person :"+person );
              return "Added "+person.getFullName();
          }
      }
  </pre>
</code>
<p>
<a href="/files/jaxws_tutorial/PersonService.java">PersonService class</a>
</p>
<li>
Deploy your Web service to your application server or Web services container. 
Refer to your application server documentation for details. 
</li>
<li>
Test the service. 
The easiest way to test the service is to use open source <a href="http://www.soapui.org">soapUI tool</a>.
You can install it as Eclipse plugin (there are also plugins for
NetBeans and IDEA) following <a href="http://www.soapui.org/eclipse/index.html">these instructions</a>. 
In Eclipse, open SoapUI view, right click and create a project from your WSDL file. SoapUI will automatically
create a sample SOAP request which you can update with your data. You can run it right away.
Later, you can create a repeatable test suite with parametirized data using SoapUI properties and 
assertions:
</li>
</ul>
<br />
<br />
<img src="/files/jaxws_tutorial/soapui.jpg" >

<p>
<a href="/files/jaxws_tutorial/personService-soapui-project.xml">SoapUI Project</a> (you can import it into SoapUI).
<p>
You can also <a href="/files/jaxws_tutorial/personService.zip">download</a> all files in a zip file.
</p>
]]></content:encoded>
			<wfw:commentRss>http://myarch.com/create-jax-ws-service-in-5-minutes/feed</wfw:commentRss>
		<slash:comments>48</slash:comments>
		</item>
	</channel>
</rss>

