use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping 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.rewrite.RewriteInterceptor.Mapping 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.rewrite.RewriteInterceptor.Mapping in project service-proxy by membrane.
the class REST2SOAPInterceptor method modifyRequest.
private void modifyRequest(AbstractExchange exc, Mapping mapping) {
exc.getRequest().setMethod("POST");
exc.getRequest().getHeader().setSOAPAction(mapping.soapAction);
Header header = exc.getRequest().getHeader();
header.removeFields(Header.CONTENT_TYPE);
header.setContentType(isSOAP12(exc) ? MimeType.APPLICATION_SOAP : MimeType.TEXT_XML_UTF8);
exc.setProperty("mapping", mapping);
setServiceEndpoint(exc, mapping);
}
use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping in project service-proxy by membrane.
the class DynamicAdminPageInterceptor method handleNodeSessionsRequest.
@Mapping("/admin/node/sessions/?(\\?.*)?")
public Response handleNodeSessionsRequest(final Map<String, String> params, String relativeRootPath) throws Exception {
StringWriter writer = new StringWriter();
return respond(new AdminPageBuilder(writer, router, relativeRootPath, params, readOnly) {
@Override
protected int getSelectedTab() {
return TAB_ID_LOAD_BALANCING;
}
@Override
protected void createTabContent() throws Exception {
h2().text("Node " + params.get("host") + ":" + params.get("port")).end();
h3().text("Sessions").end();
createSessionsTable(BalancerUtil.lookupBalancer(router, getBalancerParam(params)).getSessionsByNode(params.get("cluster"), new Node(params.get("host"), Integer.parseInt(params.get("port")))));
}
}.createPage());
}
use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping in project service-proxy by membrane.
the class DynamicAdminPageInterceptor method handleSystemRequest.
@Mapping("/admin/system/?(\\?.*)?")
public Response handleSystemRequest(final Map<String, String> params, String relativeRootPath) throws Exception {
StringWriter writer = new StringWriter();
return respond(new AdminPageBuilder(writer, router, relativeRootPath, params, readOnly) {
static final int mb = 1024 * 1024;
final DecimalFormat formatter = new DecimalFormat("#.00");
private String formatMemoryValue(float value) {
float newValue = value / (float) mb;
String unit = "MB";
if (newValue > 1024)
unit = "GB";
return formatter.format(newValue) + " " + unit;
}
@Override
protected int getSelectedTab() {
return TAB_ID_SYSTEM;
}
@Override
protected void createTabContent() {
h2().text("System").end();
p().text("Availabe system memory: " + formatMemoryValue(Runtime.getRuntime().totalMemory())).end();
p().text("Free system memory: " + formatMemoryValue(Runtime.getRuntime().freeMemory())).end();
p().text("Membrane version: " + Constants.VERSION).end();
// createLogConfigurationEditor();
}
}.createPage());
}
Aggregations