use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class SOAPRESTHelper method getRequestXMLSource.
protected StreamSource getRequestXMLSource(Exchange exc) throws Exception {
Request req = new Request(exc.getRequest());
String res = req.toXml();
log.debug("http-xml: " + res);
return new StreamSource(new StringReader(res));
}
use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class WSDLPublisherInterceptor method handleRequest.
@Override
public Outcome handleRequest(final Exchange exc) throws Exception {
if (!"GET".equals(exc.getRequest().getMethod()))
return Outcome.CONTINUE;
try {
String resource = null;
if (exc.getRequestURI().endsWith("?wsdl") || exc.getRequestURI().endsWith("?WSDL")) {
processDocuments(exc);
exc.setResponse(WebServerInterceptor.createResponse(router.getResolverMap(), resource = wsdl));
exc.getResponse().getHeader().setContentType(MimeType.TEXT_XML);
}
if (exc.getRequestURI().contains("?xsd=")) {
Map<String, String> params = URLParamUtil.getParams(router.getUriFactory(), exc);
if (params.containsKey("xsd")) {
int n = Integer.parseInt(params.get("xsd"));
String path;
processDocuments(exc);
synchronized (paths) {
if (!paths.containsKey(n)) {
exc.setResponse(Response.forbidden("Unknown parameter. You may only retrieve documents referenced by the WSDL.").build());
return Outcome.ABORT;
}
path = paths.get(n);
}
exc.setResponse(WebServerInterceptor.createResponse(router.getResolverMap(), resource = path));
exc.getResponse().getHeader().setContentType(MimeType.TEXT_XML);
}
}
if (resource != null) {
WSDLInterceptor wi = new WSDLInterceptor();
wi.setRewriteEndpoint(false);
wi.setPathRewriter(new RelativePathRewriter(exc, resource));
wi.handleResponse(exc);
return Outcome.RETURN;
}
} catch (NumberFormatException e) {
exc.setResponse(HttpUtil.setHTMLErrorResponse(Response.internalServerError(), "Bad parameter format.", ""));
return Outcome.ABORT;
} catch (ResourceRetrievalException e) {
exc.setResponse(Response.notFound().build());
return Outcome.ABORT;
}
return Outcome.CONTINUE;
}
use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.
the class SwaggerRewriterInterceptor method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
((ServiceProxy) exc.getRule()).setTargetHost(swagger.getHost());
URL url = new URL(swaggerUrl);
exc.getDestinations().set(0, url.getProtocol() + "://" + url.getHost() + (url.getPort() < 0 ? "" : ":" + url.getPort()) + exc.getOriginalRequestUri());
return super.handleRequest(exc);
}
use of com.predic8.membrane.core.exchange.Exchange 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.exchange.Exchange 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;
}
Aggregations