You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sa...@apache.org on 2005/09/12 06:17:51 UTC
svn commit: r280246 - in
/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom:
EchoRawMTOMFaultReportTest.java EchoService.java wmtom.bin
Author: saminda
Date: Sun Sep 11 21:17:42 2005
New Revision: 280246
URL: http://svn.apache.org/viewcvs?rev=280246&view=rev
Log:
Add a mtom fault report test to intergration using HttpClient
Added:
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMFaultReportTest.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoService.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/wmtom.bin
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMFaultReportTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMFaultReportTest.java?rev=280246&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMFaultReportTest.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMFaultReportTest.java Sun Sep 11 21:17:42 2005
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2004,2005 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.
+ */
+
+package org.apache.axis2.mtom;
+
+import junit.framework.TestCase;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.httpclient.*;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.description.ServiceDescription;
+import org.apache.axis2.description.ParameterImpl;
+import org.apache.axis2.description.OperationDescription;
+import org.apache.axis2.swa.EchoRawSwATest;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.Constants;
+import org.apache.axis2.receivers.AbstractMessageReceiver;
+import org.apache.axis2.receivers.RawXMLINOutMessageReceiver;
+import org.apache.wsdl.WSDLService;
+
+import javax.xml.namespace.QName;
+import java.io.*;
+
+/**
+ * Author: Saminda Abeyruwan <sa...@wso2.com>
+ */
+public class EchoRawMTOMFaultReportTest extends TestCase {
+
+ private Log log = LogFactory.getLog(getClass());
+
+ private QName serviceName = new QName("EchoService");
+
+ private QName operationName = new QName("mtomSample");
+
+ private ServiceContext serviceContext;
+
+ private ServiceDescription service;
+
+ public EchoRawMTOMFaultReportTest() {
+ super(EchoRawSwATest.class.getName());
+ }
+
+ public EchoRawMTOMFaultReportTest(String testName) {
+ super(testName);
+ }
+
+ protected void setUp() throws Exception {
+ UtilServer.start(Constants.TESTING_PATH + "MTOM-enabledRepository");
+ service = new ServiceDescription(serviceName);
+ service.setClassLoader(Thread.currentThread().getContextClassLoader());
+ service.addParameter(new ParameterImpl(AbstractMessageReceiver.SERVICE_CLASS,
+ EchoService.class.getName()));
+
+ OperationDescription axisOp = new OperationDescription(operationName);
+ axisOp.setMessageReceiver(new RawXMLINOutMessageReceiver());
+ axisOp.setStyle(WSDLService.STYLE_DOC);
+ service.addOperation(axisOp);
+ UtilServer.deployService(service);
+ serviceContext = UtilServer.getConfigurationContext()
+ .createServiceContext(service.getName());
+
+ }
+
+ protected void tearDown() throws Exception {
+ UtilServer.unDeployService(serviceName);
+ UtilServer.stop();
+ }
+
+ public void testEchoFaultSync() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod httppost = new PostMethod("http://127.0.0.1:"
+ + (UtilServer.TESTING_PORT)
+ + "/axis/services/EchoService/mtomSample");
+
+ HttpMethodRetryHandler myretryhandler = new HttpMethodRetryHandler() {
+ public boolean retryMethod(final HttpMethod method,
+ final IOException exception,
+ int executionCount) {
+ if (executionCount >= 10) {
+ return false;
+ }
+ if (exception instanceof NoHttpResponseException) {
+ return true;
+ }
+ if (!method.isRequestSent()) {
+ return true;
+ }
+ // otherwise do not retry
+ return false;
+ }
+ };
+ httppost.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
+ myretryhandler);
+ httppost.setRequestEntity(new InputStreamRequestEntity(
+ this.getResourceAsStream("/org/apache/axis2/mtom/wmtom.bin")));
+
+ httppost.setRequestHeader("Content-Type",
+ "multipart/related; boundary=--MIMEBoundary258DE2D105298B756D; type=\"application/xop+xml\"; start=\"<0....@apache.org>\"; start-info=\"application/soap+xml\"");
+ try {
+ client.executeMethod(httppost);
+
+ if (httppost.getStatusCode() ==
+ HttpStatus.SC_INTERNAL_SERVER_ERROR) {
+ assertEquals("HTTP/1.1 500 Internal server error",
+ httppost.getStatusLine().toString());
+ }
+
+ } finally {
+ httppost.releaseConnection();
+ }
+ }
+
+ private InputStream getResourceAsStream(String path) {
+ return this.getClass().getResourceAsStream(path);
+ }
+}
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoService.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoService.java?rev=280246&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoService.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/EchoService.java Sun Sep 11 21:17:42 2005
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2004,2005 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.
+ */
+
+package org.apache.axis2.mtom;
+
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMText;
+
+import java.util.Iterator;
+
+
+public class EchoService {
+ public OMElement mtomSample(OMElement element) throws Exception {
+ if (element.getLocalName().equalsIgnoreCase("Data")
+ && element.getNamespace().getName().equalsIgnoreCase(
+ "http://example.org/mtom/data")) {
+ OMText binaryNode = (OMText)element.getFirstChild();
+ binaryNode.setOptimize(!binaryNode.isOptimized());
+ }
+ else if (element.getLocalName().equalsIgnoreCase("EchoTest") && element.getNamespace().getName().equalsIgnoreCase("http://example.org/mtom/data")) {
+ Iterator childrenIterator = element.getChildren();
+ while (childrenIterator.hasNext()) {
+ OMElement dataElement = (OMElement) childrenIterator.next();
+ OMText binaryNode = (OMText)dataElement.getFirstChild();
+ binaryNode.setOptimize(!binaryNode.isOptimized());
+ }
+ }
+ return element;
+ }
+}
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/wmtom.bin
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/wmtom.bin?rev=280246&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/wmtom.bin (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/wmtom.bin Sun Sep 11 21:17:42 2005
@@ -0,0 +1,21 @@
+----MIMEBoundary258DE2D105298B756D
+content-type:application/xop+xml; charset=utf-8; type="application/soap+xml"
+content-transfer-encoding:binary
+content-id:<0....@apache.org>
+
+<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Header><wsa:To xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">http://localhost:8070/axis2/services/MTOMService/mtomSample</wsa:To></soapenv:Header><soapenv:Body><x:EchoTest xmlns:x="http://example.org/mtom/data"><x:Data><xop:Include href="cid:1.BBFC8D48A21258EBBD@apache.org" xmlns:xop="http://www.w3.org/2004/08/xop/include"></xop:Include></x:Data><x:Data><xop:Include href="cid:2.CB365E36E21BD6491A@apache.org" xmlns:xop="http://www.w3.org/2004/08/xop/include"></xop:Include></x:Data></x:EchoTest></soapenv:Body></soapenv:Envelope>
+----MIMEBoundary258DE2D105298B756D
+content-id:<11...@apache.org>
+content-type:application/octet-stream
+content-transfer-encoding:binary
+
+saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda
+
+----MIMEBoundary258DE2D105298B756D
+content-id:<2....@apache.org>
+content-type:application/octet-stream
+content-transfer-encoding:binary
+
+saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda saminda
+
+----MIMEBoundary258DE2D105298B756D--