Search in sources :

Example 6 with TransformOutInterceptor

use of org.apache.cxf.interceptor.transform.TransformOutInterceptor in project cxf by apache.

the class ProtocolVariationsTest method testInvalidWSAOnReceive.

@Test
public void testInvalidWSAOnReceive() throws Exception {
    init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", false);
    // WS-RM 1.0 using the WS-A 1.0 namespace
    Client client = ClientProxy.getClient(greeter);
    client.getRequestContext().put(RMManager.WSRM_VERSION_PROPERTY, RM10Constants.NAMESPACE_URI);
    client.getRequestContext().put(RMManager.WSRM_WSA_VERSION_PROPERTY, Names200408.WSA_NAMESPACE_NAME);
    // rewrite the outgoing message's WS-A namespace to an invalid one
    TransformOutInterceptor trans = new TransformOutInterceptor();
    Map<String, String> outElements = new HashMap<>();
    outElements.put("{" + Names200408.WSA_NAMESPACE_NAME + "}*", "{http://cxf.apache.org/invalid}*");
    trans.setOutTransformElements(outElements);
    client.getOutInterceptors().add(trans);
    try {
        greeter.greetMe("one");
        fail("invalid wsa header accepted");
    } catch (Exception e) {
        assertTrue(e.getCause() instanceof SoapFault);
        // verify a partial error text match to exclude an unexpected exception
        // (see WSA_REQUIRED_EXC in Messages.properties)
        final String text = "WS-Addressing is required";
        assertTrue(e.getCause().getMessage() != null && e.getCause().getMessage().indexOf(text) >= 0);
    }
}
Also used : SoapFault(org.apache.cxf.binding.soap.SoapFault) HashMap(java.util.HashMap) Client(org.apache.cxf.endpoint.Client) TransformOutInterceptor(org.apache.cxf.interceptor.transform.TransformOutInterceptor) RMException(org.apache.cxf.ws.rm.RMException) Test(org.junit.Test)

Example 7 with TransformOutInterceptor

use of org.apache.cxf.interceptor.transform.TransformOutInterceptor in project cxf by apache.

the class ProtocolVariationsTest method testInvalidRM11WSA200408OnReceive.

@Test
public void testInvalidRM11WSA200408OnReceive() throws Exception {
    init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", false);
    // WS-RM 1.0 using the WS-A 1.0 namespace
    Client client = ClientProxy.getClient(greeter);
    client.getRequestContext().put(RMManager.WSRM_VERSION_PROPERTY, RM10Constants.NAMESPACE_URI);
    client.getRequestContext().put(RMManager.WSRM_WSA_VERSION_PROPERTY, Names200408.WSA_NAMESPACE_NAME);
    // rewrite the outgoing message's WS-RM namespace to 1.1
    TransformOutInterceptor trans = new TransformOutInterceptor();
    Map<String, String> outElements = new HashMap<>();
    outElements.put("{" + RM10Constants.NAMESPACE_URI + "}*", "{" + RM11Constants.NAMESPACE_URI + "}*");
    trans.setOutTransformElements(outElements);
    client.getOutInterceptors().add(trans);
    try {
        greeter.greetMe("one");
        fail("invalid namespace combination accepted");
    } catch (Exception e) {
        assertTrue(e.getCause() instanceof SoapFault);
        // verify a partial error text match to exclude an unexpected exception
        // (see WSRM_REQUIRED_EXC in Messages.properties)
        final String text = "WS-ReliableMessaging is required";
        assertTrue(e.getCause().getMessage() != null && e.getCause().getMessage().indexOf(text) >= 0);
    }
}
Also used : SoapFault(org.apache.cxf.binding.soap.SoapFault) HashMap(java.util.HashMap) Client(org.apache.cxf.endpoint.Client) TransformOutInterceptor(org.apache.cxf.interceptor.transform.TransformOutInterceptor) RMException(org.apache.cxf.ws.rm.RMException) Test(org.junit.Test)

Example 8 with TransformOutInterceptor

use of org.apache.cxf.interceptor.transform.TransformOutInterceptor in project cxf by apache.

the class JAXRSSoapBookTest method testGetUnqualifiedBookSoap.

@Test
public void testGetUnqualifiedBookSoap() throws Exception {
    String wsdlAddress = "http://localhost:" + PORT + "/test/services/soap-transform/bookservice?wsdl";
    BookSoapService service = new BookSoapService(new URL(wsdlAddress), new QName("http://books.com", "BookService"));
    BookStoreJaxrsJaxws store = service.getBookPort();
    TransformOutInterceptor out = new TransformOutInterceptor();
    Map<String, String> mapOut = new HashMap<>();
    // Book content (id, name) is unqualified, thus the following works
    // because JAXB will report
    // - {http://jaxws.jaxrs.systest.cxf.apache.org/}Book
    // - id
    // - name
    // and only the qualified top-level Book tag gets matched by the following
    // mapping
    mapOut.put("{http://jaxws.jaxrs.systest.cxf.apache.org/}*", "*");
    out.setOutTransformElements(mapOut);
    TransformInInterceptor in = new TransformInInterceptor();
    Map<String, String> mapIn = new HashMap<>();
    // mapIn.put("*", "{http://jaxws.jaxrs.systest.cxf.apache.org/}*");
    // won't work for a case where a totally unqualified getBookResponse needs to be
    // qualified such that only the top-level getBookResponse is processed because of '*'.
    // Such a mapping would work nicely if we had say a package-info making both
    // Book id & name qualified; otherwise we need to choose what tag we need to qualify
    // mapIn.put("*", "{http://jaxws.jaxrs.systest.cxf.apache.org/}*");
    // works too if the schema validation is disabled
    mapIn.put("getBookResponse", "{http://jaxws.jaxrs.systest.cxf.apache.org/}getBookResponse");
    in.setInTransformElements(mapIn);
    Client cl = ClientProxy.getClient(store);
    ((HTTPConduit) cl.getConduit()).getClient().setReceiveTimeout(10000000);
    cl.getInInterceptors().add(in);
    cl.getOutInterceptors().add(out);
    Book book = store.getBook(Long.valueOf(123));
    assertEquals("id is wrong", book.getId(), 123);
}
Also used : BookStoreJaxrsJaxws(org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws) HashMap(java.util.HashMap) BookSoapService(org.apache.cxf.systest.jaxrs.jaxws.BookSoapService) QName(javax.xml.namespace.QName) TransformOutInterceptor(org.apache.cxf.interceptor.transform.TransformOutInterceptor) Client(org.apache.cxf.endpoint.Client) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) TransformInInterceptor(org.apache.cxf.interceptor.transform.TransformInInterceptor) Test(org.junit.Test)

Example 9 with TransformOutInterceptor

use of org.apache.cxf.interceptor.transform.TransformOutInterceptor in project tesb-rt-se by Talend.

the class RESTClient method addTransformInterceptors.

/**
 * Prepares transformation interceptors for a client.
 *
 * @param clientConfig the client configuration
 * @param newClient indicates if it is a new/updated client
 */
private void addTransformInterceptors(List<Interceptor<?>> inInterceptors, List<Interceptor<?>> outInterceptors, boolean newClient) {
    // The old service expects the Customer data be qualified with
    // the 'http://customer/v1' namespace.
    // The new service expects the Customer data be qualified with
    // the 'http://customer/v2' namespace.
    // If it is an old client talking to the new service then:
    // - the out transformation interceptor is configured for
    // 'http://customer/v1' qualified data be transformed into
    // 'http://customer/v2' qualified data.
    // - the in transformation interceptor is configured for
    // 'http://customer/v2' qualified response data be transformed into
    // 'http://customer/v1' qualified data.
    // If it is a new client talking to the old service then:
    // - the out transformation interceptor is configured for
    // 'http://customer/v2' qualified data be transformed into
    // 'http://customer/v1' qualified data.
    // - the in transformation interceptor is configured for
    // 'http://customer/v1' qualified response data be transformed into
    // 'http://customer/v2' qualified data.
    // - new Customer type also introduces a briefDescription property
    // which needs to be dropped for the old service validation to succeed
    // this configuration can be provided externally
    Map<String, String> newToOldTransformMap = Collections.singletonMap("{http://customer/v2}*", "{http://customer/v1}*");
    Map<String, String> oldToNewTransformMap = Collections.singletonMap("{http://customer/v1}*", "{http://customer/v2}*");
    TransformOutInterceptor outTransform = new TransformOutInterceptor();
    outTransform.setOutTransformElements(newClient ? newToOldTransformMap : oldToNewTransformMap);
    if (newClient) {
        outTransform.setOutDropElements(Collections.singletonList("{http://customer/v2}briefDescription"));
    }
    TransformInInterceptor inTransform = new TransformInInterceptor();
    inTransform.setInTransformElements(newClient ? oldToNewTransformMap : newToOldTransformMap);
    inInterceptors.add(inTransform);
    outInterceptors.add(outTransform);
}
Also used : TransformOutInterceptor(org.apache.cxf.interceptor.transform.TransformOutInterceptor) TransformInInterceptor(org.apache.cxf.interceptor.transform.TransformInInterceptor)

Example 10 with TransformOutInterceptor

use of org.apache.cxf.interceptor.transform.TransformOutInterceptor in project tesb-rt-se by Talend.

the class TransformationPolicyOutInterceptor method proceedSimple.

protected void proceedSimple(Message message, TransformationAssertion tas) {
    if (!shouldTransform(message, tas.getMessageType(), tas.getAppliesTo())) {
        return;
    }
    Object map = message.getContextualProperty(TRANSFORM_MAP);
    if (!(map instanceof Map)) {
        return;
    }
    @SuppressWarnings("unchecked") Map<String, String> outTransformMap = (Map<String, String>) map;
    TransformOutInterceptor simpleOut = new TransformOutInterceptor();
    simpleOut.setOutTransformElements(outTransformMap);
    simpleOut.handleMessage(message);
}
Also used : TransformOutInterceptor(org.apache.cxf.interceptor.transform.TransformOutInterceptor) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

TransformOutInterceptor (org.apache.cxf.interceptor.transform.TransformOutInterceptor)10 HashMap (java.util.HashMap)8 Test (org.junit.Test)7 Client (org.apache.cxf.endpoint.Client)5 TransformInInterceptor (org.apache.cxf.interceptor.transform.TransformInInterceptor)5 SoapFault (org.apache.cxf.binding.soap.SoapFault)4 RMException (org.apache.cxf.ws.rm.RMException)4 WebClient (org.apache.cxf.jaxrs.client.WebClient)2 URL (java.net.URL)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 QName (javax.xml.namespace.QName)1 Bus (org.apache.cxf.Bus)1 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)1 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)1 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)1 GreeterService (org.apache.cxf.greeter_control.GreeterService)1 BookSoapService (org.apache.cxf.systest.jaxrs.jaxws.BookSoapService)1 BookStoreJaxrsJaxws (org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1