Search in sources :

Example 36 with Service

use of com.predic8.wsdl.Service in project service-proxy by membrane.

the class XPathCBRInterceptorTest method testRouting.

@Test
public void testRouting() throws Exception {
    exc = new Exchange(null);
    Request res = new Request();
    res.setBodyContent(getByteArrayData(getClass().getResourceAsStream("/customerFromBonn.xml")));
    exc.setRequest(res);
    XPathCBRInterceptor i = new XPathCBRInterceptor();
    i.setCases(getRouteList("//CITY[text()='England']", "http://www.host.uk/service", "//CITY[text()='Bonn']", "http://www.host.de/service"));
    i.handleRequest(exc);
    Assert.assertEquals("http://www.host.de/service", exc.getDestinations().get(0));
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Request(com.predic8.membrane.core.http.Request) Test(org.junit.Test)

Example 37 with Service

use of com.predic8.wsdl.Service in project service-proxy by membrane.

the class XPathCBRInterceptorTest method testRoutingNSAware.

@Test
public void testRoutingNSAware() throws Exception {
    exc = new Exchange(null);
    Request res = new Request();
    res.setBodyContent(getByteArrayData(getClass().getResourceAsStream("/customerFromBonnWithNS.xml")));
    exc.setRequest(res);
    XPathCBRInterceptor i = new XPathCBRInterceptor();
    i.setCases(getRouteList("//pre:CITY[text()='England']", "http://www.host.uk/service", "//pre:CITY[text()='Bonn']", "http://www.host.de/service"));
    i.setNamespaces(getNamespaceMap("pre", "http://predic8.de/customer/1"));
    i.handleRequest(exc);
    Assert.assertEquals("http://www.host.de/service", exc.getDestinations().get(0));
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Request(com.predic8.membrane.core.http.Request) Test(org.junit.Test)

Example 38 with Service

use of com.predic8.wsdl.Service in project service-proxy by membrane.

the class DynamicAdminPageInterceptor method handleServiceProxyStartRequest.

@Mapping("/admin/service-proxy/start/?(\\?.*)?")
public Response handleServiceProxyStartRequest(Map<String, String> params, String relativeRootPath) throws Exception {
    if (readOnly)
        return createReadOnlyErrorResponse();
    Rule rule = RuleUtil.findRuleByIdentifier(router, params.get("name"));
    Rule newRule = rule.clone();
    router.getRuleManager().replaceRule(rule, newRule);
    return respond(getServiceProxyPage(params, relativeRootPath));
}
Also used : ProxyRule(com.predic8.membrane.core.rules.ProxyRule) Rule(com.predic8.membrane.core.rules.Rule)

Example 39 with Service

use of com.predic8.wsdl.Service in project service-proxy by membrane.

the class DynamicAdminPageInterceptor method handleServiceProxySaveRequest.

@Mapping("/admin/service-proxy/save/?(\\?.*)?")
public Response handleServiceProxySaveRequest(Map<String, String> params, String relativeRootPath) throws Exception {
    if (readOnly)
        return createReadOnlyErrorResponse();
    logAddFwdRuleParams(params);
    Rule r = new ServiceProxy(new ServiceProxyKey("*", params.get("method"), ".*", getPortParam(params), null), params.get("targetHost"), getTargetPortParam(params));
    r.setName(params.get("name"));
    try {
        router.getRuleManager().addProxyAndOpenPortIfNew(r);
    } catch (PortOccupiedException e) {
        return Response.internalServerError("The port could not be opened: Either it is occupied or Membrane does " + "not have enough privileges to do so.").build();
    }
    return respond(getServiceProxyPage(params, relativeRootPath));
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) PortOccupiedException(com.predic8.membrane.core.transport.PortOccupiedException) ProxyRule(com.predic8.membrane.core.rules.ProxyRule) Rule(com.predic8.membrane.core.rules.Rule)

Example 40 with Service

use of com.predic8.wsdl.Service in project service-proxy by membrane.

the class AMStatisticsCollector method collectStatisticFrom.

private String collectStatisticFrom(Exchange exc, String apiKey) throws IOException {
    StatisticCollector statistics = new StatisticCollector(false);
    statistics.collectFrom(exc);
    JsonGenerator gen = getAndResetJsonGenerator();
    try {
        gen.writeStartObject();
        gen.writeObjectField("excId", exc.getId());
        gen.writeObjectField("excTime", exc.getTime().toInstant().toString());
        gen.writeObjectField("excApiKey", apiKey);
        gen.writeObjectField("service", exc.getRule().getName());
        gen.writeObjectField("uri", exc.getOriginalRequestUri());
        gen.writeObjectField("method", exc.getRequest().getMethod());
        gen.writeObjectField("excStatus", exc.getStatus().toString());
        gen.writeObjectField("code", exc.getResponse().getStatusCode());
        gen.writeObjectField("time", getInflightTime(exc));
        gen.writeEndObject();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return getStringFromJsonGenerator();
}
Also used : JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) StatisticCollector(com.predic8.membrane.core.rules.StatisticCollector)

Aggregations

Test (org.junit.Test)39 Process2 (com.predic8.membrane.examples.Process2)35 File (java.io.File)29 StringWriter (java.io.StringWriter)5 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)4 Rule (com.predic8.membrane.core.rules.Rule)4 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 HttpRouter (com.predic8.membrane.core.HttpRouter)3 ProxiesXmlUtil (com.predic8.membrane.examples.ProxiesXmlUtil)3 BufferLogger (com.predic8.membrane.examples.util.BufferLogger)3 SubstringWaitableConsoleEvent (com.predic8.membrane.examples.util.SubstringWaitableConsoleEvent)3 Definitions (com.predic8.wsdl.Definitions)3 Port (com.predic8.wsdl.Port)3 Service (com.predic8.wsdl.Service)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Exchange (com.predic8.membrane.core.exchange.Exchange)2 Request (com.predic8.membrane.core.http.Request)2 Response (com.predic8.membrane.core.http.Response)2