Author: alessio.soldano(a)jboss.com
Date: 2009-01-15 04:58:06 -0500 (Thu, 15 Jan 2009)
New Revision: 9040
Added:
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMCheckClientHandler.java
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMFeatureTestCase.java
Modified:
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMEndpoint.java
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMEndpointBean.java
Log:
[JBWS-2448] @MTOM & MTOMFeature tests
Added:
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMCheckClientHandler.java
===================================================================
---
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMCheckClientHandler.java
(rev 0)
+++
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMCheckClientHandler.java 2009-01-15
09:58:06 UTC (rev 9040)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.samples.xop.doclit;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+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.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+/**
+ * A SOAPHandler that checks for Include elements in the
+ * outbound SOAPMessage in order to see if MTOM is enabled.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 15-Jan-2009
+ */
+public class MTOMCheckClientHandler implements SOAPHandler<SOAPMessageContext>
+{
+
+ public boolean handleMessage(SOAPMessageContext smc)
+ {
+ try
+ {
+ return check(smc);
+ }
+ catch (Exception e)
+ {
+ throw new WebServiceException(e);
+ }
+ }
+
+ public boolean handleFault(SOAPMessageContext smc)
+ {
+ //NOOP
+ return true;
+ }
+
+ private static boolean check(SOAPMessageContext smc) throws SOAPException,
IOException
+ {
+ Boolean outboundProperty =
(Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+
+ if (outboundProperty.booleanValue())
+ {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ SOAPMessage message = smc.getMessage();
+ message.writeTo(outputStream);
+ String messageString = outputStream.toString();
+ if (!messageString.contains("Include"))
+ throw new IllegalStateException("XOP request inlined");
+ }
+ return true;
+ }
+
+ public void close(MessageContext messageContext)
+ {
+ //NOOP
+ }
+
+ public Set<QName> getHeaders()
+ {
+ return new HashSet<QName>(); //empty set
+ }
+
+}
Property changes on:
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMCheckClientHandler.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMEndpoint.java
===================================================================
---
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMEndpoint.java 2009-01-15
09:50:02 UTC (rev 9039)
+++
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMEndpoint.java 2009-01-15
09:58:06 UTC (rev 9040)
@@ -23,11 +23,9 @@
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
-import javax.xml.ws.BindingType;
@WebService(targetNamespace = "http://org.jboss.ws/xop/doclit")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, parameterStyle =
SOAPBinding.ParameterStyle.BARE)
-@BindingType(value = "http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true")
public interface MTOMEndpoint
{
public DHResponse echoDataHandler(DHRequest request);
Modified:
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMEndpointBean.java
===================================================================
---
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMEndpointBean.java 2009-01-15
09:50:02 UTC (rev 9039)
+++
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMEndpointBean.java 2009-01-15
09:58:06 UTC (rev 9040)
@@ -28,13 +28,13 @@
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.ws.WebServiceException;
-import javax.xml.ws.BindingType;
+import javax.xml.ws.soap.MTOM;
import org.jboss.logging.Logger;
@WebService(name = "MTOMEndpoint", serviceName = "MTOMService",
endpointInterface = "org.jboss.test.ws.jaxws.samples.xop.doclit.MTOMEndpoint")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
-@BindingType(value = "http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true")
+@MTOM
public class MTOMEndpointBean implements MTOMEndpoint
{
private Logger log = Logger.getLogger(MTOMEndpointBean.class);
Added:
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMFeatureTestCase.java
===================================================================
---
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMFeatureTestCase.java
(rev 0)
+++
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMFeatureTestCase.java 2009-01-15
09:58:06 UTC (rev 9040)
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.samples.xop.doclit;
+
+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.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.MTOMFeature;
+import javax.xml.ws.soap.SOAPBinding;
+
+import junit.framework.Test;
+
+import org.jboss.wsf.test.JBossWSTest;
+import org.jboss.wsf.test.JBossWSTestSetup;
+
+/**
+ * [JBWS-2448] This test verify the MTOMFeature correctly enable MTOM on client side.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 14-Jan-2009
+ */
+public class MTOMFeatureTestCase extends JBossWSTest
+{
+
+ public final String TARGET_ENDPOINT_ADDRESS = "http://" + getServerHost() +
":8080/jaxws-samples-xop-doclit/bare";
+
+ protected MTOMEndpoint port;
+
+ public static Test suite()
+ {
+ return new JBossWSTestSetup(MTOMFeatureTestCase.class,
"jaxws-samples-xop-doclit.war");
+ }
+
+ @SuppressWarnings("unchecked")
+ private MTOMEndpoint getPort(boolean mtomEnabled) throws Exception
+ {
+ QName serviceName = new
QName("http://doclit.xop.samples.jaxws.ws.test.jboss.org/",
"MTOMService");
+ URL wsdlURL = new URL(TARGET_ENDPOINT_ADDRESS + "?wsdl");
+
+ Service service = Service.create(wsdlURL, serviceName);
+ MTOMEndpoint port = service.getPort(MTOMEndpoint.class, new
MTOMFeature(mtomEnabled));
+ SOAPBinding binding = (SOAPBinding)((BindingProvider)port).getBinding();
+
+ if (mtomEnabled)
+ {
+ List<Handler> handlerChain = new ArrayList<Handler>();
+ handlerChain.addAll(binding.getHandlerChain());
+ handlerChain.add(new MTOMCheckClientHandler());
+ binding.setHandlerChain(handlerChain);
+ }
+ return port;
+ }
+
+ public void testWithMTOMRequest() throws Exception
+ {
+ DataHandler dh = new DataHandler("DataHandlerRoundtrip",
"text/plain");
+ DHResponse response = getPort(true).echoDataHandler(new DHRequest(dh));
+ assertNotNull(response);
+
+ Object content = getContent(response.getDataHandler());
+ String contentType = response.getDataHandler().getContentType();
+
+ assertEquals("Server data", content);
+ assertEquals("text/plain", contentType);
+ }
+
+ public void testWithoutMTOMRequest() throws Exception
+ {
+ DataHandler dh = new DataHandler("DataHandlerResponseOptimzed",
"text/plain");
+ DHResponse response = getPort(false).echoDataHandler(new DHRequest(dh));
+ assertNotNull(response);
+
+ Object content = getContent(response.getDataHandler());
+ String contentType = response.getDataHandler().getContentType();
+
+ assertEquals("Server data", content);
+ assertEquals("text/plain", contentType);
+ }
+
+ protected Object getContent(DataHandler dh) throws IOException
+ {
+ Object content = dh.getContent();
+
+ // Metro returns an ByteArrayInputStream
+ if (content instanceof InputStream)
+ {
+ try
+ {
+ BufferedReader br = new BufferedReader(new
InputStreamReader((InputStream)content));
+ return br.readLine();
+ }
+ finally
+ {
+ ((InputStream)content).close();
+ }
+ }
+ return content;
+ }
+}
Property changes on:
framework/branches/jaxws21/testsuite/test/java/org/jboss/test/ws/jaxws/samples/xop/doclit/MTOMFeatureTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF