You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Alexander Rosemann <al...@gmail.com> on 2009/07/26 10:20:17 UTC

sending an application/json formatted request

Hi,

I'm trying for a while now to get axis2 to accept incoming 
application/json requests (JSONMessageFormatter/ JSONOMBuilder). I 
always get a "java.lang.IllegalArgumentException: The MessageContext 
does not have an associated SOAPFault" on the client side and a huge 
json formatted soap error on the server side: "ERROR 
http-9080-Processor24 org.apache.axis2.engine.AxisEngine - The endpoint 
reference (EPR) for the Operation not found is 
http://localhost:9082/sm62/services/echo/echo and the WSA Action = null".

The exact same service works fine when sending application/xml requests 
though.

I've configured both the client axis.xml and the server axis.xml 
according to the axis2.xml file that comes with 
JSONIntegrationTest.java. The only difference is that I've disabled the 
transportReceiver since axis runs within tomcat.

I'm using axis2 1.4.1 embedded in another web-app hosted by tomcat 5.5.

client code:

private static OMElement payload() throws Exception {
   OMFactory fac = OMAbstractFactory.getOMFactory();
   OMNamespace ns = fac.createOMNamespace("", "");
   OMElement request = fac.createOMElement("request", ns);
   request.addAttribute("attr", "some data", ns);
   return request;
}

private static void runAxisClient() {
   try {
     File configFile = new File("resources/axis2.xml");
     ConfigurationContext cfgCtx = 
ConfigurationContextFactory.createConfigurationContextFromFileSystem(null,
         configFile.getAbsolutePath());
     ServiceClient client = new ServiceClient(cfgCtx, null);
     Options options = new Options();
     options.setTo(new 
EndpointReference("http://localhost:9080/myapp/services/echo/echo"));
     options.setProperty(Constants.Configuration.MESSAGE_TYPE, 
"application/json");
     options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
     options.setProperty(Constants.Configuration.HTTP_METHOD, 
Constants.Configuration.HTTP_METHOD_POST);
     client.setOptions(options);
     OMElement response = client.sendReceive(payload());
     System.out.println("response: " + response);
   }
   catch (Exception e) {
     e.printStackTrace();
   }
}

Any pointers are much appreciated. Especially a hint why axis is telling 
me that the endpoint is wrong although it's working ok for xml messages?

Thanks in advance,
Alex


Re: sending an application/json formatted request

Posted by Andreas Veithen <an...@gmail.com>.
Alex,

Can you create an issue in JIRA and attach the aar file of your
service as well as a ZIP with the source code of the client, including
the config files (as an Eclipse project if you use that IDE)?

Andreas

On Sun, Jul 26, 2009 at 10:20, Alexander
Rosemann<al...@gmail.com> wrote:
> Hi,
>
> I'm trying for a while now to get axis2 to accept incoming application/json
> requests (JSONMessageFormatter/ JSONOMBuilder). I always get a
> "java.lang.IllegalArgumentException: The MessageContext does not have an
> associated SOAPFault" on the client side and a huge json formatted soap
> error on the server side: "ERROR http-9080-Processor24
> org.apache.axis2.engine.AxisEngine - The endpoint reference (EPR) for the
> Operation not found is http://localhost:9082/sm62/services/echo/echo and the
> WSA Action = null".
>
> The exact same service works fine when sending application/xml requests
> though.
>
> I've configured both the client axis.xml and the server axis.xml according
> to the axis2.xml file that comes with JSONIntegrationTest.java. The only
> difference is that I've disabled the transportReceiver since axis runs
> within tomcat.
>
> I'm using axis2 1.4.1 embedded in another web-app hosted by tomcat 5.5.
>
> client code:
>
> private static OMElement payload() throws Exception {
>  OMFactory fac = OMAbstractFactory.getOMFactory();
>  OMNamespace ns = fac.createOMNamespace("", "");
>  OMElement request = fac.createOMElement("request", ns);
>  request.addAttribute("attr", "some data", ns);
>  return request;
> }
>
> private static void runAxisClient() {
>  try {
>    File configFile = new File("resources/axis2.xml");
>    ConfigurationContext cfgCtx =
> ConfigurationContextFactory.createConfigurationContextFromFileSystem(null,
>        configFile.getAbsolutePath());
>    ServiceClient client = new ServiceClient(cfgCtx, null);
>    Options options = new Options();
>    options.setTo(new
> EndpointReference("http://localhost:9080/myapp/services/echo/echo"));
>    options.setProperty(Constants.Configuration.MESSAGE_TYPE,
> "application/json");
>    options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
>    options.setProperty(Constants.Configuration.HTTP_METHOD,
> Constants.Configuration.HTTP_METHOD_POST);
>    client.setOptions(options);
>    OMElement response = client.sendReceive(payload());
>    System.out.println("response: " + response);
>  }
>  catch (Exception e) {
>    e.printStackTrace();
>  }
> }
>
> Any pointers are much appreciated. Especially a hint why axis is telling me
> that the endpoint is wrong although it's working ok for xml messages?
>
> Thanks in advance,
> Alex
>
>