2 Replies Latest reply: Jul 11, 2011 6:57 AM by 871058 RSS

    REST JSON EXAMPLEEXAMPLE

    871058
      Hi Im convenient with axis2 and its features were amazing. Comparing to jersey which supports only REST, axis2 can operate as SOAP, REST, supports JMS... Currently REST+JSON is getting popular. But REST+JSON sample is not available in axis2. I tried to implement my service using REST+JSON but only getting exception that namespace error. Can anyone spend fee minutes to provide me a sample in REST JSON. That will be much helpful
        • 1. Re: REST JSON EXAMPLEEXAMPLE
          YoungWinston
          868055 wrote:
          Can anyone spend fee minutes to provide me a sample in REST JSON. That will be much helpful
          I think it would be much better for you to spend a few minutes providing us with the code that is causing your error (only the relevant bits please).

          Winston
          • 2. Re: REST JSON EXAMPLE
            871058
            That's correct. I should have shared the sample I tried. Anyway, here is the sample I tried:

            I'm taking Version service which ship with axis2. I added JSON messageFormatters and messageBuilders as specified in http://axis.apache.org/axis2/java/core/docs/json_support.html.

            My client program is as follows:
            VersionStub stub = new VersionStub("http://chd1was2:9080/iPAS-SYNC-WebService/services/Version?wsdl");
                 stub._getServiceClient().getOptions().setProperty(Constants.Configuration.CONTENT_TYPE, "application/json/badgerfish");
                 stub._getServiceClient().getOptions().setProperty(Constants.Configuration.ENABLE_REST, true);

            GetVersion req = new GetVersion();
                 GetVersionResponse res = stub.getVersion(req);
                 System.out.println("Response " + res.get_return());

            When I run this I'm getting:

            org.apache.axis2.AxisFault: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; expected '<'
            at javax.xml.stream.SerializableLocation@7d8d7d8d
                 at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
                 at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:123)
                 at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:67)
                 at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:354)
                 at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
                 at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
                 at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
                 at org.apache.axis2.VersionService.VersionStub.getVersion(VersionStub.java:191)
                 at org.apache.axis2.IPASService.VersionClient.authenticate(VersionClient.java:52)
                 at org.apache.axis2.IPASService.VersionClient.main(VersionClient.java:36)
            Caused by: org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; expected '<'
            at javax.xml.stream.SerializableLocation@7d8d7d8d
                 at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
                 at org.apache.axiom.om.impl.llom.OMDocumentImpl.getOMDocumentElement(OMDocumentImpl.java:109)
                 at org.apache.axiom.om.impl.builder.StAXOMBuilder.getDocumentElement(StAXOMBuilder.java:570)
                 at org.apache.axiom.om.impl.builder.StAXOMBuilder.getDocumentElement(StAXOMBuilder.java:566)
                 at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:188)
                 at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:145)
                 at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:108)
                 ... 8 more
            Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '{' (code 123) in prolog; expected '<'
            at javax.xml.stream.SerializableLocation@7d8d7d8d
                 at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:648)
                 at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2047)
                 at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1069)
                 at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.next(XMLStreamReaderWrapper.java:225)
                 at org.apache.axiom.util.stax.dialect.DisallowDoctypeDeclStreamReaderWrapper.next(DisallowDoctypeDeclStreamReaderWrapper.java:34)
                 at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.next(XMLStreamReaderWrapper.java:225)
                 at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext(StAXOMBuilder.java:681)
                 at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:214)
                 ... 14 more