[jbossws-commits] JBossWS SVN: r13648 - in framework/branches/jbossws-framework-3.1.2/testsuite/test: java/org/jboss/test/ws and 7 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Mon Jan 31 06:07:19 EST 2011


Author: richard.opalka at jboss.com
Date: 2011-01-31 06:07:19 -0500 (Mon, 31 Jan 2011)
New Revision: 13648

Added:
   framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/
   framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/
   framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/InputStreamDataSource.java
   framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/JBWS3084TestCase.java
   framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceIface.java
   framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceImpl.java
   framework/branches/jbossws-framework-3.1.2/testsuite/test/resources/saaj/
   framework/branches/jbossws-framework-3.1.2/testsuite/test/resources/saaj/jbws3084/
   framework/branches/jbossws-framework-3.1.2/testsuite/test/resources/saaj/jbws3084/WEB-INF/
   framework/branches/jbossws-framework-3.1.2/testsuite/test/resources/saaj/jbws3084/WEB-INF/web.xml
   framework/branches/jbossws-framework-3.1.2/testsuite/test/resources/saaj/jbws3084/WEB-INF/wsdl/
   framework/branches/jbossws-framework-3.1.2/testsuite/test/resources/saaj/jbws3084/WEB-INF/wsdl/SaajService.wsdl
Modified:
   framework/branches/jbossws-framework-3.1.2/testsuite/test/ant-import/build-samples-jaxws.xml
Log:
[JBPAPP-4564][JBWS-3084] backporting test case

Modified: framework/branches/jbossws-framework-3.1.2/testsuite/test/ant-import/build-samples-jaxws.xml
===================================================================
--- framework/branches/jbossws-framework-3.1.2/testsuite/test/ant-import/build-samples-jaxws.xml	2011-01-31 11:00:23 UTC (rev 13647)
+++ framework/branches/jbossws-framework-3.1.2/testsuite/test/ant-import/build-samples-jaxws.xml	2011-01-31 11:07:19 UTC (rev 13648)
@@ -455,6 +455,20 @@
       </fileset>
     </jar>
     
+    <!-- saaj-jbws3084 -->
+    <war
+       warfile="${tests.output.dir}/test-libs/saaj-soap-connection.war"
+       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/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/jbws3084/WEB-INF/wsdl" 
+          prefix="WEB-INF/wsdl"/>
+    </war>
+
     <!-- Please add alphabetically -->
 
   </target>

Added: framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/InputStreamDataSource.java
===================================================================
--- framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/InputStreamDataSource.java	                        (rev 0)
+++ framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/InputStreamDataSource.java	2011-01-31 11:07:19 UTC (rev 13648)
@@ -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: framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/JBWS3084TestCase.java
===================================================================
--- framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/JBWS3084TestCase.java	                        (rev 0)
+++ framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/JBWS3084TestCase.java	2011-01-31 11:07:19 UTC (rev 13648)
@@ -0,0 +1,121 @@
+/*
+ * 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.JBossWSTestSetup;
+
+/**
+ * [JBWS-3084] Enable control of chunked encoding when using SOAPConnection.
+ *
+ * @author sberyozk at redhat.com
+ */
+public class JBWS3084TestCase extends JBossWSTest
+{
+   public static Test suite()
+   {
+      return new JBossWSTestSetup(JBWS3084TestCase.class, "saaj-soap-connection.war");
+   }
+
+   public void testSoapConnectionPostWithoutChunkedEncoding() throws Exception
+   {
+      doTestSoapConnection(true);
+   }
+
+   public void testSoapConnectionPostWithChunkedEncoding() throws Exception
+   {
+      doTestSoapConnection(false);
+   }
+
+   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: framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceIface.java
===================================================================
--- framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceIface.java	                        (rev 0)
+++ framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceIface.java	2011-01-31 11:07:19 UTC (rev 13648)
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+ at WebService(targetNamespace = "http://www.jboss.org/jbossws/saaj")
+public interface ServiceIface
+{
+   @WebMethod
+   String sayHello();
+}

Added: framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceImpl.java
===================================================================
--- framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceImpl.java	                        (rev 0)
+++ framework/branches/jbossws-framework-3.1.2/testsuite/test/java/org/jboss/test/ws/saaj/jbws3084/ServiceImpl.java	2011-01-31 11:07:19 UTC (rev 13648)
@@ -0,0 +1,110 @@
+/*
+ * 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.ByteArrayOutputStream;
+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.jboss.wsf.common.IOUtils;
+
+ at 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;
+
+   @SuppressWarnings("unchecked")
+   public String sayHello()
+   {
+      Map<String, List<String>> reqHeaders = (Map<String, List<String>>) 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 = (Map<String, List<String>>) 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 = (Map<String, DataHandler>) context.getMessageContext().get(
+            MessageContext.INBOUND_MESSAGE_ATTACHMENTS);
+
+      Map<String, DataHandler> outDataHandlers = (Map<String, DataHandler>) context.getMessageContext().get(
+            MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
+
+      int index = 0;
+      try
+      {
+         for (Map.Entry<String, DataHandler> entry : dataHandlers.entrySet())
+         {
+            InputStream is = entry.getValue().getInputStream();
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            IOUtils.copyStream(baos, is);
+            String name = Integer.toString(index++);
+            DataHandler handler = new DataHandler(new InputStreamDataSource(
+                  new ByteArrayInputStream(baos.toByteArray()), "text/plain", name));
+            outDataHandlers.put(name, handler);
+         }
+      }
+      catch (Exception ex)
+      {
+         throw new RuntimeException(ex);
+      }
+
+      return "Hello World!";
+   }
+}

Added: framework/branches/jbossws-framework-3.1.2/testsuite/test/resources/saaj/jbws3084/WEB-INF/web.xml
===================================================================
--- framework/branches/jbossws-framework-3.1.2/testsuite/test/resources/saaj/jbws3084/WEB-INF/web.xml	                        (rev 0)
+++ framework/branches/jbossws-framework-3.1.2/testsuite/test/resources/saaj/jbws3084/WEB-INF/web.xml	2011-01-31 11:07:19 UTC (rev 13648)
@@ -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: framework/branches/jbossws-framework-3.1.2/testsuite/test/resources/saaj/jbws3084/WEB-INF/wsdl/SaajService.wsdl
===================================================================
--- framework/branches/jbossws-framework-3.1.2/testsuite/test/resources/saaj/jbws3084/WEB-INF/wsdl/SaajService.wsdl	                        (rev 0)
+++ framework/branches/jbossws-framework-3.1.2/testsuite/test/resources/saaj/jbws3084/WEB-INF/wsdl/SaajService.wsdl	2011-01-31 11:07:19 UTC (rev 13648)
@@ -0,0 +1,55 @@
+<?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: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:portType name="ServiceIface">
+    <wsdl:operation name="sayHello">
+      <wsdl:input name="sayHello" message="tns:sayHello"/>
+      <wsdl:output name="sayHelloResponse" message="tns:sayHelloResponse"/>
+    </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:binding>
+
+  <wsdl:service name="SaajService">
+    <wsdl:port name="SaajServicePort" binding="tns:SaajServiceSoapBinding">
+      <soap:address location="http://@jboss.bind.address@:8080/SaajService"/>
+    </wsdl:port>
+  </wsdl:service>
+
+</wsdl:definitions>



More information about the jbossws-commits mailing list