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;
}
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"), "");
}
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());
}
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;
}
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());
}
Aggregations