Search in sources :

Example 1 with XSLTInterceptor

use of com.predic8.membrane.core.interceptor.xslt.XSLTInterceptor in project service-proxy by membrane.

the class XSLTInterceptorTest method testRequest.

@Test
public void testRequest() throws Exception {
    exc = new Exchange(null);
    exc.setResponse(Response.ok().body(getClass().getResourceAsStream("/customer.xml"), true).build());
    XSLTInterceptor i = new XSLTInterceptor();
    i.setXslt("classpath:/customer2person.xsl");
    i.init(new HttpRouter());
    i.handleResponse(exc);
    // printBodyContent();
    assertXPath("/person/name/first", "Rick");
    assertXPath("/person/name/last", "Cort\u00e9s Ribotta");
    assertXPath("/person/address/street", "Calle P\u00fablica \"B\" 5240 Casa 121");
    assertXPath("/person/address/city", "Omaha");
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) HttpRouter(com.predic8.membrane.core.HttpRouter) Test(org.junit.Test)

Example 2 with XSLTInterceptor

use of com.predic8.membrane.core.interceptor.xslt.XSLTInterceptor in project service-proxy by membrane.

the class RESTBLZServiceIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3005), "thomas-bayer.com", 80);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    HTTP2XMLInterceptor http2xml = new HTTP2XMLInterceptor();
    router.getTransport().getInterceptors().add(http2xml);
    RewriteInterceptor urlRewriter = new RewriteInterceptor();
    List<Mapping> mappings = new ArrayList<Mapping>();
    mappings.add(new Mapping("/bank/.*", "/axis2/services/BLZService", null));
    urlRewriter.setMappings(mappings);
    router.getTransport().getInterceptors().add(urlRewriter);
    XSLTInterceptor xslt = new XSLTInterceptor();
    xslt.setXslt("classpath:/blz-httpget2soap-request.xsl");
    xslt.setFlow(Flow.Set.REQUEST);
    xslt.setXslt("classpath:/strip-soap-envelope.xsl");
    xslt.setFlow(Flow.Set.RESPONSE);
    router.getTransport().getInterceptors().add(xslt);
}
Also used : Mapping(com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter) XSLTInterceptor(com.predic8.membrane.core.interceptor.xslt.XSLTInterceptor)

Example 3 with XSLTInterceptor

use of com.predic8.membrane.core.interceptor.xslt.XSLTInterceptor in project service-proxy by membrane.

the class XSLTInterceptorTest method testXSLTParameter.

@Test
public void testXSLTParameter() throws Exception {
    exc = new Exchange(null);
    exc.setResponse(Response.ok().body(getClass().getResourceAsStream("/customer.xml"), true).build());
    exc.setProperty("XSLT_COMPANY", "predic8");
    XSLTInterceptor i = new XSLTInterceptor();
    i.setXslt("classpath:/customer2personAddCompany.xsl");
    i.init(new HttpRouter());
    i.handleResponse(exc);
    // printBodyContent();
    assertXPath("/person/name/first", "Rick");
    assertXPath("/person/name/last", "Cort\u00e9s Ribotta");
    assertXPath("/person/address/street", "Calle P\u00fablica \"B\" 5240 Casa 121");
    assertXPath("/person/address/city", "Omaha");
    assertXPath("/person/company", "predic8");
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) HttpRouter(com.predic8.membrane.core.HttpRouter) Test(org.junit.Test)

Aggregations

HttpRouter (com.predic8.membrane.core.HttpRouter)3 Exchange (com.predic8.membrane.core.exchange.Exchange)2 Test (org.junit.Test)2 Mapping (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping)1 XSLTInterceptor (com.predic8.membrane.core.interceptor.xslt.XSLTInterceptor)1 Rule (com.predic8.membrane.core.rules.Rule)1