Search in sources :

Example 16 with SAAJInInterceptor

use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor in project tomee by apache.

the class CalculatorTest method testCalculatorViaWsInterfaceWithTimestamp2ways.

public void testCalculatorViaWsInterfaceWithTimestamp2ways() throws Exception {
    final Service calcService = Service.create(new URL("http://localhost:" + port + "/webservice-ws-security/CalculatorImplTimestamp2ways?wsdl"), new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
    assertNotNull(calcService);
    // for debugging (ie. TCPMon)
    calcService.addPort(new QName("http://superbiz.org/wsdl", "CalculatorWsService2"), SOAPBinding.SOAP12HTTP_BINDING, "http://127.0.0.1:8204/CalculatorImplTimestamp2ways");
    // CalculatorWs calc = calcService.getPort(
    // new QName("http://superbiz.org/wsdl", "CalculatorWsService2"),
    // CalculatorWs.class);
    final CalculatorWs calc = calcService.getPort(CalculatorWs.class);
    final Client client = ClientProxy.getClient(calc);
    final Endpoint endpoint = client.getEndpoint();
    endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
    endpoint.getInInterceptors().add(new SAAJInInterceptor());
    final Map<String, Object> outProps = new HashMap<String, Object>();
    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
    final WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    endpoint.getOutInterceptors().add(wssOut);
    final Map<String, Object> inProps = new HashMap<String, Object>();
    inProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
    final WSS4JInInterceptor wssIn = new WSS4JInInterceptor(inProps);
    endpoint.getInInterceptors().add(wssIn);
    assertEquals(12, calc.multiply(3, 4));
}
Also used : SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) Endpoint(org.apache.cxf.endpoint.Endpoint) WSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client)

Example 17 with SAAJInInterceptor

use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor in project cxf by apache.

the class SpringBeansTest method testClients.

@Test
public void testClients() throws Exception {
    AbstractFactoryBeanDefinitionParser.setFactoriesAreAbstract(false);
    ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/frontend/spring/clients.xml" });
    Object bean = ctx.getBean("client1.proxyFactory");
    assertNotNull(bean);
    ClientProxyFactoryBean cpfbean = (ClientProxyFactoryBean) bean;
    BindingConfiguration bc = cpfbean.getBindingConfig();
    assertTrue(bc instanceof SoapBindingConfiguration);
    SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
    assertTrue(sbc.getVersion() instanceof Soap12);
    HelloService greeter = (HelloService) ctx.getBean("client1");
    assertNotNull(greeter);
    Client client = ClientProxy.getClient(greeter);
    assertNotNull("expected ConduitSelector", client.getConduitSelector());
    assertTrue("unexpected ConduitSelector", client.getConduitSelector() instanceof NullConduitSelector);
    List<Interceptor<? extends Message>> inInterceptors = client.getInInterceptors();
    boolean saaj = false;
    boolean logging = false;
    for (Interceptor<? extends Message> i : inInterceptors) {
        if (i instanceof SAAJInInterceptor) {
            saaj = true;
        } else if (i instanceof LoggingInInterceptor) {
            logging = true;
        }
    }
    assertTrue(saaj);
    assertTrue(logging);
    saaj = false;
    logging = false;
    for (Interceptor<?> i : client.getOutInterceptors()) {
        if (i instanceof SAAJOutInterceptor) {
            saaj = true;
        } else if (i instanceof LoggingOutInterceptor) {
            logging = true;
        }
    }
    assertTrue(saaj);
    assertTrue(logging);
    ClientProxyFactoryBean clientProxyFactoryBean = (ClientProxyFactoryBean) ctx.getBean("client2.proxyFactory");
    assertNotNull(clientProxyFactoryBean);
    assertEquals("get the wrong transportId", clientProxyFactoryBean.getTransportId(), "http://cxf.apache.org/transports/local");
    assertEquals("get the wrong bindingId", clientProxyFactoryBean.getBindingId(), "http://cxf.apache.org/bindings/xformat");
    greeter = (HelloService) ctx.getBean("client2");
    assertNotNull(greeter);
    greeter = (HelloService) ctx.getBean("client3");
    assertNotNull(greeter);
    client = ClientProxy.getClient(greeter);
    EndpointInfo epi = client.getEndpoint().getEndpointInfo();
    AuthorizationPolicy ap = epi.getExtensor(AuthorizationPolicy.class);
    assertNotNull("The AuthorizationPolicy instance should not be null", ap);
    assertEquals("Get the wrong username", ap.getUserName(), "testUser");
    assertEquals("Get the wrong password", ap.getPassword(), "password");
}
Also used : Soap12(org.apache.cxf.binding.soap.Soap12) SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) Message(org.apache.cxf.message.Message) HelloService(org.apache.cxf.service.factory.HelloService) NullConduitSelector(org.apache.cxf.endpoint.NullConduitSelector) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) ClientProxyFactoryBean(org.apache.cxf.frontend.ClientProxyFactoryBean) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) BindingConfiguration(org.apache.cxf.binding.BindingConfiguration) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) Test(org.junit.Test)

Example 18 with SAAJInInterceptor

use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor in project cxf by apache.

the class WSS4JInOutTest method testOrder.

@Test
public void testOrder() throws Exception {
    // make sure the interceptors get ordered correctly
    SortedSet<Phase> phases = new TreeSet<>();
    phases.add(new Phase(Phase.PRE_PROTOCOL, 1));
    List<Interceptor<? extends Message>> lst = new ArrayList<>();
    lst.add(new MustUnderstandInterceptor());
    lst.add(new WSS4JInInterceptor());
    lst.add(new SAAJInInterceptor());
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
    chain.add(lst);
    String output = chain.toString();
    assertTrue(output.contains("MustUnderstandInterceptor, SAAJInInterceptor, WSS4JInInterceptor"));
}
Also used : SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Phase(org.apache.cxf.phase.Phase) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SOAPMessage(javax.xml.soap.SOAPMessage) TreeSet(java.util.TreeSet) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) ArrayList(java.util.ArrayList) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) Test(org.junit.Test)

Example 19 with SAAJInInterceptor

use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor in project cxf by apache.

the class ClientMtomXopTest method testMtomXopProvider.

@Test
public void testMtomXopProvider() throws Exception {
    TestMtom mtomPort = createPort(MTOM_SERVICE, MTOM_PORT_PROVIDER, TestMtom.class, true, true);
    try {
        Holder<DataHandler> param = new Holder<>();
        Holder<String> name;
        byte[] bytes;
        InputStream in;
        InputStream pre = this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl");
        int fileSize = 0;
        for (int i = pre.read(); i != -1; i = pre.read()) {
            fileSize++;
        }
        int count = 50;
        byte[] data = new byte[fileSize * count];
        for (int x = 0; x < count; x++) {
            this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data, fileSize * x, fileSize);
        }
        Object[] validationTypes = new Object[] { Boolean.TRUE, SchemaValidationType.IN, SchemaValidationType.BOTH };
        for (Object validationType : validationTypes) {
            ((BindingProvider) mtomPort).getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, validationType);
            param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
            name = new Holder<>("call detail");
            mtomPort.testXop(name, param);
            assertEquals("name unchanged", "return detail + call detail", name.value);
            assertNotNull(param.value);
            in = param.value.getInputStream();
            bytes = IOUtils.readBytesFromStream(in);
            assertEquals(data.length, bytes.length);
            in.close();
            param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
            name = new Holder<>("call detail");
            mtomPort.testXop(name, param);
            assertEquals("name unchanged", "return detail + call detail", name.value);
            assertNotNull(param.value);
            in = param.value.getInputStream();
            bytes = IOUtils.readBytesFromStream(in);
            assertEquals(data.length, bytes.length);
            in.close();
        }
        validationTypes = new Object[] { Boolean.FALSE, SchemaValidationType.OUT, SchemaValidationType.NONE };
        for (Object validationType : validationTypes) {
            ((BindingProvider) mtomPort).getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, validationType);
            SAAJOutInterceptor saajOut = new SAAJOutInterceptor();
            SAAJInInterceptor saajIn = new SAAJInInterceptor();
            param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
            name = new Holder<>("call detail");
            mtomPort.testXop(name, param);
            assertEquals("name unchanged", "return detail + call detail", name.value);
            assertNotNull(param.value);
            in = param.value.getInputStream();
            bytes = IOUtils.readBytesFromStream(in);
            assertEquals(data.length, bytes.length);
            in.close();
            ClientProxy.getClient(mtomPort).getInInterceptors().add(saajIn);
            ClientProxy.getClient(mtomPort).getInInterceptors().add(saajOut);
            param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
            name = new Holder<>("call detail");
            mtomPort.testXop(name, param);
            assertEquals("name unchanged", "return detail + call detail", name.value);
            assertNotNull(param.value);
            in = param.value.getInputStream();
            bytes = IOUtils.readBytesFromStream(in);
            assertEquals(data.length, bytes.length);
            in.close();
            ClientProxy.getClient(mtomPort).getInInterceptors().remove(saajIn);
            ClientProxy.getClient(mtomPort).getInInterceptors().remove(saajOut);
        }
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    } catch (Exception ex) {
        System.out.println(System.getProperties());
        throw ex;
    }
}
Also used : SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) InputStream(java.io.InputStream) Holder(javax.xml.ws.Holder) TestMtom(org.apache.cxf.mime.TestMtom) DataHandler(javax.activation.DataHandler) Endpoint(org.apache.cxf.endpoint.Endpoint) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) Test(org.junit.Test)

Example 20 with SAAJInInterceptor

use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor in project jbossws-cxf by jbossws.

the class JaspiClientOutInterceptor method handleMessage.

@Override
public void handleMessage(SoapMessage message) throws Fault {
    if (message.getContent(SOAPMessage.class) == null) {
        SAAJInInterceptor saajIn = new SAAJInInterceptor();
        saajIn.handleMessage(message);
    }
    SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
    if (soapMessage == null) {
        return;
    }
    SOAPMessage copyMessage = null;
    try {
        MessageFactory messageFactory = SAAJPreInInterceptor.INSTANCE.getFactory(message);
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        soapMessage.writeTo(bout);
        copyMessage = messageFactory.createMessage(soapMessage.getMimeHeaders(), new ByteArrayInputStream(bout.toByteArray()));
    } catch (SOAPException e) {
        throw new Fault(e);
    } catch (IOException e) {
        throw new Fault(e);
    }
    if (copyMessage != null) {
        message.put(SOAPMessage.class, copyMessage);
    }
    try {
        authManager.secureRequest(message);
    } finally {
        message.put(SOAPMessage.class, soapMessage);
    }
}
Also used : SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPException(javax.xml.soap.SOAPException) Fault(org.apache.cxf.interceptor.Fault) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SOAPMessage(javax.xml.soap.SOAPMessage)

Aggregations

SAAJInInterceptor (org.apache.cxf.binding.soap.saaj.SAAJInInterceptor)21 SAAJOutInterceptor (org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor)10 Test (org.junit.Test)8 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)7 XMLStreamReader (javax.xml.stream.XMLStreamReader)5 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)5 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)5 Interceptor (org.apache.cxf.interceptor.Interceptor)5 Message (org.apache.cxf.message.Message)5 Endpoint (org.apache.cxf.endpoint.Endpoint)4 StringReader (java.io.StringReader)3 SOAPException (javax.xml.soap.SOAPException)3 SOAPMessage (javax.xml.soap.SOAPMessage)3 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)3 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2