use of org.apache.cxf.interceptor.transform.TransformInInterceptor 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.TransformInInterceptor 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);
}
use of org.apache.cxf.interceptor.transform.TransformInInterceptor 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(new Long(123));
assertEquals("id is wrong", book.getId(), 123);
}
Aggregations