You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ch...@apache.org on 2005/10/03 08:41:45 UTC
svn commit: r293268 - in /webservices/axis2/trunk/java/modules:
core/src/org/apache/axis2/transport/http/
integration/test/org/apache/axis2/engine/
integration/test/org/apache/axis2/engine/util/
Author: chinthaka
Date: Sun Oct 2 23:41:28 2005
New Revision: 293268
URL: http://svn.apache.org/viewcvs?rev=293268&view=rev
Log:
Fixing a threading issue. Problems seems to be in serializing the SOAP envelope. For the time being I made the invoke method of CommnonsHTTPTransportSender, synchronized. But I think we need to boil down this to the exact location.
Added a test case also. This test case will invoke the same service with given number of threads, which you can give in the thread.
Added:
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ThreadingTest.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/InvokerThread.java
Modified:
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java?rev=293268&r1=293267&r2=293268&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java Sun Oct 2 23:41:28 2005
@@ -74,7 +74,7 @@
public CommonsHTTPTransportSender() {
} //default
- public void invoke(MessageContext msgContext) throws AxisFault {
+ public synchronized void invoke(MessageContext msgContext) throws AxisFault {
try {
String charSetEnc =
(String) msgContext.getProperty(
@@ -83,14 +83,14 @@
omOutput.setCharSetEncoding(charSetEnc);
} else {
OperationContext opctx = msgContext.getOperationContext();
- if(opctx != null) {
- charSetEnc = (String)opctx.getProperty(MessageContext.CHARACTER_SET_ENCODING);
+ if (opctx != null) {
+ charSetEnc = (String) opctx.getProperty(MessageContext.CHARACTER_SET_ENCODING);
}
}
/**
* If the char set enc is still not found use the default
*/
- if(charSetEnc == null) {
+ if (charSetEnc == null) {
charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
}
msgContext.setDoingMTOM(HTTPTransportUtils.doWriteMTOM(msgContext));
@@ -133,7 +133,7 @@
omOutput.setSoap11(msgContext.isSOAP11());
transportInfo.setCharacterEncoding(omOutput.getCharSetEncoding());
transportInfo.setContentType(omOutput.getContentType());
- }else{
+ } else {
throw new AxisFault(HTTPConstants.HTTPOutTransportInfo + " does not set");
}
}
@@ -141,7 +141,7 @@
dataOut.serialize(omOutput);
omOutput.flush();
}
- if(msgContext.getOperationContext() != null){
+ if (msgContext.getOperationContext() != null) {
msgContext.getOperationContext().setProperty(
Constants.RESPONSE_WRITTEN,
Constants.VALUE_TRUE);
@@ -205,6 +205,7 @@
}
}
+
protected HostConfiguration getHostConfiguration(
MessageContext context,
URL targetURL) {
@@ -347,12 +348,12 @@
public String getContentType() {
String encoding = omOutput.getCharSetEncoding();
String contentType = omOutput.getContentType();
- if(encoding != null){
+ if (encoding != null) {
contentType += "; charset=" + encoding;
}
// action header is not mandated in SOAP 1.2. So putting it, if available
- if(!msgCtxt.isSOAP11() && soapActionString != null && !"".equals(soapActionString.trim())) {
+ if (!msgCtxt.isSOAP11() && soapActionString != null && !"".equals(soapActionString.trim())) {
contentType = contentType + ";action=" + soapActionString + ";";
}
return contentType;
@@ -455,7 +456,7 @@
String charEncoding =
(String) msgContext.getProperty(
MessageContext.CHARACTER_SET_ENCODING);
- if(charEncoding == null){
+ if (charEncoding == null) {
charEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
}
@@ -505,17 +506,17 @@
processResponse(postMethod, msgContext);
} else if (postMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
return;
- } else if (postMethod.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR){
+ } else if (postMethod.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
Header contenttypeHheader = postMethod.getResponseHeader(
HTTPConstants.HEADER_CONTENT_TYPE);
String value = contenttypeHheader.getValue();
- if(value != null){
- if(value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE)>=0||
- value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >=0){
+ if (value != null) {
+ if (value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0 ||
+ value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >= 0) {
processResponse(postMethod, msgContext);
- } else {
+ } else {
/**
* if the content type is text/html;charset=utf-8
*/
@@ -526,7 +527,7 @@
postMethod.getResponseBodyAsString()));
}
}
- }else{
+ } else {
throw new AxisFault(
Messages.getMessage(
"transportError",
@@ -537,9 +538,10 @@
}
/**
- * This is used to get the dynamically set time out values from the
+ * This is used to get the dynamically set time out values from the
* message context. If the values are not available or invalid then
* teh default values or the values set by teh configuration will be used
+ *
* @param msgContext
*/
private void getTimoutValues(MessageContext msgContext) {
@@ -612,20 +614,20 @@
processResponse(getMethod, msgContext);
} else if (getMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
return;
- }else if (getMethod.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR){
+ } else if (getMethod.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
Header contenttypeHheader = getMethod.getResponseHeader(
HTTPConstants.HEADER_CONTENT_TYPE);
String value = contenttypeHheader.getValue();
- if(value != null){
- if(value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE)>=0||
- value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >=0){
+ if (value != null) {
+ if (value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0 ||
+ value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >= 0) {
processResponse(getMethod, msgContext);
}
}
- }else{
+ } else {
throw new AxisFault(
Messages.getMessage(
"transportError",
@@ -636,10 +638,11 @@
/**
* Collect the HTTP header information and set them in the message context
+ *
* @param method
* @param msgContext
*/
- private void obatainHTTPHeaderInformation(HttpMethodBase method,MessageContext msgContext) {
+ private void obatainHTTPHeaderInformation(HttpMethodBase method, MessageContext msgContext) {
Header header =
method.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
if (header != null) {
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ThreadingTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ThreadingTest.java?rev=293268&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ThreadingTest.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ThreadingTest.java Sun Oct 2 23:41:28 2005
@@ -0,0 +1,108 @@
+package org.apache.axis2.engine;
+
+import junit.framework.TestCase;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.description.ServiceDescription;
+import org.apache.axis2.engine.util.InvokerThread;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * @author : Eran Chinthaka (chinthaka@apache.org)
+ */
+
+public class ThreadingTest extends TestCase {
+
+ protected EndpointReference targetEPR =
+ new EndpointReference("http://127.0.0.1:"
+ + (UtilServer.TESTING_PORT)
+ + "/axis/services/EchoXMLService/echoOMElement");
+ protected Log log = LogFactory.getLog(getClass());
+ protected QName serviceName = new QName("EchoXMLService");
+ protected QName operationName = new QName("echoOMElement");
+ protected QName transportName = new QName("http://localhost/my",
+ "NullTransport");
+
+ protected AxisConfiguration engineRegistry;
+ protected MessageContext mc;
+ protected ServiceContext serviceContext;
+ protected ServiceDescription service;
+
+ protected boolean finish = false;
+
+ protected void setUp() throws Exception {
+ UtilServer.start();
+ service =
+ Utils.createSimpleService(serviceName,
+ Echo.class.getName(),
+ operationName);
+ UtilServer.deployService(service);
+ }
+
+ protected void tearDown() throws Exception {
+ UtilServer.unDeployService(serviceName);
+ UtilServer.stop();
+ UtilServer.unDeployClientService();
+ }
+
+ public void testEchoXMLSync() throws Exception {
+
+
+ int numberOfThreads = 5;
+ InvokerThread[] invokerThreads = new InvokerThread[numberOfThreads];
+
+ for (int i = 0; i < numberOfThreads; i++) {
+ InvokerThread invokerThread = new InvokerThread(i + 1);
+ invokerThreads[i] = invokerThread;
+ invokerThread.start();
+ }
+
+ boolean threadsAreRunning;
+ Calendar cal = new GregorianCalendar();
+ int min = cal.get(Calendar.MINUTE);
+
+ do {
+ threadsAreRunning = false;
+ for (int i = 0; i < numberOfThreads; i++) {
+ if (invokerThreads[i].isAlive()) {
+ threadsAreRunning = true;
+ break;
+ }
+ if (invokerThreads[i].isExceptionThrown()) {
+ fail("Exception thrown in thread "+ i + " ....");
+ }
+ }
+
+ // waiting 3 seconds, if not finish, time out.
+ if (Math.abs(min - new GregorianCalendar().get(Calendar.MINUTE)) > 1) {
+ log.info("I'm timing out. Can't wait more than this to finish.");
+ fail("Timing out");
+ }
+
+ } while (threadsAreRunning);
+
+ assertTrue(true);
+ }
+}
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/InvokerThread.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/InvokerThread.java?rev=293268&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/InvokerThread.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/InvokerThread.java Sun Oct 2 23:41:28 2005
@@ -0,0 +1,76 @@
+package org.apache.axis2.engine.util;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.clientapi.Call;
+import org.apache.axis2.integration.TestingUtils;
+import org.apache.axis2.om.OMElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * @author : Eran Chinthaka (chinthaka@apache.org)
+ */
+
+public class InvokerThread extends Thread {
+
+ private int threadNumber;
+ protected EndpointReference targetEPR =
+ new EndpointReference("http://127.0.0.1:"
+ + (5556)
+// + (UtilServer.TESTING_PORT)
+ + "/axis/services/EchoXMLService/echoOMElement");
+ protected QName operationName = new QName("echoOMElement");
+ protected Log log = LogFactory.getLog(getClass());
+ private boolean isExceptionThrown = false;
+
+ public InvokerThread(int threadNumber) {
+ this.threadNumber = threadNumber;
+ }
+
+ public void run() {
+ try {
+ log.info("Starting Thread number "+ threadNumber + " .............");
+ Call call =
+ new Call("target/test-resources/intregrationRepo");
+ OMElement payload = TestingUtils.createDummyOMElement();
+
+ call.setTo(targetEPR);
+ call.setTransportInfo(Constants.TRANSPORT_HTTP,
+ Constants.TRANSPORT_HTTP,
+ false);
+
+ OMElement result =
+ call.invokeBlocking(operationName.getLocalPart(),
+ payload);
+ TestingUtils.campareWithCreatedOMElement(result);
+ call.close();
+ log.info("Finishing Thread number "+ threadNumber + " .....");
+ isExceptionThrown = false;
+ } catch (AxisFault axisFault) {
+ isExceptionThrown = true;
+ log.error("Error has occured invoking the service ", axisFault);
+ }
+ }
+
+ public boolean isExceptionThrown() {
+ return isExceptionThrown;
+ }
+}