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);
}
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations