use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class STOMPClient method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
String login = exc.getRequest().getHeader().getFirstValue("login");
String passcode = exc.getRequest().getHeader().getFirstValue("passcode");
String host = exc.getRequest().getHeader().getFirstValue("host");
String acceptVersion = exc.getRequest().getHeader().getFirstValue("accept-version");
boolean isStomp1_0 = login != null && passcode != null;
boolean isStomp1_1orAbove = host != null && acceptVersion != null;
if (isStomp1_0 || isStomp1_1orAbove) {
Connection c = connectionManager.getConnection(this.host, port, connectionConfiguration.getLocalAddr(), sslOutboundProvider, connectionConfiguration.getTimeout());
exc.getRequest().writeSTOMP(c.out);
HttpClient.setupConnectionForwarding(exc, c, "STOMP", getRouter().getStatistics().getStreamPumpStats());
} else {
exc.setResponse(Response.badRequest().build());
}
return Outcome.RETURN;
}
use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class RegistrationInterceptor method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
Request request = exc.getRequest();
if (!request.isPOSTRequest())
return ErrorMessages.returnErrorBadRequest(exc);
User user;
try {
user = new ObjectMapper().readValue(request.getBodyAsStringDecoded(), User.class);
} catch (IOException e) {
return ErrorMessages.returnErrorBadRequest(exc);
}
try (Connection connection = userDataProvider.getDatasource().getConnection()) {
try (ResultSet rs = connection.createStatement().executeQuery(getIsAccountNameAvailableSQL(user))) {
if (rs.next() && rs.getInt(1) != 0)
return ErrorMessages.returnErrorUserAlreadyExists(exc);
}
if (!SecurityUtils.isHashedPassword(user.getPassword()))
user.setPassword(SecurityUtils.createPasswdCompatibleHash(user.getPassword()));
connection.createStatement().executeUpdate(getInsertAccountIntoDatabaseSQL(user));
}
// TODO: Save user mit flag if confirmated
// TODO: Send Confirmation Email
// TODO: PreparedStatements gegen SQL-Injection verwenden??????
exc.setResponse(Response.ok().build());
return Outcome.RETURN;
}
use of com.predic8.membrane.core.interceptor.Outcome 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.interceptor.Outcome in project service-proxy by membrane.
the class LargeBodyTest method setup.
public void setup() throws Exception {
// streaming only works for maxRetries = 1
hcc = new HttpClientConfiguration();
hcc.setMaxRetries(1);
Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3040), "thomas-bayer.com", 80);
rule.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
exc.setResponse(Response.ok().body("").build());
return Outcome.RETURN;
}
});
router = new HttpRouter();
((HTTPClientInterceptor) router.getTransport().getInterceptors().get(3)).setHttpClientConfig(hcc);
router.getRuleManager().addProxyAndOpenPortIfNew(rule);
router.init();
Rule rule1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3041), "localhost", 3040);
router2 = new HttpRouter();
((HTTPClientInterceptor) router2.getTransport().getInterceptors().get(3)).setHttpClientConfig(hcc);
router2.getRuleManager().addProxyAndOpenPortIfNew(rule1);
router2.init();
}
use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class LoadBalancingInterceptorTest method testFailOverOnStatus500.
@Test
public void testFailOverOnStatus500() throws Exception {
balancingInterceptor.setDispatchingStrategy(roundRobinStrategy);
HttpClient client = new HttpClient();
client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(1, mockInterceptor1.getCount());
assertEquals(0, mockInterceptor2.getCount());
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(1, mockInterceptor1.getCount());
assertEquals(1, mockInterceptor2.getCount());
((ServiceProxy) service1.getRuleManager().getRules().get(0)).getInterceptors().add(0, new AbstractInterceptor() {
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
exc.setResponse(Response.internalServerError().build());
return Outcome.ABORT;
}
});
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(1, mockInterceptor1.getCount());
assertEquals(2, mockInterceptor2.getCount());
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(3, mockInterceptor2.getCount());
}
Aggregations