Search in sources :

Example 31 with SOAPBinding

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

the class AttachmentTest method testAttachmentViaWsInterface.

// END SNIPPET: setup
/**
 * Create a webservice client using wsdl url
 *
 * @throws Exception
 */
// START SNIPPET: webservice
public void testAttachmentViaWsInterface() throws Exception {
    Service service = Service.create(new URL("http://localhost:" + port + "/webservice-attachments/AttachmentImpl?wsdl"), new QName("http://superbiz.org/wsdl", "AttachmentWsService"));
    assertNotNull(service);
    AttachmentWs ws = service.getPort(AttachmentWs.class);
    // retrieve the SOAPBinding
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) ws).getBinding();
    binding.setMTOMEnabled(true);
    String request = "tsztelak@gmail.com";
    // Byte array
    String response = ws.stringFromBytes(request.getBytes());
    assertEquals(request, response);
    // Data Source
    DataSource source = new ByteArrayDataSource(request.getBytes(), "text/plain; charset=UTF-8");
    // not yet supported !
    // response = ws.stringFromDataSource(source);
    // assertEquals(request, response);
    // Data Handler
    response = ws.stringFromDataHandler(new DataHandler(source));
    assertEquals(request, response);
}
Also used : QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) SOAPBinding(javax.xml.ws.soap.SOAPBinding) DataHandler(javax.activation.DataHandler) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) URL(java.net.URL) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) DataSource(javax.activation.DataSource)

Example 32 with SOAPBinding

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

the class JaxWsClientProxy method mapException.

Exception mapException(Method method, BindingOperationInfo boi, Exception ex) {
    if (method != null) {
        for (Class<?> excls : method.getExceptionTypes()) {
            if (excls.isInstance(ex)) {
                return ex;
            }
        }
    } else if (boi != null) {
        for (BindingFaultInfo fi : boi.getFaults()) {
            Class<?> c = fi.getFaultInfo().getProperty(Class.class.getName(), Class.class);
            if (c != null && c.isInstance(ex)) {
                return ex;
            }
        }
        if (ex instanceof IOException) {
            return ex;
        }
    }
    if (ex instanceof Fault && ex.getCause() instanceof IOException) {
        return new WebServiceException(ex.getMessage(), ex.getCause());
    }
    if (getBinding() instanceof HTTPBinding) {
        HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
        exception.initCause(ex);
        return exception;
    } else if (getBinding() instanceof SOAPBinding) {
        try {
            SOAPFault soapFault = createSoapFault((SOAPBinding) getBinding(), ex);
            if (soapFault == null) {
                throw new WebServiceException(ex);
            }
            SOAPFaultException exception = new SOAPFaultException(soapFault);
            if (ex instanceof Fault && ex.getCause() != null) {
                exception.initCause(ex.getCause());
            } else {
                exception.initCause(ex);
            }
            return exception;
        } catch (SOAPException e) {
            return new WebServiceException(ex);
        }
    }
    return new WebServiceException(ex);
}
Also used : HTTPException(javax.xml.ws.http.HTTPException) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPBinding(javax.xml.ws.soap.SOAPBinding) Fault(org.apache.cxf.interceptor.Fault) SOAPFault(javax.xml.soap.SOAPFault) SoapFault(org.apache.cxf.binding.soap.SoapFault) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) IOException(java.io.IOException) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) HTTPBinding(javax.xml.ws.http.HTTPBinding)

Example 33 with SOAPBinding

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

the class DispatchImpl method mapException.

private RuntimeException mapException(Exception ex) {
    if (ex instanceof Fault && ex.getCause() instanceof IOException) {
        throw new WebServiceException(ex.getMessage(), ex.getCause());
    }
    if (getBinding() instanceof HTTPBinding) {
        HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
        exception.initCause(ex);
        return exception;
    } else if (getBinding() instanceof SOAPBinding) {
        SOAPFault soapFault = null;
        try {
            soapFault = JaxWsClientProxy.createSoapFault((SOAPBinding) getBinding(), ex);
        } catch (SOAPException e) {
        // ignore
        }
        if (soapFault == null) {
            return new WebServiceException(ex);
        }
        SOAPFaultException exception = new SOAPFaultException(soapFault);
        exception.initCause(ex);
        return exception;
    }
    return new WebServiceException(ex);
}
Also used : HTTPException(javax.xml.ws.http.HTTPException) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPBinding(javax.xml.ws.soap.SOAPBinding) SOAPFault(javax.xml.soap.SOAPFault) Fault(org.apache.cxf.interceptor.Fault) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) IOException(java.io.IOException) HTTPBinding(javax.xml.ws.http.HTTPBinding)

Example 34 with SOAPBinding

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

the class ClientMtomXopWithJMSTest method startServers.

@BeforeClass
public static void startServers() throws Exception {
    Object implementor = new TestMtomJMSImpl();
    bus = BusFactory.getDefaultBus();
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
    PooledConnectionFactory cfp = new PooledConnectionFactory(cf);
    cff = new ConnectionFactoryFeature(cfp);
    EndpointImpl ep = (EndpointImpl) Endpoint.create(implementor);
    ep.getFeatures().add(cff);
    ep.getInInterceptors().add(new TestMultipartMessageInterceptor());
    ep.getOutInterceptors().add(new TestAttachmentOutInterceptor());
    // ep.getInInterceptors().add(new LoggingInInterceptor());
    // ep.getOutInterceptors().add(new LoggingOutInterceptor());
    SOAPBinding jaxWsSoapBinding = (SOAPBinding) ep.getBinding();
    jaxWsSoapBinding.setMTOMEnabled(true);
    ep.publish();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ConnectionFactoryFeature(org.apache.cxf.transport.jms.ConnectionFactoryFeature) EndpointImpl(org.apache.cxf.jaxws.EndpointImpl) PooledConnectionFactory(org.apache.activemq.pool.PooledConnectionFactory) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BeforeClass(org.junit.BeforeClass)

Example 35 with SOAPBinding

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

the class MTOMBindingTypeTest method testDetail.

@Test
public void testDetail() throws Exception {
    ByteArrayOutputStream input = setupInLogging();
    ByteArrayOutputStream output = setupOutLogging();
    Holder<byte[]> photo = new Holder<>("CXF".getBytes());
    Holder<Image> image = new Holder<>(getImage("/java.jpg"));
    Hello port = getPort();
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) port).getBinding();
    binding.setMTOMEnabled(true);
    port.detail(photo, image);
    String expected = "<xop:Include ";
    assertTrue(output.toString().indexOf(expected) != -1);
    assertTrue(input.toString().indexOf(expected) != -1);
    assertEquals("CXF", new String(photo.value));
    assertNotNull(image.value);
}
Also used : Hello(org.apache.cxf.systest.mtom_feature.Hello) Holder(javax.xml.ws.Holder) SOAPBinding(javax.xml.ws.soap.SOAPBinding) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Image(java.awt.Image) 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