use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class HTTP2XMLInterceptor method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
log.debug("uri: " + exc.getRequest().getUri());
String res = new Request(exc.getRequest()).toXml();
log.debug("http-xml: " + res);
exc.getRequest().setBodyContent(res.getBytes("UTF-8"));
// TODO
exc.getRequest().setMethod("POST");
exc.getRequest().getHeader().setSOAPAction("");
return Outcome.CONTINUE;
}
use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class RESTInterceptor method dispatchRequest.
private Outcome dispatchRequest(Exchange exc) throws Exception {
String path = router.getUriFactory().create(exc.getDestinations().get(0)).getPath();
for (Method m : getClass().getMethods()) {
Mapping a = m.getAnnotation(Mapping.class);
if (a == null)
continue;
Matcher matcher = Pattern.compile(a.value()).matcher(path);
if (matcher.matches()) {
Object[] parameters;
switch(m.getParameterTypes().length) {
case 2:
parameters = new Object[] { new QueryParameter(URLParamUtil.getParams(router.getUriFactory(), exc), matcher), getRelativeRootPath(path) };
break;
case 3:
parameters = new Object[] { new QueryParameter(URLParamUtil.getParams(router.getUriFactory(), exc), matcher), getRelativeRootPath(path), exc };
break;
default:
throw new InvalidParameterException("@Mapping is supposed to annotate a 2-parameter method.");
}
exc.setResponse((Response) m.invoke(this, parameters));
return Outcome.RETURN;
}
}
return Outcome.CONTINUE;
}
use of com.predic8.membrane.core.interceptor.Outcome in project service-proxy by membrane.
the class RESTInterceptor method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
log.debug("request: " + exc.getOriginalRequestUri());
exc.setTimeReqSent(System.currentTimeMillis());
Outcome o = dispatchRequest(exc);
exc.setReceived();
exc.setTimeResReceived(System.currentTimeMillis());
return o;
}
use of com.predic8.membrane.core.interceptor.Outcome 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.interceptor.Outcome 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);
}
Aggregations