Search in sources :

Example 31 with Exchange

use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.

the class REST2SOAPInterceptor method handleResponse.

@Override
public Outcome handleResponse(Exchange exc) throws Exception {
    Mapping mapping = getRESTURL(exc);
    log.debug("restURL: " + mapping);
    if (getRESTURL(exc) == null)
        return Outcome.CONTINUE;
    if (log.isDebugEnabled())
        log.debug("response: " + new String(getTransformer(null).transform(getBodySource(exc), exc.getStringProperties()), Constants.UTF_8_CHARSET));
    exc.getResponse().setBodyContent(getTransformer(mapping.responseXSLT).transform(getBodySource(exc)));
    Header header = exc.getResponse().getHeader();
    header.removeFields(Header.CONTENT_TYPE);
    header.setContentType(MimeType.TEXT_XML_UTF8);
    XML2HTTP.unwrapMessageIfNecessary(exc.getResponse());
    convertResponseToJSONIfNecessary(exc.getRequest().getHeader(), mapping, exc.getResponse(), exc.getStringProperties());
    return Outcome.CONTINUE;
}
Also used : Header(com.predic8.membrane.core.http.Header)

Example 32 with Exchange

use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.

the class DynamicRegistration method registerWithCallbackAt.

public Client registerWithCallbackAt(String callbackUri, String registrationEndpoint) throws Exception {
    Exchange exc = new Request.Builder().post(registrationEndpoint).header(Header.CONTENT_TYPE, MimeType.APPLICATION_JSON_UTF8).body(getRegistrationBody(callbackUri)).buildExchange();
    Response response = doRequest(exc);
    HashMap<String, String> json = Util.parseSimpleJSONResponse(response);
    if (!json.containsKey("client_id") || !json.containsKey("client_secret"))
        throw new RuntimeException("Registration endpoint didn't return clientId/clientSecret");
    return new Client(json.get("client_id"), json.get("client_secret"), "");
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Response(com.predic8.membrane.core.http.Response) Client(com.predic8.membrane.core.interceptor.oauth2.Client) HttpClient(com.predic8.membrane.core.transport.http.HttpClient)

Example 33 with Exchange

use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.

the class ClusterBalancerTest method testNoNodeFound.

@Test
public void testNoNodeFound() throws Exception {
    Exchange exc = getExchangeWithOutSession();
    BalancerUtil.down(r, "Default", "Default", "localhost", 2000);
    BalancerUtil.down(r, "Default", "Default", "localhost", 3000);
    lb.handleRequest(exc);
    assertEquals(500, exc.getResponse().getStatusCode());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange)

Example 34 with Exchange

use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.

the class ClusterBalancerTest method getExchangeWithOutSession.

private Exchange getExchangeWithOutSession() throws IOException {
    Exchange exc = new Exchange(null);
    Request res = new Request();
    res.setHeader(getHeader());
    res.setBodyContent(getByteArrayData(getClass().getResourceAsStream("/getBank.xml")));
    exc.setRequest(res);
    exc.setOriginalRequestUri("/axis2/services/BLZService");
    return exc;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange)

Example 35 with Exchange

use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.

the class NodeOnlineCheckerTest method testExchangeWithException.

@Test
public void testExchangeWithException() {
    Node node = new Node("http://www.predic8.de", 80);
    Exchange exc = new Exchange(null);
    exc.getDestinations().add(0, "http://www.predic8.de:80");
    exc.setNodeException(0, new Exception());
    LoadBalancingInterceptor lbi = new LoadBalancingInterceptor();
    Cluster cl = lbi.getClusterManager().getClusters().get(0);
    cl.nodeUp(node);
    assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
    NodeOnlineChecker noc = new NodeOnlineChecker();
    lbi.setNodeOnlineChecker(noc);
    noc.handle(exc);
    assertEquals(Node.Status.DOWN, cl.getNode(node).getStatus());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Aggregations

Exchange (com.predic8.membrane.core.exchange.Exchange)107 Test (org.junit.Test)39 IOException (java.io.IOException)32 Request (com.predic8.membrane.core.http.Request)25 Outcome (com.predic8.membrane.core.interceptor.Outcome)24 Response (com.predic8.membrane.core.http.Response)16 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)16 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)16 HttpRouter (com.predic8.membrane.core.HttpRouter)14 Before (org.junit.Before)13 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)12 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)11 Header (com.predic8.membrane.core.http.Header)10 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)10 CacheBuilder (com.google.common.cache.CacheBuilder)9 Rule (com.predic8.membrane.core.rules.Rule)6 URISyntaxException (java.net.URISyntaxException)6 UnknownHostException (java.net.UnknownHostException)6 ArrayList (java.util.ArrayList)6 Session (com.predic8.membrane.core.interceptor.authentication.session.SessionManager.Session)5