Author: alessio.soldano(a)jboss.com
Date: 2013-06-19 12:34:45 -0400 (Wed, 19 Jun 2013)
New Revision: 17712
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/ClientHandler.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/Endpoint.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/EndpointBean.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/JBWS3593TestCase.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/MTOMOutInterceptor.java
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml
Log:
[JBWS-3593] Adding testcase including workaround
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 2013-06-19
12:03:48 UTC (rev 17711)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml 2013-06-19
16:34:45 UTC (rev 17712)
@@ -343,6 +343,17 @@
</manifest>
</jar>
+ <!-- jaxws-cxf-jbws3593 -->
+ <war warfile="${tests.output.dir}/test-libs/jaxws-cxf-jbws3593.war"
needxmlfile='false'>
+ <classes dir="${tests.output.dir}/test-classes">
+ <include
name="org/jboss/test/ws/jaxws/cxf/jbws3593/EndpointBean.class" />
+ <include
name="org/jboss/test/ws/jaxws/cxf/jbws3593/MTOMOutInterceptor.class" />
+ </classes>
+ <manifest>
+ <attribute name="Dependencies"
value="org.apache.cxf"/>
+ </manifest>
+ </war>
+
<!-- jaxws-cxf-jbws3648 -->
<war warfile="${tests.output.dir}/test-libs/jaxws-cxf-jbws3648.war"
needxmlfile='false'>
<classes dir="${tests.output.dir}/test-classes">
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/ClientHandler.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/ClientHandler.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/ClientHandler.java 2013-06-19
16:34:45 UTC (rev 17712)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, 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.jaxws.cxf.jbws3593;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.mail.internet.ContentType;
+import javax.mail.internet.ParseException;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPConstants;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.api.handler.GenericSOAPHandler;
+
+public class ClientHandler extends GenericSOAPHandler
+{
+ private static Logger log = Logger.getLogger(ClientHandler.class);
+
+ private boolean checkMtom;
+
+ public ClientHandler(boolean checkMtom) {
+ super();
+ this.checkMtom = checkMtom;
+ }
+
+ public boolean handleInbound(MessageContext msgContext)
+ {
+ log.info("handleInbound");
+
+ try
+ {
+ SOAPEnvelope soapEnvelope =
(SOAPEnvelope)((SOAPMessageContext)msgContext).getMessage().getSOAPPart().getEnvelope();
+ String nsURI = soapEnvelope.getNamespaceURI();
+
+ log.info("nsURI=" + nsURI);
+
+ if (!SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(nsURI))
+ {
+ throw new RuntimeException("Wrong NS uri: " + nsURI);
+ }
+ }
+ catch (SOAPException se)
+ {
+ throw new WebServiceException(se);
+ }
+
+ ContentType contentType = getContentType(msgContext);
+
+ if (contentType != null)
+ {
+ log.info("contentType="+contentType);
+ String startInfo = contentType.getParameter("start-info");
+ if (!checkMtom) {
+ if (startInfo != null) {
+ throw new RuntimeException("Unexpected multipart/related
message!");
+ } else {
+ return true;
+ }
+ }
+ if (!startInfo.equals(SOAPConstants.SOAP_1_1_CONTENT_TYPE))
+ {
+ throw new RuntimeException("Wrong start info: " + startInfo);
+ }
+ }
+ else
+ {
+ throw new RuntimeException("Missing content type");
+ }
+
+ return true;
+ }
+
+ protected ContentType getContentType(MessageContext msgContext)
+ {
+ ContentType contentType = null;
+
+ try
+ {
+ Map<String, List> headers =
(Map)msgContext.get(MessageContext.HTTP_RESPONSE_HEADERS);
+ List<String> ctype = (headers == null) ? null :
headers.get("Content-Type");
+ if (ctype == null)
+ {
+ //Cxf stores it in lower case
+ ctype = (headers == null) ? null : headers.get("content-type");
+ }
+ log.info("ctype="+ctype);
+
+ if (ctype == null)
+ {
+ //Native has already processed this header into the message
+ SOAPMessage soapMessage = ((SOAPMessageContext)msgContext).getMessage();
+ MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
+ String[] ct = mimeHeaders.getHeader("Content-Type");
+ log.info("ct="+ct);
+ if (ct != null)
+ {
+ contentType = new ContentType(ct[0]);
+ }
+ }
+ else
+ {
+ contentType = new ContentType(ctype.get(0));
+ }
+ }
+ catch (ParseException e)
+ {
+ throw new WebServiceException(e);
+ }
+
+ return contentType;
+ }
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/Endpoint.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/Endpoint.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/Endpoint.java 2013-06-19
16:34:45 UTC (rev 17712)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, 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.jaxws.cxf.jbws3593;
+
+import java.util.List;
+
+import javax.activation.DataHandler;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.xml.bind.annotation.XmlMimeType;
+
+@WebService(name = "Endpoint", targetNamespace =
"http://org.jboss.ws/jaxws/jbws3593")
+@SOAPBinding(style = SOAPBinding.Style.RPC, parameterStyle =
SOAPBinding.ParameterStyle.BARE)
+public interface Endpoint
+{
+ @XmlMimeType("text/plain")
+ public DataHandler namespace(@XmlMimeType("text/plain") DataHandler data);
+
+ public List<String> echoStrings(List<String> l);
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/EndpointBean.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/EndpointBean.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/EndpointBean.java 2013-06-19
16:34:45 UTC (rev 17712)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, 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.jaxws.cxf.jbws3593;
+
+import static javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.List;
+
+import javax.activation.DataHandler;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.xml.bind.annotation.XmlMimeType;
+import javax.xml.ws.BindingType;
+import javax.xml.ws.WebServiceException;
+
+import org.apache.cxf.interceptor.OutInterceptors;
+import org.jboss.logging.Logger;
+
+@WebService(name="Endpoint",
targetNamespace="http://org.jboss.ws/jaxws/jbws3593")
+@SOAPBinding(style = SOAPBinding.Style.RPC, parameterStyle =
SOAPBinding.ParameterStyle.BARE)
+@BindingType(SOAP11HTTP_MTOM_BINDING)
+@OutInterceptors(interceptors =
{"org.jboss.test.ws.jaxws.cxf.jbws3593.MTOMOutInterceptor"})
+public class EndpointBean
+{
+ private static Logger log = Logger.getLogger(EndpointBean.class);
+
+ @XmlMimeType("text/plain")
+ public DataHandler namespace(@XmlMimeType("text/plain") DataHandler data)
+ {
+ try
+ {
+ String name = (String)getContent(data);
+ String type = (String)data.getContentType();
+ log.info("User " + name + " requested namespace with content type
["+ type +"]");
+
+ return new DataHandler("Hello " + name, "text/plain");
+ }
+ catch (IOException e)
+ {
+ throw new WebServiceException(e);
+ }
+ }
+
+ public List<String> echoStrings(List<String> l) {
+ if (l != null) {
+ for (String s : l) {
+ log.info("String: " + s);
+ }
+ }
+ return l;
+ }
+
+ protected Object getContent(DataHandler dh) throws IOException
+ {
+ Object content = dh.getContent();
+
+ if (content instanceof InputStream)
+ {
+ try
+ {
+ BufferedReader br = new BufferedReader(new
InputStreamReader((InputStream)content));
+ return br.readLine();
+ }
+ finally
+ {
+ ((InputStream)content).close();
+ }
+ }
+ return content;
+ }
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/JBWS3593TestCase.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/JBWS3593TestCase.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/JBWS3593TestCase.java 2013-06-19
16:34:45 UTC (rev 17712)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, 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.jaxws.cxf.jbws3593;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Service;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.soap.SOAPBinding;
+
+import junit.framework.Test;
+
+import org.jboss.wsf.test.JBossWSTest;
+import org.jboss.wsf.test.JBossWSTestSetup;
+
+/**
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 18-Jun-2013
+ */
+public class JBWS3593TestCase extends JBossWSTest
+{
+ public final String TARGET_ENDPOINT_ADDRESS = "http://" + getServerHost() +
":8080/jaxws-cxf-jbws3593/EndpointBean";
+
+ public static Test suite()
+ {
+ return new JBossWSTestSetup(JBWS3593TestCase.class,
"jaxws-cxf-jbws3593.war");
+ }
+
+ public void testMTOMAccess() throws Exception
+ {
+ URL wsdlURL = new URL(TARGET_ENDPOINT_ADDRESS + "?wsdl");
+ QName qname = new QName("http://org.jboss.ws/jaxws/jbws3593",
"EndpointBeanService");
+ Service service = Service.create(wsdlURL, qname);
+ Endpoint port = service.getPort(Endpoint.class);
+
+ addClientHandler((BindingProvider)port, true);
+
+ ((SOAPBinding)((BindingProvider)port).getBinding()).setMTOMEnabled(true);
+
+ DataHandler response = port.namespace(new
DataHandler("Jimbo","text/plain"));
+ Object messg = getContent(response);
+ assertEquals("Hello Jimbo", messg);
+ }
+
+ public void testTextXmlAccess() throws Exception
+ {
+ URL wsdlURL = new URL(TARGET_ENDPOINT_ADDRESS + "?wsdl");
+ QName qname = new QName("http://org.jboss.ws/jaxws/jbws3593",
"EndpointBeanService");
+ Service service = Service.create(wsdlURL, qname);
+ Endpoint port = service.getPort(Endpoint.class);
+
+ addClientHandler((BindingProvider)port, false);
+
+ List<String> list = new LinkedList<String>();
+ list.add("Hello");
+ list.add("Jimbo");
+ List<String> response = port.echoStrings(list);
+ assertEquals("Hello", response.get(0));
+ assertEquals("Jimbo", response.get(1));
+ }
+
+ @SuppressWarnings("rawtypes")
+ private void addClientHandler(BindingProvider provider, boolean checkMtom) {
+ List<Handler> handlerChain = new ArrayList<Handler>();
+ handlerChain.addAll(provider.getBinding().getHandlerChain());
+ handlerChain.add(new ClientHandler(checkMtom));
+ provider.getBinding().setHandlerChain(handlerChain);
+ }
+
+ protected Object getContent(DataHandler dh) throws IOException
+ {
+ Object content = dh.getContent();
+
+ if (content instanceof InputStream)
+ {
+ try
+ {
+ BufferedReader br = new BufferedReader(new
InputStreamReader((InputStream)content));
+ return br.readLine();
+ }
+ finally
+ {
+ ((InputStream)content).close();
+ }
+ }
+ return content;
+ }
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/MTOMOutInterceptor.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/MTOMOutInterceptor.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jbws3593/MTOMOutInterceptor.java 2013-06-19
16:34:45 UTC (rev 17712)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, 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.jaxws.cxf.jbws3593;
+
+import org.apache.cxf.interceptor.AttachmentOutInterceptor;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.model.MessageInfo;
+
+/**
+ * A CXF interceptor for selectively turn off MTOM
+ */
+public class MTOMOutInterceptor extends AbstractPhaseInterceptor<Message>
+{
+
+ public MTOMOutInterceptor()
+ {
+ super(Phase.PRE_STREAM);
+ addBefore(AttachmentOutInterceptor.class.getName());
+ }
+
+ public void handleMessage(Message message)
+ {
+ MessageInfo mi = (MessageInfo)message.get(MessageInfo.class.getName());
+ if ("echoStringsResponse".equals(mi.getName().getLocalPart())) {
+ message.put("mtom-enabled", false);
+ }
+ }
+}