Java tutorial
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2015, Red Hat, Inc., 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.integration.mtom; import java.awt.Image; import java.io.FileInputStream; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.BindingProvider; import javax.xml.ws.Service; import javax.xml.ws.soap.SOAPBinding; import org.apache.commons.io.IOUtils; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.WebArchive; import static org.junit.Assert.assertFalse; import static org.junit.Assert.fail; import org.junit.Test; import org.junit.runner.RunWith; /** * @author <a href="mailto:psotirop@redhat.com">Panos</a> */ @RunWith(Arquillian.class) @RunAsClient public class MtomTestCase { private final String serverLogPath = "/../surefire-reports/org.jboss.test.integration.mtom.MtomTestCase-output.txt"; @Deployment public static WebArchive deployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, "war-mtom.war"); war.addClasses(ImageServer.class, ImageServerImpl.class); war.setWebXML("META-INF/web.xml"); return war; } @Test public void mtomTest() throws Exception { URL url = new URL("http://localhost:8080/war-mtom?wsdl"); QName qname = new QName("http://mtom.integration.test.jboss.org/", "ImageServerImplService"); String path = this.getClass().getClassLoader().getResource("").getPath(); FileInputStream inputStream = new FileInputStream(path + serverLogPath); try { String everything = IOUtils.toString(inputStream); assertFalse("Testing archive has enabled mtom feature", everything.contains("mtomEnabled=true")); } finally { inputStream.close(); } Service service = Service.create(url, qname); ImageServer imageServer = service.getPort(ImageServer.class); //enable MTOM in client BindingProvider bp = (BindingProvider) imageServer; SOAPBinding binding = (SOAPBinding) bp.getBinding(); binding.setMTOMEnabled(true); Image im = imageServer.downloadImage(path + "rss.png"); if (im == null) { fail(); } } }