I have created axis2 webservice using SOAP+XML. Now my client want me to use REST+JSON. I followed this article: http://www.marcusschiesser.de/?p=130
Calling http://localhost:8080/axis2/services/Version/getVersion?response=application/json from browser is always returning <ns:getVersionResponse xmlns:ns="http://axisversion.sample"> <ns:return>Hi - the Axis2 version is 1.6.0</ns:return> </ns:getVersionResponse> But I want the response in JSON format. I couldn't figureout what went wrong. For more details I have attached axis2.xml. I added system out in DynamicResponseHandler, and it never called. public class DynamicResponseHandler extends AbstractHandler { public Handler.InvocationResponse invoke(MessageContext messageContext) throws AxisFault { OperationContext operationContext = messageContext.getOperationContext(); if (operationContext != null) { MessageContext inMessageContext = operationContext.getMessageContext("In"); if (inMessageContext != null) { HttpServletRequest request = (HttpServletRequest)inMessageContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); if (request != null) { String responseFormat = request.getParameter("response"); if (responseFormat != null) { Parameter parameter = getParameter(responseFormat); if (parameter != null) responseFormat = (String)parameter.getValue(); messageContext.setProperty("messageType", responseFormat); System.out.println("Setting message type"); } } } } return Handler.InvocationResponse.CONTINUE; } } I'm missing something. Please guide me to fix it
<!-- ~ Licensed to the Apache Software Foundation (ASF) under one ~ or more contributor license agreements. See the NOTICE file ~ distributed with this work for additional information ~ regarding copyright ownership. The ASF licenses this file ~ to you under the Apache License, Version 2.0 (the ~ "License"); you may not use this file except in compliance ~ with the License. You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, ~ software distributed under the License is distributed on an ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~ KIND, either express or implied. See the License for the ~ specific language governing permissions and limitations ~ under the License. --> <axisconfig name="AxisJava2.0"> <!-- ================================================= --> <!-- Parameters --> <!-- ================================================= --> <parameter name="hotdeployment">true</parameter> <parameter name="hotupdate">false</parameter> <parameter name="enableMTOM">false</parameter> <parameter name="enableSwA">false</parameter> <!--Uncomment if you want to enable file caching for attachments --> <!--parameter name="cacheAttachments">true</parameter> <parameter name="attachmentDIR"></parameter> <parameter name="sizeThreshold">4000</parameter--> <!--This will give out the timout of the configuration contexts, in seconds--> <parameter name="ConfigContextTimeoutInterval">30</parameter> <!--During a fault, stacktrace can be sent with the fault message. The following flag will control --> <!--that behaviour.--> <parameter name="sendStacktraceDetailsWithFaults">false</parameter> <!--If there aren't any information available to find out the fault reason, we set the message of the expcetion--> <!--as the faultreason/Reason. But when a fault is thrown from a service or some where, it will be --> <!--wrapped by different levels. Due to this the initial exception message can be lost. If this flag--> <!--is set then, Axis2 tries to get the first exception and set its message as the faultreason/Reason.--> <parameter name="DrillDownToRootCauseForFaultReason">false</parameter> <parameter name="userName">admin</parameter> <parameter name="password">axis2</parameter> <!--To override repository/services you need to uncomment following parameter and value SHOULD be absolute file path.--> <!--<parameter name="ServicesDirectory">service</parameter>--> <!--To override repository/modules you need to uncomment following parameter and value SHOULD be absolute file path--> <!--<parameter name="ModulesDirectory">modules</parameter>--> <!--Following params will set the proper context paths for invocations. All the endpoints will have a commons context--> <!--root which can configured using the following contextRoot parameter--> <!--<parameter name="contextRoot">axis2</parameter>--> <!--Our HTTP endpoints can handle both REST and SOAP. Following parameters can be used to distingiush those endpoints--> <!--In case of a servlet, if you change this you have to manually change the settings of your servlet container to map this --> <!--context path to proper Axis2 servlets--> <!--<parameter name="servicePath">services</parameter>--> <!--<parameter name="restPath">rest</parameter>--> <!--Set the flag to true if you want to enable transport level session mangment--> <parameter name="manageTransportSession">false</parameter> <!--Following two parameters will be used to handle REST in Axis2. The default settings will make Axis2 to have two--> <!--different endpoints, one for REST (AxisRESTServlet) one for SOAP message handling (AxisServlet). But following--> <!--parameters help to tweak the message handling of two main servlets. --> <!-- If the enableRESTInAxis2MainServlet is true, then Axis2MainServlet will handle both SOAP and REST messages --> <parameter name="enableRESTInAxis2MainServlet" locked="true">false</parameter> <!-- Following parameter will completely disable REST handling in both the servlets--> <parameter name="disableREST" locked="true">false</parameter> <!-- This will disable the separate servlet we have for REST handling. --> <parameter name="disableSeparateEndpointForREST" locked="true">false</parameter> <!-- If you have a frontend host which exposes this webservice using a different public URL --> <!-- use this parameter to override autodetected url --> <!--<parameter name="httpFrontendHostUrl">https://someotherhost/context</parameter>--> <!-- The way of adding listener to the system--> <!-- <listener class="org.apache.axis2.ObserverIMPL">--> <!-- <parameter name="RSS_URL">http://127.0.0.1/rss</parameter>--> <!-- </listener>--> <!-- ================================================= --> <!-- Message Receivers --> <!-- ================================================= --> <!--This is the Deafult Message Receiver for the system , if you want to have MessageReceivers for --> <!--all the other MEP implement it and add the correct entry to here , so that you can refer from--> <!--any operation --> <!--Note : You can ovride this for particular service by adding the same element with your requirement--> <messageReceivers> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/> </messageReceivers> <!-- ================================================= --> <!-- Message Formatter --> <!-- ================================================= --> <!--Following content type to message formatter mapping can be used to implement support for different message --> <!--formats serialization in Axis2. These message formats are expected to be resolved based on the content type. --> <messageFormatters> <messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONMessageFormatter"/> <messageFormatter contentType="application/json/badgerfish" class="org.apache.axis2.json.JSONBadgerfishMessageFormatter"/> <messageFormatter contentType="text/javascript" class="org.apache.axis2.json.JSONMessageFormatter"/> <messageformatter contentType="application/jsonp" class="org.apache.axis2.json.JsonpMessageFormatter"> </messageformatter> <messageformatter contentType="application/jsonp/badgerfish" class="org.apache.axis2.json.JsonpBadgerfishMessageFormatter"> </messageformatter> </messageFormatters> <!-- ================================================= --> <!-- Message Builders --> <!-- ================================================= --> <!--Following content type to builder mapping can be used to implement support for different message --> <!--formats in Axis2. These message formats are expected to be resolved based on the content type. --> <messageBuilders> <messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONOMBuilder"/> <messageBuilder contentType="application/json/badgerfish" class="org.apache.axis2.json.JSONBadgerfishOMBuilder"/> <messageBuilder contentType="text/javascript" class="org.apache.axis2.json.JSONOMBuilder"/> </messageBuilders> <!-- ================================================= --> <!-- Transport Ins --> <!-- ================================================= --> <transportReceiver name="http" class="org.apache.axis2.transport.http.SimpleHTTPServer"> <parameter name="port">8080</parameter> <!-- Here is the complete list of supported parameters (see example settings further below): port: the port to listen on (default 6060) hostname: if non-null, url prefix used in reply-to endpoint references (default null) originServer: value of http Server header in outgoing messages (default "Simple-Server/1.1") requestTimeout: value in millis of time that requests can wait for data (default 20000) requestTcpNoDelay: true to maximize performance and minimize latency (default true) false to minimize bandwidth consumption by combining segments requestCoreThreadPoolSize: number of threads available for request processing (unless queue fills up) (default 25) requestMaxThreadPoolSize: number of threads available for request processing if queue fills us (default 150) note that default queue never fills up: see HttpFactory threadKeepAliveTime: time to keep threads in excess of core size alive while inactive (default 180) note that no such threads can exist with default unbounded request queue threadKeepAliveTimeUnit: TimeUnit of value in threadKeepAliveTime (default SECONDS) (default SECONDS) --> <!-- <parameter name="hostname" >http://www.myApp.com/ws</parameter> --> <!-- <parameter name="originServer" >My-Server/1.1</parameter> --> <!-- <parameter name="requestTimeout" >10000</parameter> --> <!-- <parameter name="requestTcpNoDelay" >false</parameter> --> <!-- <parameter name="requestCoreThreadPoolSize">50</parameter> --> <!-- <parameter name="requestMaxThreadPoolSize" >100</parameter> --> <!-- <parameter name="threadKeepAliveTime" >240000</parameter> --> <!-- <parameter name="threadKeepAliveTimeUnit" >MILLISECONDS</parameter> --> </transportReceiver> <!-- ================================================= --> <!-- Transport Outs --> <!-- ================================================= --> <transportSender name="local" class="org.apache.axis2.transport.local.LocalTransportSender"/> <transportSender name="http" class="org.apache.axis2.transport.http.CommonsHTTPTransportSender"> <parameter name="PROTOCOL">HTTP/1.1</parameter> <parameter name="Transfer-Encoding">chunked</parameter> </transportSender> <transportSender name="https" class="org.apache.axis2.transport.http.CommonsHTTPTransportSender"> <parameter name="PROTOCOL">HTTP/1.1</parameter> <parameter name="Transfer-Encoding">chunked</parameter> </transportSender> <!-- ================================================= --> <!-- Global Modules --> <!-- ================================================= --> <!-- Comment this to disable Addressing --> <!--module ref="addressing"/--> <module ref="DynamicResponseHandler"/> <!--Configuring module , providing parameters for modules whether they refer or not--> <!--<moduleConfig name="addressing">--> <!--<parameter name="addressingPara">N/A</parameter>--> <!--</moduleConfig>--> <!-- ================================================= --> <!-- Phases --> <!-- ================================================= --> <phaseOrder type="InFlow"> <!-- System pre defined phases --> <phase name="Transport"> <handler name="RequestURIBasedDispatcher" class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"> <order phase="Transport"/> </handler> <handler name="SOAPActionBasedDispatcher" class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"> <order phase="Transport"/> </handler> </phase> <phase name="Security"/> <phase name="PreDispatch"/> <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase"> <handler name="AddressingBasedDispatcher" class="org.apache.axis2.dispatchers.AddressingBasedDispatcher"/> <handler name="RequestURIOperationDispatcher" class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/> <handler name="SOAPMessageBodyBasedDispatcher" class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/> </phase> <!-- System pre defined phases --> <!-- After Postdispatch phase module author or or service author can add any phase he want --> <phase name="OperationInPhase"/> <phase name="soapmonitorPhase"/> </phaseOrder> <phaseOrder type="OutFlow"> <!-- user can add his own phases to this area --> <phase name="soapmonitorPhase"/> <phase name="OperationOutPhase"/> <!--system predefined phase--> <!--these phase will run irrespective of the service--> <phase name="PolicyDetermination"/> <phase name="MessageOut"/> <phase name="Security"/> </phaseOrder> <phaseOrder type="InFaultFlow"> <phase name="PreDispatch"/> <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase"> <handler name="RequestURIBasedDispatcher" class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/> <handler name="SOAPActionBasedDispatcher" class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/> <handler name="AddressingBasedDispatcher" class="org.apache.axis2.dispatchers.AddressingBasedDispatcher"/> <handler name="RequestURIOperationDispatcher" class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/> <handler name="SOAPMessageBodyBasedDispatcher" class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/> </phase> <!-- user can add his own phases to this area --> <phase name="OperationInFaultPhase"/> <phase name="soapmonitorPhase"/> </phaseOrder> <phaseOrder type="OutFaultFlow"> <!-- user can add his own phases to this area --> <phase name="soapmonitorPhase"/> <phase name="OperationOutFaultPhase"/> <phase name="PolicyDetermination"/> <phase name="MessageOut"/> </phaseOrder> </axisconfig>
--------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@axis.apache.org For additional commands, e-mail: java-user-h...@axis.apache.org