Tuesday, February 14, 2012

Web Services using JAX-RPC, JAX-WS or JAX-RS

Quickstart WebServices Tutorial


Weblogic 12c version now ships by default with JAX-RS 1.1 as a core library.  Previously in Weblogic the following shared web applications were required - now we just use the specification library.

 Library jackson-core-asl(1.0,1.1.1) Active  Library
 Library jersey-bundle(1.1.1, Active  Library
 Library jettison(1.1,1.1) Active  Library
 Library jsr311-api(1.1.1,1.1.1) Active  Library

Now in eclipse just add the JAX-RS facet which will add the jersey servlet to your web.xml

    <description>JAX-RS Tools Generated - Do not modify</description>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <servlet-name>JAX-RS Servlet</servlet-name>


Jax-RPC has fallen out of favor for most new web services in favor of JAX-RS 1.1 or REST.
A simple java SE example that is single threaded and runs off of Metro included in Java SE 1.6.
This example does not need a web container or a full application server to run - however it is non-scalable and thread-blocking simple example.

package org.dataparallel.example.jaxws;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

* definitions targetNamespace="http://jaxws.example.dataparallel.org/" name="ServiceEndpointImplService

@SOAPBinding(style = Style.RPC)
public interface ServiceEndpoint {
    public static final String URL =;
    public static final String PORT = "8980";
    public static final String SERVICE_NAME = "service";
    public static final String SERVICE_URI = URL + ":" + PORT + "/" + SERVICE_NAME;
    public static final String DOMAIN_NAME = "http://jaxws.example.dataparallel.org/";

    public String getImage();

package org.dataparallel.example.jaxws;

import javax.jws.WebService;

public class ServiceEndpointImpl implements ServiceEndpoint {
    public String getImage() {
        return "aString";

package org.dataparallel.example.jaxws;

import javax.xml.ws.Endpoint;
public class ServiceEndpointPublisher {
    public void publish() {
        publish(ServiceEndpoint.SERVICE_URI, new ServiceEndpointImpl());

    public void publish(String url, ServiceEndpoint service) {
        Endpoint.publish(url, service);

    public static void main(String[] args) {
        // single threaded testing service
        ServiceEndpointPublisher aPublisher = new ServiceEndpointPublisher();

package org.dataparallel.example.jaxws;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

public class ServiceClient {
    public void callService() {
        try {
            URL aWsdlURL = new URL(ServiceEndpoint.SERVICE_URI + "?wsdl");
            QName aQName = new QName(ServiceEndpoint.DOMAIN_NAME,ServiceEndpointImpl.class.getSimpleName() + "Service");
            Service aService = Service.create(aWsdlURL, aQName);
            ServiceEndpoint anEndpointInterface = aService.getPort(ServiceEndpoint.class);
            System.out.println("Service.getImage: " + anEndpointInterface.getImage());
        } catch (MalformedURLException mue) {

    public static void main(String[] args) {
        ServiceClient aClient = new ServiceClient();

Jax-WS has fallen out of favor for most new web services in favor of JAX-RS 1.1 or REST - it still has a place for specific SOAP clients or data types.

- in queue - see

Total Pageviews