axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruno Simioni <>
Subject JAX-WS, JAXB, Javascript clients, and JSON communication.
Date Sat, 12 Dec 2009 16:47:19 GMT
Hello all, that's my first email to this group. I've developed an app server
and a set of JAX-WS webservices on top of axis2, with javascript clients,
and my purpose is discuss this case with all group members, to make right
decisions on this architecture.

I need to exchange messages with several clients, from just one server
instance (app server instance, on top of axis2). My clients are javascript
based (browsers and Mozilla Xulrunner), and for my convenience, I would like
to exchange JSON messages (without XML namespaces (urrgh)), instead of SOAP
messages, for a better (and easier) javascript client data manipulation.

Well, sending SOAP messages from Javascript is easy, using Jquery or other
javascript lib, or even, from scratch. That's not a big deal. However,
sending JSON messages to axis2 is not so clearly explained. I search over
all reference I've found, and so, I have some questions.

I've made all basic steps, like putting formatter and builder JSON on

<messageFormatter contentType="application/json"

<messageBuilder contentType="application/json"

And changing the HTTPRequest content type.

Also, there is a module (engaged in a custom made phase, configured in
conf/axis2.xml), made from scratch, for intercept all received messages, for
app logging purposes. This module receives all messages (from
invoke(MessageContext messageContext) method) and parse it, getting the
webservices name, and method name.

In module handler implementation, the webservice uri cames from:

EndpointReference ref = messageContext.getTo();
String webservice = ref.getAddress();

And the java class method name cames from:


>From clients, the post http request is made by something like this (JSON, in
clients, is some stub for translating JSON string to Java Script Object and

var req = new getNewXMLHttpRequest();
var url = http://localhost:8080/MyApp/services/MyService;  // POJO (JAX-WS)
var method = "MyMethod";

var data = {
                    input: "xxxx"
};"POST", url, true);
req.setRequestHeader("Cache-Control", "no-store, no-cache");
req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
req.setRequestHeader("Content-Length", data.length);
req.setRequestHeader("SOAPAction", method); // is that necessary on JSON

The first problem is about JSON data input (from client) and the
messageContext.getSOAPAction() on axis2 module. Specifying the JAX-WS class
method in data object make the process right, but I don't have any method to
inform what Java method was called (solve this replicating the information,
by SOAPAction on request header). How to solve this? #1

And on the server side, my webservice (JAX-WS) looks like this:

@WebService(name="MyService.Info", serviceName="MyService", portName="Info")
public class Info {

    public @WebResult MyMethodOutputClass MyMethod(@WebParam
MyMethodInputClass input)
        MyMethodOutputClass output = new MyMethodOutputClass();

       // app logic

        return output;

And the input and output parameters classes(JAXB):

@XmlType(name = "MyMethodOutputClass")

public class MyMethodOutputClass
    @XmlElement(required = true)
    public String[] outputs = null;


@XmlType(name = "MyMethodInputClass")

public class MyMethodInputClass
    @XmlElement(required = true)
    public String input;

Is that correct, to build webservices in JAX-WS and JAXB like that? #2

And here goes the last question: Receiving response through the
JSONMessageFormatter, throws an error related to namespaces. I've changed
the formatter to Badgerfish notation, and it stops to throw this error, but
JSON returned from server, had namespaces. (urgh).

To solve this (remove namespaces, and make javascript data manipulation on
client side easier), I've written my own formatter class, to exclude
namespaces for response message.

I didn't like to rewrite all the axis2 developers job (rewrite the
formatter), so, is there anyway to remove namespaces from JSON return
messages, using JAX-WS webservices and JSON notation? #3.

Well, that's my study case. All three questions are marked by #1 #2 and #3,
on this loooong email. I need some attention, so, i'm glad for your patience
and help.


Bruno Simioni, from Brazil.

View raw message