Author: richard.opalka(a)jboss.com
Date: 2010-11-08 06:34:20 -0500 (Mon, 08 Nov 2010)
New Revision: 13242
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/InputStreamDataSource.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/JBWS3084TestCase.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceIface.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceImpl.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/jbws3084/
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/jbws3084/WEB-INF/
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/jbws3084/WEB-INF/web.xml
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/jbws3084/WEB-INF/wsdl/
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/jbws3084/WEB-INF/wsdl/SaajService.wsdl
Removed:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/InputStreamDataSource.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/SOAPConnectionTestCase.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceIface.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceImpl.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/cxf/
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml
Log:
[JBWS-3084] refactoring test case
Modified: stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml 2010-11-08
04:34:47 UTC (rev 13241)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml 2010-11-08
11:34:20 UTC (rev 13242)
@@ -51,7 +51,7 @@
<include
name="org/jboss/test/ws/jaxws/cxf/endorse/Helper.class"/>
</classes>
</war>
-
+
<!-- jaxws-cxf-gzip -->
<jar destfile="${tests.output.dir}/test-libs/jaxws-cxf-gzip.jar">
<fileset dir="${tests.output.dir}/test-classes">
@@ -70,7 +70,7 @@
<include name="**/*" />
</metainf>
</jar>
-
+
<!-- jaxws-cxf-jbws3060 -->
<jar
destfile="${tests.output.dir}/test-libs/jaxws-cxf-jbws3060.jar">
<fileset dir="${tests.output.dir}/test-classes">
@@ -98,11 +98,11 @@
<!-- jaxws-cxf-management -->
<war warfile="${tests.output.dir}/test-libs/jaxws-cxf-management.war"
webxml="${tests.output.dir}/test-resources/jaxws/cxf/management/WEB-INF/web.xml">
<classes dir="${tests.output.dir}/test-classes">
- <include
name="org/jboss/test/ws/jaxws/cxf/management/HelloWorldImpl.class" />
- <include
name="org/jboss/test/ws/jaxws/cxf/management/HelloWorld.class"/>
- </classes>
+ <include
name="org/jboss/test/ws/jaxws/cxf/management/HelloWorldImpl.class" />
+ <include
name="org/jboss/test/ws/jaxws/cxf/management/HelloWorld.class"/>
+ </classes>
</war>
-
+
<!-- jaxws-samples-mtom -->
<war
warfile="${tests.output.dir}/test-libs/jaxws-samples-mtom.war"
@@ -115,7 +115,7 @@
dir="${tests.output.dir}/test-resources/jaxws/samples/mtom/WEB-INF/wsdl"
prefix="WEB-INF/wsdl"/>
</war>
-
+
<!-- jaxws-samples-wsa -->
<war
warfile="${tests.output.dir}/test-libs/jaxws-samples-wsa.war"
@@ -137,25 +137,23 @@
dir="${tests.output.dir}/test-resources/jaxws/samples/wsrm/WEB-INF/wsdl"
prefix="WEB-INF/wsdl"/>
</war>
-
+
<!-- saaj-soap-connection -->
<war
warfile="${tests.output.dir}/test-libs/saaj-soap-connection.war"
-
webxml="${tests.output.dir}/test-resources/saaj/cxf/WEB-INF/web.xml">
+
webxml="${tests.output.dir}/test-resources/saaj/jbws3084/WEB-INF/web.xml">
<classes dir="${tests.output.dir}/test-classes">
- <include name="org/jboss/test/ws/saaj/ServiceImpl.class"/>
- <include name="org/jboss/test/ws/saaj/ServiceIface.class"/>
- <include
name="org/jboss/test/ws/saaj/InputStreamDataSource.class"/>
+ <include
name="org/jboss/test/ws/saaj/jbws3084/ServiceImpl.class"/>
+ <include
name="org/jboss/test/ws/saaj/jbws3084/ServiceIface.class"/>
+ <include
name="org/jboss/test/ws/saaj/jbws3084/InputStreamDataSource.class"/>
</classes>
<zipfileset
- dir="${tests.output.dir}/test-resources/saaj/cxf/WEB-INF/wsdl"
+ dir="${tests.output.dir}/test-resources/saaj/jbws3084/WEB-INF/wsdl"
prefix="WEB-INF/wsdl"/>
</war>
-
<!-- Please add alphabetically -->
-
</target>
</project>
Deleted:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/InputStreamDataSource.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/InputStreamDataSource.java 2010-11-08
04:34:47 UTC (rev 13241)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/InputStreamDataSource.java 2010-11-08
11:34:20 UTC (rev 13242)
@@ -1,44 +0,0 @@
-package org.jboss.test.ws.saaj;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import javax.activation.DataSource;
-
-public class InputStreamDataSource implements DataSource
-{
-
- private InputStream is;
- private String contentType;
- private String name;
-
- public InputStreamDataSource(InputStream is, String contentType, String name)
- {
- this.is = is;
- this.contentType = contentType;
- this.name = name;
- }
- @Override
- public String getContentType()
- {
- return contentType;
- }
-
- @Override
- public InputStream getInputStream() throws IOException
- {
- return is;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public OutputStream getOutputStream() throws IOException {
- throw new UnsupportedOperationException();
- }
-
-}
Deleted:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/SOAPConnectionTestCase.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/SOAPConnectionTestCase.java 2010-11-08
04:34:47 UTC (rev 13241)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/SOAPConnectionTestCase.java 2010-11-08
11:34:20 UTC (rev 13242)
@@ -1,138 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.test.ws.saaj;
-
-import java.net.URL;
-import java.util.Arrays;
-import java.util.Iterator;
-
-import javax.xml.namespace.QName;
-import javax.xml.soap.AttachmentPart;
-import javax.xml.soap.MessageFactory;
-import javax.xml.soap.SOAPConnection;
-import javax.xml.soap.SOAPConnectionFactory;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPFactory;
-import javax.xml.soap.SOAPMessage;
-
-import junit.framework.Test;
-
-import org.jboss.wsf.test.JBossWSTest;
-import org.jboss.wsf.test.JBossWSCXFTestSetup;
-
-/**
- *
- * @author sberyozk(a)redhat.com
- *
- */
-public class SOAPConnectionTestCase extends JBossWSTest
-{
- public static Test suite()
- {
- return new JBossWSCXFTestSetup(SOAPConnectionTestCase.class,
"saaj-soap-connection.war");
- }
-
- public void testSoapConnectionPostWithoutChunkedEncoding() throws Exception
- {
- doTestSoapConnection(true);
- }
-
- public void testSoapConnectionPostWithChunkedEncoding() throws Exception
- {
- doTestSoapConnection(false);
- }
-
- public void testSoapConnectionGet() throws Exception
- {
- final String serviceURL = "http://" + getServerHost() +
":8080/saaj-soap-connection/greetMe";
- SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
-
- SOAPConnection con = conFac.createConnection();
- URL endpoint = new URL(serviceURL);
- SOAPMessage response = con.get(endpoint);
- QName greetMeResp = new
QName("http://www.jboss.org/jbossws/saaj",
"greetMeResponse");
-
- Iterator<?> sayHiRespIterator =
response.getSOAPBody().getChildElements(greetMeResp);
- SOAPElement soapElement = (SOAPElement)sayHiRespIterator.next();
- assertNotNull(soapElement);
-
- assertEquals(1, response.countAttachments());
- }
-
- private void doTestSoapConnection(boolean disableChunking) throws Exception
- {
- SOAPFactory soapFac = SOAPFactory.newInstance();
- MessageFactory msgFac = MessageFactory.newInstance();
- SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
- SOAPMessage msg = msgFac.createMessage();
-
- if (disableChunking)
- {
- // this is the custom header checked by ServiceImpl
- msg.getMimeHeaders().addHeader("Transfer-Encoding-Disabled",
"true");
- // this is a hint to SOAPConnection that the chunked encoding is not needed
- msg.getMimeHeaders().addHeader("Transfer-Encoding",
"disabled");
- }
-
- QName sayHi = new
QName("http://www.jboss.org/jbossws/saaj",
"sayHello");
- msg.getSOAPBody().addChildElement(soapFac.createElement(sayHi));
- AttachmentPart ap1 = msg.createAttachmentPart();
-
- char[] content = new char[16 * 1024];
- Arrays.fill(content, 'A');
-
- ap1.setContent(new String(content), "text/plain");
- msg.addAttachmentPart(ap1);
-
- AttachmentPart ap2 = msg.createAttachmentPart();
- ap2.setContent("Attachment content - Part 2", "text/plain");
- msg.addAttachmentPart(ap2);
- msg.saveChanges();
-
- SOAPConnection con = conFac.createConnection();
-
- final String serviceURL = "http://" + getServerHost() +
":8080/saaj-soap-connection";
-
- URL endpoint = new URL(serviceURL);
- SOAPMessage response = con.call(msg, endpoint);
- QName sayHiResp = new
QName("http://www.jboss.org/jbossws/saaj",
"sayHelloResponse");
-
- Iterator<?> sayHiRespIterator =
response.getSOAPBody().getChildElements(sayHiResp);
- SOAPElement soapElement = (SOAPElement)sayHiRespIterator.next();
- assertNotNull(soapElement);
-
- assertEquals(2, response.countAttachments());
-
- String[] values =
response.getMimeHeaders().getHeader("Transfer-Encoding-Disabled");
- if (disableChunking)
- {
- // this means that the ServiceImpl executed the code branch verifying
- // that chunking was disabled
- assertNotNull(values);
- assertTrue(values.length == 1);
- }
- else
- {
- assertNull(values);
- }
- }
-}
Deleted:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceIface.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceIface.java 2010-11-08
04:34:47 UTC (rev 13241)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceIface.java 2010-11-08
11:34:20 UTC (rev 13242)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.test.ws.saaj;
-
-import javax.jws.WebMethod;
-import javax.jws.WebService;
-
-@WebService
-(
- targetNamespace = "http://www.jboss.org/jbossws/saaj"
-)
-public interface ServiceIface
-{
- @WebMethod
- String sayHello();
-
- @WebMethod
- String greetMe();
-}
Deleted:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceImpl.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceImpl.java 2010-11-08
04:34:47 UTC (rev 13241)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/ServiceImpl.java 2010-11-08
11:34:20 UTC (rev 13242)
@@ -1,141 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.test.ws.saaj;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.activation.DataHandler;
-import javax.annotation.Resource;
-import javax.jws.WebService;
-import javax.xml.ws.WebServiceContext;
-import javax.xml.ws.handler.MessageContext;
-
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
-
-@WebService
-(
- portName = "SaajServicePort",
- serviceName = "SaajService",
- wsdlLocation = "WEB-INF/wsdl/SaajService.wsdl",
- targetNamespace = "http://www.jboss.org/jbossws/saaj",
- endpointInterface = "org.jboss.test.ws.saaj.ServiceIface"
-)
-public class ServiceImpl implements ServiceIface
-{
- @Resource
- private WebServiceContext context;
-
- public String sayHello()
- {
- Map<String, List<String>> reqHeaders = CastUtils.cast(
- (Map<?,
?>)context.getMessageContext().get(MessageContext.HTTP_REQUEST_HEADERS));
-
- boolean chunkedEncodingDisabled =
reqHeaders.get("transfer-encoding-disabled") != null;
-
- List<String> transferEncHeader = reqHeaders.get("transfer-encoding");
-
- if (!chunkedEncodingDisabled)
- {
- if (transferEncHeader == null || transferEncHeader.size() != 1)
- {
- throw new RuntimeException("Transfer-Encoding is missing");
- }
- if (!"chunked".equals(transferEncHeader.get(0)))
- {
- throw new RuntimeException("Wrong Transfer-Encoding value");
- }
- }
- else
- {
- if (transferEncHeader != null)
- {
- throw new RuntimeException("Unexpected Transfer-Encoding header");
- }
- Map<String, List<String>> respHeaders = CastUtils.cast(
- (Map<?,
?>)context.getMessageContext().get(MessageContext.HTTP_RESPONSE_HEADERS));
- if (respHeaders == null) {
- respHeaders = new HashMap<String, List<String>>();
- context.getMessageContext().put(MessageContext.HTTP_RESPONSE_HEADERS,
respHeaders);
- }
- respHeaders.put("Transfer-Encoding-Disabled",
Arrays.asList("true"));
- }
-
- Map<String, DataHandler> dataHandlers = CastUtils.cast(
- (Map<?,
?>)context.getMessageContext().get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS));
-
- Map<String, DataHandler> outDataHandlers = CastUtils.cast(
- (Map<?,
?>)context.getMessageContext().get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS));
-
- int index = 0;
- try
- {
- for (Map.Entry<String, DataHandler> entry : dataHandlers.entrySet())
- {
- InputStream is = entry.getValue().getInputStream();
- LoadingByteArrayOutputStream bous = new LoadingByteArrayOutputStream();
- IOUtils.copy(is, bous);
- String name = Integer.toString(index++);
- DataHandler handler = new DataHandler(
- new InputStreamDataSource(bous.createInputStream(), "text/plain",
name));
- outDataHandlers.put(name, handler);
- }
- }
- catch (Exception ex)
- {
- throw new RuntimeException(ex);
- }
-
- return "Hello World!";
- }
-
- public String greetMe()
- {
- try
- {
- Map<String, DataHandler> outDataHandlers = CastUtils.cast(
- (Map<?,
?>)context.getMessageContext().get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS));
-
- final char[] content = new char[16 * 1024];
- Arrays.fill(content, 'A');
-
- DataHandler handler = new DataHandler(
- new InputStreamDataSource(new ByteArrayInputStream(new
String(content).getBytes()),
- "text/plain", "1"));
- outDataHandlers.put("1", handler);
-
- }
- catch (Exception ex)
- {
- throw new RuntimeException(ex);
- }
-
- return "Greetings";
- }
-
-}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/InputStreamDataSource.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/InputStreamDataSource.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/InputStreamDataSource.java 2010-11-08
11:34:20 UTC (rev 13242)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.saaj.jbws3084;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.activation.DataSource;
+
+public class InputStreamDataSource implements DataSource
+{
+ private InputStream is;
+
+ private String contentType;
+
+ private String name;
+
+ public InputStreamDataSource(InputStream is, String contentType, String name)
+ {
+ this.is = is;
+ this.contentType = contentType;
+ this.name = name;
+ }
+
+ @Override
+ public String getContentType()
+ {
+ return contentType;
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException
+ {
+ return is;
+ }
+
+ @Override
+ public String getName()
+ {
+ return name;
+ }
+
+ @Override
+ public OutputStream getOutputStream() throws IOException
+ {
+ throw new UnsupportedOperationException();
+ }
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/JBWS3084TestCase.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/JBWS3084TestCase.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/JBWS3084TestCase.java 2010-11-08
11:34:20 UTC (rev 13242)
@@ -0,0 +1,138 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.saaj.jbws3084;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.AttachmentPart;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPConnection;
+import javax.xml.soap.SOAPConnectionFactory;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPMessage;
+
+import junit.framework.Test;
+
+import org.jboss.wsf.test.JBossWSTest;
+import org.jboss.wsf.test.JBossWSCXFTestSetup;
+
+/**
+ * [JBWS-3084] Enable control of chunked encoding when using SOAPConnection.
+ *
+ * @author sberyozk(a)redhat.com
+ */
+public class JBWS3084TestCase extends JBossWSTest
+{
+ public static Test suite()
+ {
+ return new JBossWSCXFTestSetup(JBWS3084TestCase.class,
"saaj-soap-connection.war");
+ }
+
+ public void testSoapConnectionPostWithoutChunkedEncoding() throws Exception
+ {
+ doTestSoapConnection(true);
+ }
+
+ public void testSoapConnectionPostWithChunkedEncoding() throws Exception
+ {
+ doTestSoapConnection(false);
+ }
+
+ public void testSoapConnectionGet() throws Exception
+ {
+ final String serviceURL = "http://" + getServerHost() +
":8080/saaj-soap-connection/greetMe";
+ SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
+
+ SOAPConnection con = conFac.createConnection();
+ URL endpoint = new URL(serviceURL);
+ SOAPMessage response = con.get(endpoint);
+ QName greetMeResp = new
QName("http://www.jboss.org/jbossws/saaj",
"greetMeResponse");
+
+ Iterator<?> sayHiRespIterator =
response.getSOAPBody().getChildElements(greetMeResp);
+ SOAPElement soapElement = (SOAPElement) sayHiRespIterator.next();
+ assertNotNull(soapElement);
+
+ assertEquals(1, response.countAttachments());
+ }
+
+ private void doTestSoapConnection(boolean disableChunking) throws Exception
+ {
+ SOAPFactory soapFac = SOAPFactory.newInstance();
+ MessageFactory msgFac = MessageFactory.newInstance();
+ SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
+ SOAPMessage msg = msgFac.createMessage();
+
+ if (disableChunking)
+ {
+ // this is the custom header checked by ServiceImpl
+ msg.getMimeHeaders().addHeader("Transfer-Encoding-Disabled",
"true");
+ // this is a hint to SOAPConnection that the chunked encoding is not needed
+ msg.getMimeHeaders().addHeader("Transfer-Encoding",
"disabled");
+ }
+
+ QName sayHi = new
QName("http://www.jboss.org/jbossws/saaj",
"sayHello");
+ msg.getSOAPBody().addChildElement(soapFac.createElement(sayHi));
+ AttachmentPart ap1 = msg.createAttachmentPart();
+
+ char[] content = new char[16 * 1024];
+ Arrays.fill(content, 'A');
+
+ ap1.setContent(new String(content), "text/plain");
+ msg.addAttachmentPart(ap1);
+
+ AttachmentPart ap2 = msg.createAttachmentPart();
+ ap2.setContent("Attachment content - Part 2", "text/plain");
+ msg.addAttachmentPart(ap2);
+ msg.saveChanges();
+
+ SOAPConnection con = conFac.createConnection();
+
+ final String serviceURL = "http://" + getServerHost() +
":8080/saaj-soap-connection";
+
+ URL endpoint = new URL(serviceURL);
+ SOAPMessage response = con.call(msg, endpoint);
+ QName sayHiResp = new
QName("http://www.jboss.org/jbossws/saaj",
"sayHelloResponse");
+
+ Iterator<?> sayHiRespIterator =
response.getSOAPBody().getChildElements(sayHiResp);
+ SOAPElement soapElement = (SOAPElement) sayHiRespIterator.next();
+ assertNotNull(soapElement);
+
+ assertEquals(2, response.countAttachments());
+
+ String[] values =
response.getMimeHeaders().getHeader("Transfer-Encoding-Disabled");
+ if (disableChunking)
+ {
+ // this means that the ServiceImpl executed the code branch verifying
+ // that chunking was disabled
+ assertNotNull(values);
+ assertTrue(values.length == 1);
+ }
+ else
+ {
+ assertNull(values);
+ }
+ }
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceIface.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceIface.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceIface.java 2010-11-08
11:34:20 UTC (rev 13242)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.saaj.jbws3084;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+
+@WebService(targetNamespace = "http://www.jboss.org/jbossws/saaj")
+public interface ServiceIface
+{
+ @WebMethod
+ String sayHello();
+
+ @WebMethod
+ String greetMe();
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceImpl.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceImpl.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceImpl.java 2010-11-08
11:34:20 UTC (rev 13242)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.saaj.jbws3084;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.activation.DataHandler;
+import javax.annotation.Resource;
+import javax.jws.WebService;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
+
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
+
+@WebService(portName = "SaajServicePort", serviceName =
"SaajService", wsdlLocation = "WEB-INF/wsdl/SaajService.wsdl",
targetNamespace = "http://www.jboss.org/jbossws/saaj", endpointInterface =
"org.jboss.test.ws.saaj.jbws3084.ServiceIface")
+public class ServiceImpl implements ServiceIface
+{
+ @Resource
+ private WebServiceContext context;
+
+ public String sayHello()
+ {
+ Map<String, List<String>> reqHeaders = CastUtils.cast((Map<?, ?>)
context.getMessageContext().get(
+ MessageContext.HTTP_REQUEST_HEADERS));
+
+ boolean chunkedEncodingDisabled =
reqHeaders.get("transfer-encoding-disabled") != null;
+
+ List<String> transferEncHeader =
reqHeaders.get("transfer-encoding");
+
+ if (!chunkedEncodingDisabled)
+ {
+ if (transferEncHeader == null || transferEncHeader.size() != 1)
+ {
+ throw new RuntimeException("Transfer-Encoding is missing");
+ }
+ if (!"chunked".equals(transferEncHeader.get(0)))
+ {
+ throw new RuntimeException("Wrong Transfer-Encoding value");
+ }
+ }
+ else
+ {
+ if (transferEncHeader != null)
+ {
+ throw new RuntimeException("Unexpected Transfer-Encoding header");
+ }
+ Map<String, List<String>> respHeaders = CastUtils.cast((Map<?,
?>) context.getMessageContext().get(
+ MessageContext.HTTP_RESPONSE_HEADERS));
+ if (respHeaders == null)
+ {
+ respHeaders = new HashMap<String, List<String>>();
+ context.getMessageContext().put(MessageContext.HTTP_RESPONSE_HEADERS,
respHeaders);
+ }
+ respHeaders.put("Transfer-Encoding-Disabled",
Arrays.asList("true"));
+ }
+
+ Map<String, DataHandler> dataHandlers = CastUtils.cast((Map<?, ?>)
context.getMessageContext().get(
+ MessageContext.INBOUND_MESSAGE_ATTACHMENTS));
+
+ Map<String, DataHandler> outDataHandlers = CastUtils.cast((Map<?, ?>)
context.getMessageContext().get(
+ MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS));
+
+ int index = 0;
+ try
+ {
+ for (Map.Entry<String, DataHandler> entry : dataHandlers.entrySet())
+ {
+ InputStream is = entry.getValue().getInputStream();
+ LoadingByteArrayOutputStream bous = new LoadingByteArrayOutputStream();
+ IOUtils.copy(is, bous);
+ String name = Integer.toString(index++);
+ DataHandler handler = new DataHandler(new
InputStreamDataSource(bous.createInputStream(), "text/plain",
+ name));
+ outDataHandlers.put(name, handler);
+ }
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException(ex);
+ }
+
+ return "Hello World!";
+ }
+
+ public String greetMe()
+ {
+ try
+ {
+ Map<String, DataHandler> outDataHandlers = CastUtils.cast((Map<?,
?>) context.getMessageContext().get(
+ MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS));
+
+ final char[] content = new char[16 * 1024];
+ Arrays.fill(content, 'A');
+
+ DataHandler handler = new DataHandler(new InputStreamDataSource(new
ByteArrayInputStream(
+ new String(content).getBytes()), "text/plain", "1"));
+ outDataHandlers.put("1", handler);
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException(ex);
+ }
+
+ return "Greetings";
+ }
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/jbws3084/WEB-INF/web.xml
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/jbws3084/WEB-INF/web.xml
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/jbws3084/WEB-INF/web.xml 2010-11-08
11:34:20 UTC (rev 13242)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app
+ version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <servlet>
+ <servlet-name>SaajService</servlet-name>
+
<servlet-class>org.jboss.test.ws.saaj.jbws3084.ServiceImpl</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>SaajService</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/jbws3084/WEB-INF/wsdl/SaajService.wsdl
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/jbws3084/WEB-INF/wsdl/SaajService.wsdl
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/saaj/jbws3084/WEB-INF/wsdl/SaajService.wsdl 2010-11-08
11:34:20 UTC (rev 13242)
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wsdl:definitions name="SaajService"
targetNamespace="http://www.jboss.org/jbossws/saaj"
xmlns:tns="http://www.jboss.org/jbossws/saaj"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
+ <wsdl:types>
+<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.jboss.org/jbossws/saaj"
attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="http://www.jboss.org/jbossws/saaj">
+<xsd:element name="sayHello" type="tns:sayHello"/>
+<xsd:complexType name="sayHello">
+<xsd:sequence/>
+</xsd:complexType>
+<xsd:element name="sayHelloResponse"
type="tns:sayHelloResponse"/>
+<xsd:complexType name="sayHelloResponse">
+<xsd:sequence>
+<xsd:element minOccurs="0" name="return"
type="xsd:string"/>
+</xsd:sequence>
+</xsd:complexType>
+
+<xsd:element name="greetMe" type="tns:greetMe"/>
+<xsd:complexType name="greetMe">
+<xsd:sequence/>
+</xsd:complexType>
+<xsd:element name="greetMeResponse"
type="tns:greetMeResponse"/>
+<xsd:complexType name="greetMeResponse">
+<xsd:sequence>
+<xsd:element minOccurs="0" name="return"
type="xsd:string"/>
+</xsd:sequence>
+</xsd:complexType>
+
+</xsd:schema>
+ </wsdl:types>
+ <wsdl:message name="sayHelloResponse">
+ <wsdl:part name="parameters"
element="tns:sayHelloResponse">
+ </wsdl:part>
+ </wsdl:message>
+ <wsdl:message name="sayHello">
+ <wsdl:part name="parameters" element="tns:sayHello">
+ </wsdl:part>
+ </wsdl:message>
+
+ <wsdl:message name="greetMeResponse">
+ <wsdl:part name="parameters"
element="tns:greetMeResponse">
+ </wsdl:part>
+ </wsdl:message>
+ <wsdl:message name="greetMe">
+ <wsdl:part name="parameters" element="tns:greetMe">
+ </wsdl:part>
+ </wsdl:message>
+
+ <wsdl:portType name="ServiceIface">
+ <wsdl:operation name="sayHello">
+ <wsdl:input name="sayHello" message="tns:sayHello">
+ </wsdl:input>
+ <wsdl:output name="sayHelloResponse"
message="tns:sayHelloResponse">
+ </wsdl:output>
+ </wsdl:operation>
+
+ <wsdl:operation name="greetMe">
+ <wsdl:input name="greetMe" message="tns:greetMe">
+ </wsdl:input>
+ <wsdl:output name="greetMeResponse"
message="tns:greetMeResponse">
+ </wsdl:output>
+ </wsdl:operation>
+
+ </wsdl:portType>
+ <wsdl:binding name="SaajServiceSoapBinding"
type="tns:ServiceIface">
+ <soap:binding style="document"
transport="http://schemas.xmlsoap.org/wsdl/http/"/>
+ <wsdl:operation name="sayHello">
+ <soap:operation soapAction="" style="document"/>
+ <wsdl:input name="sayHello">
+ <soap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output name="sayHelloResponse">
+ <soap:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+ <wsdl:operation name="greetMe">
+ <soap:operation soapAction="" style="document"/>
+ <wsdl:input name="greetMe">
+ <soap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output name="greetMeResponse">
+ <soap:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:service name="SaajService">
+ <wsdl:port name="SaajServicePort"
binding="tns:SaajServiceSoapBinding">
+ <soap:address location="http://localhost:8080/SaajService"/>
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>