Search in sources :

Example 16 with SOAPBinding

use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.

the class Client method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.out.println("Please specify the WSDL file.");
        System.exit(1);
    }
    URL wsdlURL;
    File wsdlFile = new File(args[0]);
    if (wsdlFile.exists()) {
        wsdlURL = wsdlFile.toURI().toURL();
    } else {
        wsdlURL = new URL(args[0]);
    }
    System.out.println(wsdlURL);
    TestMtomService tms = new TestMtomService(wsdlURL, SERVICE_NAME);
    TestMtomPortType port = (TestMtomPortType) tms.getPort(PORT_NAME, TestMtomPortType.class);
    Binding binding = ((BindingProvider) port).getBinding();
    ((SOAPBinding) binding).setMTOMEnabled(true);
    URL fileURL = Client.class.getResource("/me.bmp");
    File aFile = new File(new URI(fileURL.toString()));
    long fileSize = aFile.length();
    System.out.println("Filesize of me.bmp image is: " + fileSize);
    System.out.println("\nStarting MTOM Test using basic byte array:");
    Holder<String> name = new Holder<>("Sam");
    Holder<byte[]> param = new Holder<>();
    param.value = new byte[(int) fileSize];
    InputStream in = fileURL.openStream();
    int len = in.read(param.value);
    while (len < fileSize) {
        len += in.read(param.value, len, (int) (fileSize - len));
    }
    System.out.println("--Sending the me.bmp image to server");
    System.out.println("--Sending a name value of " + name.value);
    port.testByteArray(name, param);
    System.out.println("--Received byte[] back from server, returned size is " + param.value.length);
    System.out.println("--Returned string value is " + name.value);
    Image image = ImageIO.read(new ByteArrayInputStream(param.value));
    System.out.println("--Loaded image from byte[] successfully, hashCode=" + image.hashCode());
    System.out.println("Successfully ran MTOM/byte array demo");
    System.out.println("\nStarting MTOM test with DataHandler:");
    name.value = "Bob";
    Holder<DataHandler> handler = new Holder<>();
    handler.value = new DataHandler(fileURL);
    System.out.println("--Sending the me.bmp image to server");
    System.out.println("--Sending a name value of " + name.value);
    port.testDataHandler(name, handler);
    InputStream mtomIn = handler.value.getInputStream();
    fileSize = 0;
    for (int i = mtomIn.read(); i != -1; i = mtomIn.read()) {
        fileSize++;
    }
    System.out.println("--Received DataHandler back from server, " + "returned size is " + fileSize);
    System.out.println("--Returned string value is " + name.value);
    System.out.println("Successfully ran MTOM/DataHandler demo");
    System.exit(0);
}
Also used : Binding(javax.xml.ws.Binding) SOAPBinding(javax.xml.ws.soap.SOAPBinding) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Holder(javax.xml.ws.Holder) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) DataHandler(javax.activation.DataHandler) TestMtomPortType(org.apache.cxf.mime.TestMtomPortType) Image(java.awt.Image) TestMtomService(org.apache.cxf.mime.TestMtomService) URI(java.net.URI) URL(java.net.URL) ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File)

Example 17 with SOAPBinding

use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.

the class ServiceImpl method initializePorts.

private void initializePorts() {
    try {
        Definition def = bus.getExtension(WSDLManager.class).getDefinition(wsdlURL);
        javax.wsdl.Service serv = def.getService(serviceName);
        if (serv == null) {
            throw new WebServiceException("Could not find service named " + serviceName + " in wsdl " + wsdlURL);
        }
        Map<String, Port> wsdlports = CastUtils.cast(serv.getPorts());
        for (Port port : wsdlports.values()) {
            QName name = new QName(serviceName.getNamespaceURI(), port.getName());
            String address = null;
            String bindingID = null;
            List<? extends ExtensibilityElement> extensions = CastUtils.cast(port.getBinding().getExtensibilityElements());
            if (!extensions.isEmpty()) {
                ExtensibilityElement e = extensions.get(0);
                if (e instanceof SoapBinding) {
                    bindingID = SOAPBinding.SOAP11HTTP_BINDING;
                } else if (e instanceof SOAP12Binding) {
                    bindingID = SOAPBinding.SOAP12HTTP_BINDING;
                } else if (e instanceof javax.wsdl.extensions.soap.SOAPBinding) {
                    bindingID = SOAPBinding.SOAP11HTTP_BINDING;
                }
            }
            extensions = CastUtils.cast(port.getExtensibilityElements());
            if (!extensions.isEmpty()) {
                ExtensibilityElement e = extensions.get(0);
                if (e instanceof SoapAddress) {
                    address = ((SoapAddress) e).getLocationURI();
                } else if (e instanceof AddressType) {
                    address = ((AddressType) e).getLocation();
                } else if (e instanceof SOAP12Address) {
                    address = ((SOAP12Address) e).getLocationURI();
                } else if (e instanceof SOAPAddress) {
                    address = ((SOAPAddress) e).getLocationURI();
                } else if (e instanceof HTTPAddress) {
                    address = ((HTTPAddress) e).getLocationURI();
                }
            }
            addPort(name, bindingID, address);
        }
    } catch (WebServiceException e) {
        throw e;
    } catch (Throwable e) {
        if (e instanceof UncheckedException && LOG.isLoggable(Level.FINE)) {
            LOG.log(Level.FINE, e.getLocalizedMessage(), e);
        }
        WSDLServiceFactory sf = new WSDLServiceFactory(bus, wsdlURL, serviceName);
        Service service = sf.create();
        for (ServiceInfo si : service.getServiceInfos()) {
            for (EndpointInfo ei : si.getEndpoints()) {
                String bindingID = BindingID.getJaxwsBindingID(ei.getTransportId());
                addPort(ei.getName(), bindingID, ei.getAddress());
            }
        }
    }
}
Also used : HTTPAddress(javax.wsdl.extensions.http.HTTPAddress) Port(javax.wsdl.Port) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) SOAP12Address(javax.wsdl.extensions.soap12.SOAP12Address) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) SOAPBinding(javax.xml.ws.soap.SOAPBinding) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) UncheckedException(org.apache.cxf.common.i18n.UncheckedException) SoapAddress(org.apache.cxf.binding.soap.wsdl.extensions.SoapAddress) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) WSDLManager(org.apache.cxf.wsdl.WSDLManager) AddressType(org.apache.cxf.wsdl.http.AddressType)

Example 18 with SOAPBinding

use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.

the class DispatchTest method testSOAPPBinding.

@Test
public void testSOAPPBinding() throws Exception {
    ServiceImpl service = new ServiceImpl(getBus(), null, SERVICE_NAME, null);
    service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, "local://foobar");
    Dispatch<Source> disp = service.createDispatch(PORT_NAME, Source.class, Service.Mode.MESSAGE);
    assertTrue(disp.getBinding() instanceof SOAPBinding);
}
Also used : ServiceImpl(org.apache.cxf.jaxws.ServiceImpl) SOAPBinding(javax.xml.ws.soap.SOAPBinding) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

Example 19 with SOAPBinding

use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.

the class SOAPBindingTest method testSAAJ.

@Test
public void testSAAJ() throws Exception {
    URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
    assertNotNull(wsdl1);
    ServiceImpl service = new ServiceImpl(getBus(), wsdl1, SERVICE_1, ServiceImpl.class);
    CalculatorPortType cal = service.getPort(PORT_1, CalculatorPortType.class);
    BindingProvider bindingProvider = (BindingProvider) cal;
    assertTrue(bindingProvider.getBinding() instanceof SOAPBinding);
    SOAPBinding binding = (SOAPBinding) bindingProvider.getBinding();
    assertNotNull(binding.getMessageFactory());
    assertNotNull(binding.getSOAPFactory());
}
Also used : CalculatorPortType(org.apache.cxf.calculator.CalculatorPortType) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Test(org.junit.Test)

Example 20 with SOAPBinding

use of javax.xml.ws.soap.SOAPBinding in project cxf by apache.

the class SOAPBindingTest method testRoles.

@Test
public void testRoles() throws Exception {
    URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
    assertNotNull(wsdl1);
    ServiceImpl service = new ServiceImpl(getBus(), wsdl1, SERVICE_1, ServiceImpl.class);
    CalculatorPortType cal = service.getPort(PORT_1, CalculatorPortType.class);
    BindingProvider bindingProvider = (BindingProvider) cal;
    assertTrue(bindingProvider.getBinding() instanceof SOAPBinding);
    SOAPBinding binding = (SOAPBinding) bindingProvider.getBinding();
    assertNotNull(binding.getRoles());
    assertEquals(2, binding.getRoles().size());
    assertTrue(binding.getRoles().contains(Soap12.getInstance().getNextRole()));
    assertTrue(binding.getRoles().contains(Soap12.getInstance().getUltimateReceiverRole()));
    String myrole = "http://myrole";
    Set<String> roles = new HashSet<>();
    roles.add(myrole);
    binding.setRoles(roles);
    assertNotNull(binding.getRoles());
    assertEquals(3, binding.getRoles().size());
    assertTrue(binding.getRoles().contains(myrole));
    assertTrue(binding.getRoles().contains(Soap12.getInstance().getNextRole()));
    assertTrue(binding.getRoles().contains(Soap12.getInstance().getUltimateReceiverRole()));
    roles.add(Soap12.getInstance().getNoneRole());
    try {
        binding.setRoles(roles);
        fail("did not throw exception");
    } catch (WebServiceException e) {
    // that's expected with none role
    }
}
Also used : CalculatorPortType(org.apache.cxf.calculator.CalculatorPortType) WebServiceException(javax.xml.ws.WebServiceException) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SOAPBinding (javax.xml.ws.soap.SOAPBinding)51 Test (org.junit.Test)20 URL (java.net.URL)19 BindingProvider (javax.xml.ws.BindingProvider)19 QName (javax.xml.namespace.QName)18 Service (javax.xml.ws.Service)14 DataHandler (javax.activation.DataHandler)13 WebServiceException (javax.xml.ws.WebServiceException)7 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)7 JBossWSTest (org.jboss.wsf.test.JBossWSTest)7 ArrayList (java.util.ArrayList)6 Holder (javax.xml.ws.Holder)6 Image (java.awt.Image)5 IOException (java.io.IOException)5 Binding (javax.xml.ws.Binding)5 File (java.io.File)4 Before (org.junit.Before)4 FileDataSource (javax.activation.FileDataSource)3 Handler (javax.xml.ws.handler.Handler)3 MTOMFeature (javax.xml.ws.soap.MTOMFeature)3