use of org.apache.cxf.interceptor.transform.TransformOutInterceptor in project tesb-rt-se by Talend.
the class SOAPClient 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 = new HashMap<String, String>();
newToOldTransformMap.put("{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) {
newToOldTransformMap.put("{http://customer/v2}briefDescription", "");
// 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 cxf by apache.
the class JAXRSSoapBookTest method testPostBookTransform.
@Test
public void testPostBookTransform() throws Exception {
String address = "http://localhost:" + PORT + "/test/v1/rest-transform/bookstore/books";
TransformOutInterceptor out = new TransformOutInterceptor();
out.setOutTransformElements(Collections.singletonMap("{http://www.example.org/books}*", "{http://www.example.org/super-books}*"));
TransformInInterceptor in = new TransformInInterceptor();
Map<String, String> map = new HashMap<>();
// If Book2 didn't have {http://www.example.org/books}Book
// then we'd just do '"*" : "{http://www.example.org/books}*'
// but given that we have TheBook being returned, we need
map.put("TheBook", "{http://www.example.org/books}Book");
map.put("id", "{http://www.example.org/books}id");
in.setInTransformElements(map);
WebClient client = WebClient.create(address);
WebClient.getConfig(client).getInInterceptors().add(in);
WebClient.getConfig(client).getOutInterceptors().add(out);
Book2 book = client.type("application/xml").accept("text/xml").post(new Book2(), Book2.class);
assertEquals(124L, book.getId());
}
use of org.apache.cxf.interceptor.transform.TransformOutInterceptor in project cxf by apache.
the class ProtocolVariationsTest method testInvalidWSRMOnReceive.
@Test
public void testInvalidWSRMOnReceive() 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);
// remove the outgoing message's WS-RM header
TransformOutInterceptor trans = new TransformOutInterceptor();
Map<String, String> outElements = new HashMap<>();
outElements.put("{" + RM10Constants.NAMESPACE_URI + "}Sequence", "");
trans.setOutTransformElements(outElements);
client.getOutInterceptors().add(trans);
try {
greeter.greetMe("one");
fail("invalid wsrm header");
} 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 ProtocolVariationsTest method testInvalidWSRMMustUnderstandOnReceive.
@Test
public void testInvalidWSRMMustUnderstandOnReceive() 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 an invalid one
TransformOutInterceptor trans = new TransformOutInterceptor();
Map<String, String> outElements = new HashMap<>();
outElements.put("{" + RM10Constants.NAMESPACE_URI + "}*", "{http://cxf.apache.org/invalid}*");
trans.setOutTransformElements(outElements);
client.getOutInterceptors().add(trans);
try {
greeter.greetMe("one");
fail("invalid wsrm header");
} catch (Exception e) {
assertTrue(e.getCause() instanceof SoapFault);
final String text = "WS-ReliableMessaging is required";
assertTrue(e.getCause().getMessage(), 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 StaxTransformFeatureTest method testTransformWithLogging.
@Test
public void testTransformWithLogging() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
Bus bus = bf.createBus();
BusFactory.setDefaultBus(bus);
TestLoggingEventSender logIn = new TestLoggingEventSender();
bus.getInInterceptors().add(new LoggingInInterceptor(logIn));
bus.getInFaultInterceptors().add(new LoggingInInterceptor(logIn));
TestLoggingEventSender logOut = new TestLoggingEventSender();
bus.getOutInterceptors().add(new LoggingOutInterceptor(logOut));
bus.getOutFaultInterceptors().add(new LoggingOutInterceptor(logOut));
TransformInInterceptor transIn = new TransformInInterceptor();
Map<String, String> inElements = new HashMap<>();
inElements.put("{http://cxf.apache.org/greeter_control/types}noFaultDetail", "{http://cxf.apache.org/greeter_control/types}faultDetail");
bus.getInInterceptors().add(transIn);
TransformOutInterceptor transOut = new TransformOutInterceptor();
Map<String, String> outElements = new HashMap<>();
outElements.put("{http://cxf.apache.org/greeter_control/types}pingMe", "{http://cxf.apache.org/greeter_control/types}dontPingMe");
transOut.setOutTransformElements(outElements);
bus.getOutInterceptors().add(transOut);
bus.getOutFaultInterceptors().add(transOut);
GreeterService gs = new GreeterService();
greeter = gs.getGreeterPort();
updateAddressPort(greeter, PORT);
LOG.fine("Created greeter client.");
// ping 1: request-response transformation
greeter.pingMe();
verifyPayload(logOut.getMessage(), "dontPingMe");
verifyPayload(logIn.getMessage(), "pingMeResponse");
verifyPayload(serverlogIn.getMessage(), "dontPingMe");
verifyPayload(serverlogOut.getMessage(), "pingMeResponse");
serverlogOut.cleaerMessage();
serverlogIn.cleaerMessage();
logOut.cleaerMessage();
logIn.cleaerMessage();
// ping 2: request-fault transformation
try {
greeter.pingMe();
fail("Ping should have failed");
} catch (Exception e) {
assertEquals("Pings succeed only every other time.", e.getMessage());
}
verifyPayload(logOut.getMessage(), "dontPingMe");
verifyPayload(logIn.getMessage(), "noFaultDetail");
verifyPayload(serverlogIn.getMessage(), "dontPingMe");
verifyPayload(serverlogOut.getMessage(), "noFaultDetail");
// ping 3: idle
greeter.pingMe();
serverlogOut.cleaerMessage();
serverlogIn.cleaerMessage();
logOut.cleaerMessage();
logIn.cleaerMessage();
// ping 4: request-fault transformation with skipOnFault
transOut.setSkipOnFault(true);
servertransOut.setSkipOnFault(true);
try {
greeter.pingMe();
fail("Ping should have failed");
} catch (Exception e) {
assertEquals("Pings succeed only every other time.", e.getMessage());
}
verifyPayload(logOut.getMessage(), "dontPingMe");
verifyPayload(logIn.getMessage(), "faultDetail");
verifyPayload(serverlogIn.getMessage(), "dontPingMe");
verifyPayload(serverlogOut.getMessage(), "faultDetail");
bus.shutdown(true);
}
Aggregations