Author: amilas
Date: Tue Apr 2 10:45:25 2013
New Revision: 1463475
URL: http://svn.apache.org/r1463475
Log:
appliying patch for AXIS2-5417
Added:
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonUtils.java
axis/axis2/java/core/trunk/modules/json/test-repository/services/JSONPOJOService.aar/
axis/axis2/java/core/trunk/modules/json/test-repository/services/JSONPOJOService.aar/META-INF/
axis/axis2/java/core/trunk/modules/json/test-repository/services/JSONPOJOService.aar/META-INF/services.xml
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/UtilTest.java
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/JSONPOJOService.java
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/JSONRPCIntegrationTest.java
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/Person.java
Removed:
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/factory/JsonUtils.java
Modified:
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JSONMessageHandler.java
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonInOnlyRPCMessageReceiver.java
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonRpcMessageReceiver.java
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/JSONXMLStreamAPITest.java
Modified:
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JSONMessageHandler.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JSONMessageHandler.java?rev=1463475&r1=1463474&r2=1463475&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JSONMessageHandler.java
(original)
+++
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/JSONMessageHandler.java
Tue Apr 2 10:45:25 2013
@@ -25,6 +25,7 @@ import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.engine.MessageReceiver;
import org.apache.axis2.handlers.AbstractHandler;
+import org.apache.axis2.json.gson.rpc.JsonInOnlyRPCMessageReceiver;
import org.apache.axis2.json.gson.rpc.JsonRpcMessageReceiver;
import org.apache.axis2.json.gson.factory.JsonConstant;
import org.apache.axis2.wsdl.WSDLConstants;
@@ -58,7 +59,7 @@ public class JSONMessageHandler extends
public InvocationResponse invoke(MessageContext msgContext) throws
AxisFault {
MessageReceiver messageReceiver =
msgContext.getAxisOperation().getMessageReceiver();
- if (messageReceiver instanceof JsonRpcMessageReceiver) {
+ if (messageReceiver instanceof JsonRpcMessageReceiver ||
messageReceiver instanceof JsonInOnlyRPCMessageReceiver) {
// do not need to parse XMLSchema list, as this message receiver
will not use GsonXMLStreamReader to read the inputStream.
} else {
Object tempObj =
msgContext.getProperty(JsonConstant.IS_JSON_STREAM);
Modified:
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonInOnlyRPCMessageReceiver.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonInOnlyRPCMessageReceiver.java?rev=1463475&r1=1463474&r2=1463475&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonInOnlyRPCMessageReceiver.java
(original)
+++
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonInOnlyRPCMessageReceiver.java
Tue Apr 2 10:45:25 2013
@@ -25,7 +25,6 @@ import org.apache.axis2.context.MessageC
import org.apache.axis2.description.AxisOperation;
import org.apache.axis2.json.gson.GsonXMLStreamReader;
import org.apache.axis2.json.gson.factory.JsonConstant;
-import org.apache.axis2.json.gson.factory.JsonUtils;
import org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -39,17 +38,14 @@ public class JsonInOnlyRPCMessageReceive
private static Log log =
LogFactory.getLog(JsonInOnlyRPCMessageReceiver.class);
@Override
public void invokeBusinessLogic(MessageContext inMessage) throws AxisFault
{
-
Object tempObj = inMessage.getProperty(JsonConstant.IS_JSON_STREAM);
boolean isJsonStream;
-
if (tempObj != null) {
isJsonStream = Boolean.valueOf(tempObj.toString());
} else {
// if IS_JSON_STREAM property is not set then it is not a JSON
request
isJsonStream = false;
}
-
if (isJsonStream) {
Object o =
inMessage.getProperty(JsonConstant.GSON_XML_STREAM_READER);
if (o != null) {
@@ -58,77 +54,45 @@ public class JsonInOnlyRPCMessageReceive
if (jsonReader == null) {
throw new AxisFault("JsonReader should not be null");
}
- Method method = null;
- String msg;
Object serviceObj = getTheImplementationObject(inMessage);
- Class implClass = serviceObj.getClass();
- Method[] allMethods = implClass.getDeclaredMethods();
AxisOperation op =
inMessage.getOperationContext().getAxisOperation();
String operation = op.getName().getLocalPart();
- method = JsonUtils.getOpMethod(operation, allMethods);
- Class[] paramClasses = method.getParameterTypes();
- try {
- int paramCount = paramClasses.length;
- JsonUtils.invokeServiceClass(jsonReader, serviceObj,
method, paramClasses, paramCount);
- } catch (IllegalAccessException e) {
- msg = "Does not have access to " +
- "the definition of the specified class, field,
method or constructor";
- log.error(msg, e);
- throw AxisFault.makeFault(e);
-
- } catch (InvocationTargetException e) {
- msg = "Exception occurred while trying to invoke service
method " +
- (method != null ? method.getName() : "null");
- log.error(msg, e);
- throw AxisFault.makeFault(e);
- } catch (IOException e) {
- msg = "Exception occur while encording or " +
- "access to the input string at the
JsonRpcMessageReceiver";
- log.error(msg, e);
- throw AxisFault.makeFault(e);
- }
+ invokeService(jsonReader, serviceObj, operation);
} else {
throw new AxisFault("GsonXMLStreamReader should have put as a
property of messageContext " +
"to evaluate JSON message");
}
-/* InputStream inputStream =
(InputStream)inMessage.getProperty(JsonConstant.INPUT_STREAM);
- if (inputStream != null) {
- Method method = null;
- String msg;
-
- Object serviceObj = getTheImplementationObject(inMessage);
- Class implClass = serviceObj.getClass();
- Method[] allmethods = implClass.getDeclaredMethods();
- AxisOperation op =
inMessage.getOperationContext().getAxisOperation();
- String operation = op.getName().getLocalPart();
- method = JsonUtils.getOpMethod(operation, allmethods);
- Class [] paramClasses = method.getParameterTypes();
- String charSetEncoding = (String)
inMessage.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
- try {
- int paramCount=paramClasses.length;
-
- JsonUtils.invokeServiceClass(inputStream,
- serviceObj, method, paramClasses, paramCount,
charSetEncoding);
-
- } catch (IllegalAccessException e) {
- msg = "Does not have access to " +
- "the definition of the specified class, field, method
or constructor";
- log.error(msg, e);
- throw AxisFault.makeFault(e);
-
- } catch (InvocationTargetException e) {
- msg = "Exception occurred while trying to invoke service
method " +
- (method != null ? method.getName() : "null");
- log.error(msg, e);
- throw AxisFault.makeFault(e);
- } catch (IOException e) {
- msg = "Exception occur while encording or " +
- "access to the input string at the
JsonRpcMessageReceiver";
- log.error(msg, e);
- throw AxisFault.makeFault(e);
- }*/
} else{
super.invokeBusinessLogic(inMessage); // call RPCMessageReceiver
if inputstream is null
}
}
+
+ public void invokeService(JsonReader jsonReader, Object serviceObj, String
operation_name) throws AxisFault {
+ Method method = null;
+ String msg;
+ Class implClass = serviceObj.getClass();
+ Method[] allMethods = implClass.getDeclaredMethods();
+ method = JsonUtils.getOpMethod(operation_name, allMethods);
+ Class[] paramClasses = method.getParameterTypes();
+ try {
+ int paramCount = paramClasses.length;
+ JsonUtils.invokeServiceClass(jsonReader, serviceObj, method,
paramClasses, paramCount);
+ } catch (IllegalAccessException e) {
+ msg = "Does not have access to " +
+ "the definition of the specified class, field, method or
constructor";
+ log.error(msg, e);
+ throw AxisFault.makeFault(e);
+
+ } catch (InvocationTargetException e) {
+ msg = "Exception occurred while trying to invoke service method " +
+ (method != null ? method.getName() : "null");
+ log.error(msg, e);
+ throw AxisFault.makeFault(e);
+ } catch (IOException e) {
+ msg = "Exception occur while encording or " +
+ "access to the input string at the JsonRpcMessageReceiver";
+ log.error(msg, e);
+ throw AxisFault.makeFault(e);
+ }
+ }
}
Modified:
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonRpcMessageReceiver.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonRpcMessageReceiver.java?rev=1463475&r1=1463474&r2=1463475&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonRpcMessageReceiver.java
(original)
+++
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonRpcMessageReceiver.java
Tue Apr 2 10:45:25 2013
@@ -24,7 +24,6 @@ import org.apache.axis2.context.MessageC
import org.apache.axis2.description.AxisOperation;
import org.apache.axis2.json.gson.GsonXMLStreamReader;
import org.apache.axis2.json.gson.factory.JsonConstant;
-import org.apache.axis2.json.gson.factory.JsonUtils;
import org.apache.axis2.rpc.receivers.RPCMessageReceiver;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -41,14 +40,12 @@ public class JsonRpcMessageReceiver exte
public void invokeBusinessLogic(MessageContext inMessage, MessageContext
outMessage) throws AxisFault {
Object tempObj = inMessage.getProperty(JsonConstant.IS_JSON_STREAM);
boolean isJsonStream;
-
if (tempObj != null) {
isJsonStream = Boolean.valueOf(tempObj.toString());
} else {
// if IS_JSON_STREAM property is not set then it is not a JSON
request
isJsonStream = false;
}
-
if (isJsonStream) {
Object o =
inMessage.getProperty(JsonConstant.GSON_XML_STREAM_READER);
if (o != null) {
@@ -57,40 +54,10 @@ public class JsonRpcMessageReceiver exte
if (jsonReader == null) {
throw new AxisFault("JsonReader should not be null");
}
- Method method = null;
- String msg;
Object serviceObj = getTheImplementationObject(inMessage);
- Class implClass = serviceObj.getClass();
- Method[] allMethods = implClass.getDeclaredMethods();
AxisOperation op =
inMessage.getOperationContext().getAxisOperation();
String operation = op.getName().getLocalPart();
- method = JsonUtils.getOpMethod(operation, allMethods);
- Class[] paramClasses = method.getParameterTypes();
- try {
- int paramCount = paramClasses.length;
- Object retObj = JsonUtils.invokeServiceClass(jsonReader,
serviceObj, method, paramClasses, paramCount);
-
- // handle response
- outMessage.setProperty(JsonConstant.RETURN_OBJECT, retObj);
- outMessage.setProperty(JsonConstant.RETURN_TYPE,
method.getReturnType());
-
- } catch (IllegalAccessException e) {
- msg = "Does not have access to " +
- "the definition of the specified class, field,
method or constructor";
- log.error(msg, e);
- throw AxisFault.makeFault(e);
-
- } catch (InvocationTargetException e) {
- msg = "Exception occurred while trying to invoke service
method " +
- (method != null ? method.getName() : "null");
- log.error(msg, e);
- throw AxisFault.makeFault(e);
- } catch (IOException e) {
- msg = "Exception occur while encording or " +
- "access to the input string at the
JsonRpcMessageReceiver";
- log.error(msg, e);
- throw AxisFault.makeFault(e);
- }
+ invokeService(jsonReader, serviceObj, operation , outMessage);
} else {
throw new AxisFault("GsonXMLStreamReader should be put as a
property of messageContext " +
"to evaluate JSON message");
@@ -99,4 +66,38 @@ public class JsonRpcMessageReceiver exte
super.invokeBusinessLogic(inMessage, outMessage); // call
RPCMessageReceiver if inputstream is null
}
}
+
+ public void invokeService(JsonReader jsonReader, Object serviceObj, String
operation_name,
+ MessageContext outMes) throws AxisFault {
+ String msg;
+ Class implClass = serviceObj.getClass();
+ Method[] allMethods = implClass.getDeclaredMethods();
+ Method method = JsonUtils.getOpMethod(operation_name, allMethods);
+ Class[] paramClasses = method.getParameterTypes();
+ try {
+ int paramCount = paramClasses.length;
+ Object retObj = JsonUtils.invokeServiceClass(jsonReader,
serviceObj, method, paramClasses, paramCount);
+
+ // handle response
+ outMes.setProperty(JsonConstant.RETURN_OBJECT, retObj);
+ outMes.setProperty(JsonConstant.RETURN_TYPE,
method.getReturnType());
+
+ } catch (IllegalAccessException e) {
+ msg = "Does not have access to " +
+ "the definition of the specified class, field, method or
constructor";
+ log.error(msg, e);
+ throw AxisFault.makeFault(e);
+
+ } catch (InvocationTargetException e) {
+ msg = "Exception occurred while trying to invoke service method " +
+ (method != null ? method.getName() : "null");
+ log.error(msg, e);
+ throw AxisFault.makeFault(e);
+ } catch (IOException e) {
+ msg = "Exception occur while encording or " +
+ "access to the input string at the JsonRpcMessageReceiver";
+ log.error(msg, e);
+ throw AxisFault.makeFault(e);
+ }
+ }
}
Added:
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonUtils.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonUtils.java?rev=1463475&view=auto
==============================================================================
---
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonUtils.java
(added)
+++
axis/axis2/java/core/trunk/modules/json/src/org/apache/axis2/json/gson/rpc/JsonUtils.java
Tue Apr 2 10:45:25 2013
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+package org.apache.axis2.json.gson.rpc;
+
+import com.google.gson.Gson;
+import com.google.gson.stream.JsonReader;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+
+public class JsonUtils {
+
+ public static Object invokeServiceClass(JsonReader jsonReader,
+ Object service,
+ Method operation ,
+ Class[] paramClasses ,
+ int paramCount ) throws
InvocationTargetException,
+ IllegalAccessException, IOException {
+
+ Object[] methodParam = new Object[paramCount];
+ Gson gson = new Gson();
+ String[] argNames = new String[paramCount];
+
+ if( ! jsonReader.isLenient()){
+ jsonReader.setLenient(true);
+ }
+ jsonReader.beginObject();
+ String messageName=jsonReader.nextName(); // get message name from
input json stream
+ jsonReader.beginArray();
+
+ int i = 0;
+ for (Class paramType : paramClasses) {
+ jsonReader.beginObject();
+ argNames[i] = jsonReader.nextName();
+ methodParam[i] = gson.fromJson(jsonReader, paramType); // gson
handle all types well and return an object from it
+ jsonReader.endObject();
+ i++;
+ }
+
+ jsonReader.endArray();
+ jsonReader.endObject();
+
+ return operation.invoke(service, methodParam);
+
+ }
+
+ public static Method getOpMethod(String methodName, Method[] methodSet) {
+ for (Method method : methodSet) {
+ String mName = method.getName();
+ if (mName.equals(methodName)) {
+ return method;
+ }
+ }
+ return null;
+ }
+
+}
Added:
axis/axis2/java/core/trunk/modules/json/test-repository/services/JSONPOJOService.aar/META-INF/services.xml
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/test-repository/services/JSONPOJOService.aar/META-INF/services.xml?rev=1463475&view=auto
==============================================================================
---
axis/axis2/java/core/trunk/modules/json/test-repository/services/JSONPOJOService.aar/META-INF/services.xml
(added)
+++
axis/axis2/java/core/trunk/modules/json/test-repository/services/JSONPOJOService.aar/META-INF/services.xml
Tue Apr 2 10:45:25 2013
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+ ~ 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.
+ -->
+<service name="JSONPOJOService" scope="application" >
+ <description>POJO Service which expose to process under JSON
requests</description>
+ <messageReceivers>
+ <messageReceiver mep="http://www.w3.org/ns/wsdl/in-only"
class="org.apache.axis2.json.gson.rpc.JsonInOnlyRPCMessageReceiver"/>
+ <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out"
class="org.apache.axis2.json.gson.rpc.JsonRpcMessageReceiver"/>
+ </messageReceivers>
+ <parameter
name="ServiceClass">org.apache.axis2.json.gson.rpc.JSONPOJOService</parameter>
+</service>
Modified:
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/JSONXMLStreamAPITest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/JSONXMLStreamAPITest.java?rev=1463475&r1=1463474&r2=1463475&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/JSONXMLStreamAPITest.java
(original)
+++
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/JSONXMLStreamAPITest.java
Tue Apr 2 10:45:25 2013
@@ -87,29 +87,17 @@ public class JSONXMLStreamAPITest {
"{\"author\":\"Jhon_4\",\"numOfPages\":175,\"publisher\":\"Foxier\",\"reviewers\":[\"rev1\",\"rev2\","
+
"\"rev3\"]}],\"staff\":50}}}";
- String actualResponse = post(echoLibrary, echoLibURL, contentType,
charSet);
+ String actualResponse = UtilTest.post(echoLibrary, echoLibURL,
contentType, charSet);
Assert.assertNotNull(actualResponse);
Assert.assertEquals(echoLibraryResponse , actualResponse);
- String actualRespose_2 = post(getLibrary, getLibURL, contentType,
charSet);
+ String actualRespose_2 = UtilTest.post(getLibrary, getLibURL,
contentType, charSet);
Assert.assertNotNull(actualRespose_2);
Assert.assertEquals(getLibraryResponse, actualRespose_2);
}
- public String post(String jsonString, String strURL, String
contentType, String charSet)
- throws IOException {
- PostMethod post = new PostMethod(strURL);
- RequestEntity entity = new StringRequestEntity(jsonString,
contentType, charSet);
- post.setRequestEntity(entity);
- HttpClient httpclient = new HttpClient();
- try {
- int result = httpclient.executeMethod(post);
- return post.getResponseBodyAsString();
- }finally {
- post.releaseConnection();
- }
- }
+
}
Added:
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/UtilTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/UtilTest.java?rev=1463475&view=auto
==============================================================================
---
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/UtilTest.java
(added)
+++
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/UtilTest.java
Tue Apr 2 10:45:25 2013
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+package org.apache.axis2.json.gson;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+
+import java.io.IOException;
+
+public class UtilTest {
+
+ public static String post(String jsonString, String strURL, String
contentType, String charSet)
+ throws IOException {
+ PostMethod post = new PostMethod(strURL);
+ RequestEntity entity = new StringRequestEntity(jsonString,
contentType, charSet);
+ post.setRequestEntity(entity);
+ HttpClient httpclient = new HttpClient();
+ try {
+ int result = httpclient.executeMethod(post);
+ return post.getResponseBodyAsString();
+ }finally {
+ post.releaseConnection();
+ }
+ }
+}
Added:
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/JSONPOJOService.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/JSONPOJOService.java?rev=1463475&view=auto
==============================================================================
---
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/JSONPOJOService.java
(added)
+++
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/JSONPOJOService.java
Tue Apr 2 10:45:25 2013
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+package org.apache.axis2.json.gson.rpc;
+
+public class JSONPOJOService {
+
+ public Person echoPerson(Person person) {
+ return person;
+ }
+
+ public void ping(Person person){
+ // nothing to do
+ }
+}
Added:
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/JSONRPCIntegrationTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/JSONRPCIntegrationTest.java?rev=1463475&view=auto
==============================================================================
---
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/JSONRPCIntegrationTest.java
(added)
+++
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/JSONRPCIntegrationTest.java
Tue Apr 2 10:45:25 2013
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+package org.apache.axis2.json.gson.rpc;
+
+import junit.framework.Assert;
+import org.apache.axis2.json.gson.UtilTest;
+import org.apache.axis2.testutils.UtilServer;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JSONRPCIntegrationTest {
+ String contentType = "application/json";
+ String charSet = "UTF-8";
+
+ @BeforeClass
+ public static void startTestServer() throws Exception {
+ UtilServer.start("test-repository", "test-conf/axis2_json.xml");
+ }
+
+ @AfterClass
+ public static void stopTestServer() throws Exception {
+ UtilServer.stop();
+ }
+
+ @Test
+ public void testJsonRpcMessageReceiver() throws Exception {
+ String jsonRequest =
"{\"echoPerson\":[{\"arg0\":{\"name\":\"Simon\",\"age\":\"35\",\"gender\":\"male\"}}]}";
+ String echoPersonUrl = "http://localhost:" + UtilServer.TESTING_PORT
+"/axis2/services/JSONPOJOService/echoPerson";
+ String expectedResponse =
"{\"response\":{\"name\":\"Simon\",\"age\":\"35\",\"gender\":\"male\"}}";
+ String response = UtilTest.post(jsonRequest, echoPersonUrl,
contentType, charSet);
+ Assert.assertNotNull(response);
+ Assert.assertEquals(expectedResponse , response);
+ }
+
+ @Test
+ public void testJsonInOnlyRPCMessageReceiver() throws Exception {
+ String jsonRequest =
"{\"ping\":[{\"arg0\":{\"name\":\"Simon\",\"age\":\"35\",\"gender\":\"male\"}}]}";
+ String echoPersonUrl = "http://localhost:" + UtilServer.TESTING_PORT
+"/axis2/services/JSONPOJOService/ping";
+ String response = UtilTest.post(jsonRequest, echoPersonUrl,
contentType, charSet);
+ Assert.assertEquals("", response);
+ }
+}
Added:
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/Person.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/Person.java?rev=1463475&view=auto
==============================================================================
---
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/Person.java
(added)
+++
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/gson/rpc/Person.java
Tue Apr 2 10:45:25 2013
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+package org.apache.axis2.json.gson.rpc;
+
+public class Person {
+
+ private String name;
+ private String age;
+ private String gender;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getGender() {
+ return gender;
+ }
+
+ public void setGender(String gender) {
+ this.gender = gender;
+ }
+
+ public String getAge() {
+ return age;
+ }
+
+ public void setAge(String age) {
+ this.age = age;
+ }
+}
+