use of com.predic8.membrane.core.transport.http.Connection in project service-proxy by membrane.
the class Request method parseStartLine.
@Override
public void parseStartLine(InputStream in) throws IOException, EndOfStreamException {
try {
String firstLine = HttpUtil.readLine(in);
Matcher matcher = pattern.matcher(firstLine);
if (matcher.find()) {
method = matcher.group(1);
uri = matcher.group(2);
version = matcher.group(3);
} else if (stompPattern.matcher(firstLine).find()) {
method = firstLine;
uri = "";
version = "STOMP";
} else {
throw new EOFWhileReadingFirstLineException(firstLine);
}
} catch (EOFWhileReadingLineException e) {
if (e.getLineSoFar().length() == 0)
// happens regularly at the end of a keep-alive connection
throw new NoMoreRequestsException();
throw new EOFWhileReadingFirstLineException(e.getLineSoFar());
}
}
use of com.predic8.membrane.core.transport.http.Connection 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.transport.http.Connection 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.transport.http.Connection in project service-proxy by membrane.
the class HttpUtil method createHeaders.
public static Header createHeaders(String contentType, String... headers) {
Header header = new Header();
if (contentType != null)
header.setContentType(contentType);
synchronized (GMT_DATE_FORMAT) {
header.add("Date", GMT_DATE_FORMAT.format(new Date()));
}
header.add("Server", Constants.PRODUCT_NAME + " " + Constants.VERSION + ". See http://membrane-soa.org");
header.add("Connection", Header.CLOSE);
for (int i = 0; i < headers.length; i += 2) {
header.add(headers[i], headers[i + 1]);
}
return header;
}
use of com.predic8.membrane.core.transport.http.Connection in project service-proxy by membrane.
the class LoadBalancingInterceptorTest method setUp.
@Before
public void setUp() throws Exception {
service1 = new HttpRouter();
mockInterceptor1 = new DummyWebServiceInterceptor();
ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 2000), "thomas-bayer.com", 80);
sp1.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleResponse(Exchange exc) throws Exception {
exc.getResponse().getHeader().add("Connection", "close");
return Outcome.CONTINUE;
}
});
sp1.getInterceptors().add(mockInterceptor1);
service1.getRuleManager().addProxyAndOpenPortIfNew(sp1);
service1.init();
service2 = new HttpRouter();
mockInterceptor2 = new DummyWebServiceInterceptor();
ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3000), "thomas-bayer.com", 80);
sp2.getInterceptors().add(new AbstractInterceptor() {
@Override
public Outcome handleResponse(Exchange exc) throws Exception {
exc.getResponse().getHeader().add("Connection", "close");
return Outcome.CONTINUE;
}
});
sp2.getInterceptors().add(mockInterceptor2);
service2.getRuleManager().addProxyAndOpenPortIfNew(sp2);
service2.init();
balancer = new HttpRouter();
ServiceProxy sp3 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 7000), "thomas-bayer.com", 80);
balancingInterceptor = new LoadBalancingInterceptor();
balancingInterceptor.setName("Default");
sp3.getInterceptors().add(balancingInterceptor);
balancer.getRuleManager().addProxyAndOpenPortIfNew(sp3);
enableFailOverOn5XX(balancer);
balancer.init();
BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", 2000);
BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", 3000);
roundRobinStrategy = new RoundRobinStrategy();
byThreadStrategy = new ByThreadStrategy();
}
Aggregations