use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping in project service-proxy by membrane.
the class WebServiceExplorerInterceptor method createSOAPUIResponse.
@Mapping("(?!.*operation)([^?]*)")
public Response createSOAPUIResponse(QueryParameter params, final String relativeRootPath, final Exchange exc) throws Exception {
try {
final String myPath = router.getUriFactory().create(exc.getRequestURI()).getPath();
final Definitions w = getParsedWSDL();
final Service service = getService(w);
final Port port = SOAPProxy.selectPort(service.getPorts(), portName);
final List<Port> ports = getPortsByLocation(service, port);
StringWriter sw = new StringWriter();
new StandardPage(sw, service.getName()) {
@Override
protected void createContent() {
h1().text("Service Proxy: " + service.getName()).end();
p();
text("Target Namespace: " + w.getTargetNamespace());
br().end();
String wsdlLink = getClientURL(exc) + "?wsdl";
text("WSDL: ").a().href(wsdlLink).text(wsdlLink).end();
end();
for (PortType pt : w.getPortTypes()) {
h2().text("Port Type: " + pt.getName()).end();
Documentation d = pt.getDocumentation();
if (d != null) {
p().text("Documentation: " + d.toString()).end();
}
}
Binding binding = port.getBinding();
PortType portType = binding.getPortType();
List<Operation> bindingOperations = getOperationsByBinding(w, binding);
if (bindingOperations.isEmpty())
p().text("There are no operations defined.").end();
else
createOperationsTable(w, bindingOperations, binding, portType);
h2().text("Virtual Endpoint").end();
p().a().href(getClientURL(exc)).text(getClientURL(exc)).end().end();
h2().text("Target Endpoints").end();
if (service.getPorts().isEmpty())
p().text("There are no endpoints defined.").end();
else
createEndpointTable(service.getPorts(), ports);
}
private void createOperationsTable(Definitions w, List<Operation> bindingOperations, Binding binding, PortType portType) {
table().cellspacing("0").cellpadding("0").border("" + 1);
tr();
th().text("Operation").end();
th().text("Input").end();
th().text("Output").end();
end();
for (Operation o : bindingOperations) {
tr();
td();
if ("HTTP".equals(getProtocolVersion(binding))) {
text(o.getName());
} else {
String link = myPath + "/operation/" + binding.getName() + "/" + portType.getName() + "/" + o.getName();
a().href(link).text(o.getName()).end();
}
end();
td();
for (Part p : o.getInput().getMessage().getParts()) text(p.getElement().getName());
end();
td();
for (Part p : o.getOutput().getMessage().getParts()) text(p.getElement().getName());
end();
end();
}
end();
}
private void createEndpointTable(List<Port> ports, List<Port> matchingPorts) {
table().cellspacing("0").cellpadding("0").border("" + 1);
tr();
th().text("Port Name").end();
th().text("Protocol").end();
th().text("URL").end();
end();
for (Port p : ports) {
tr();
td().text(p.getName()).end();
td().text(getProtocolVersion(p.getBinding())).end();
td().text(p.getAddress().getLocation()).end();
td();
if (matchingPorts.contains(p))
text("*");
end();
end();
}
end();
p().small().text("* available through this proxy").end().end();
}
};
return Response.ok(sw.toString()).build();
} catch (IllegalArgumentException e) {
log.error("", e);
return Response.internalServerError().build();
}
}
use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping in project service-proxy by membrane.
the class AdminRESTInterceptor method getProxies.
@Mapping("/admin/rest/proxies(/?\\?.*)?")
public Response getProxies(final QueryParameter params, String relativeRootPath) throws Exception {
final List<AbstractServiceProxy> proxies = getServiceProxies();
if ("order".equals(params.getString("sort"))) {
if (params.getString("order", "asc").equals("desc"))
Collections.reverse(proxies);
} else {
Collections.sort(proxies, ComparatorFactory.getAbstractServiceProxyComparator(params.getString("sort", "name"), params.getString("order", "asc")));
}
final int offset = params.getInt("offset", 0);
int max = params.getInt("max", proxies.size());
final List<AbstractServiceProxy> paginated = proxies.subList(offset, Math.min(offset + max, proxies.size()));
return json(new JSONContent() {
public void write(JsonGenerator gen) throws Exception {
gen.writeStartObject();
gen.writeArrayFieldStart("proxies");
int i = offset;
if (params.getString("order", "asc").equals("desc"))
i = proxies.size() - i + 1;
for (AbstractServiceProxy p : paginated) {
gen.writeStartObject();
gen.writeNumberField("order", i += params.getString("order", "asc").equals("desc") ? -1 : 1);
gen.writeStringField("name", p.toString());
gen.writeBooleanField("active", p.isActive());
if (!p.isActive())
gen.writeStringField("error", p.getErrorState());
gen.writeNumberField("listenPort", p.getKey().getPort());
gen.writeStringField("virtualHost", p.getKey().getHost());
gen.writeStringField("method", p.getKey().getMethod());
gen.writeStringField("path", p.getKey().getPath());
gen.writeStringField("targetHost", p.getTargetHost());
gen.writeNumberField("targetPort", p.getTargetPort());
gen.writeNumberField("count", p.getCount());
gen.writeObjectFieldStart("actions");
if (!isReadOnly()) {
gen.writeStringField("delete", "/admin/service-proxy/delete?name=" + URLEncoder.encode(RuleUtil.getRuleIdentifier(p), "UTF-8"));
}
if (!p.isActive())
gen.writeStringField("start", "/admin/service-proxy/start?name=" + URLEncoder.encode(RuleUtil.getRuleIdentifier(p), "UTF-8"));
gen.writeEndObject();
gen.writeEndObject();
}
gen.writeEndArray();
gen.writeNumberField("total", proxies.size());
gen.writeEndObject();
}
});
}
use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping in project service-proxy by membrane.
the class AdminRESTInterceptor method getRaw.
@Mapping("/admin/rest/exchanges/(-?\\d+)/(response|request)/raw")
public Response getRaw(QueryParameter params, String relativeRootPath) throws Exception {
AbstractExchange exc = router.getExchangeStore().getExchangeById(params.getGroupInt(1));
if (exc == null) {
return Response.notFound().build();
}
Message msg = params.getGroup(2).equals("response") ? exc.getResponse() : exc.getRequest();
if (msg == null) {
return Response.noContent().build();
}
// TODO uses body.toString that doesn't handle different encodings than utf-8
return Response.ok().contentType(MimeType.TEXT_PLAIN_UTF8).body(msg.toString()).build();
}
use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping in project service-proxy by membrane.
the class AdminRESTInterceptor method getClients.
@Mapping("/admin/rest/clients(/?\\?.*)?")
public Response getClients(QueryParameter params, String relativeRootPath) throws Exception {
final List<? extends ClientStatistics> clients = getRouter().getExchangeStore().getClientStatistics();
Collections.sort(clients, ComparatorFactory.getClientStatisticsComparator(params.getString("sort", "name"), params.getString("order", "asc")));
int offset = params.getInt("offset", 0);
int max = params.getInt("max", clients.size());
final int total = clients.size();
final List<? extends ClientStatistics> paginated = clients.subList(offset, Math.min(offset + max, clients.size()));
return json(new JSONContent() {
public void write(JsonGenerator gen) throws Exception {
gen.writeStartObject();
gen.writeArrayFieldStart("clients");
for (ClientStatistics s : paginated) {
gen.writeStartObject();
gen.writeStringField("name", s.getClient());
gen.writeNumberField("count", s.getCount());
gen.writeNumberField("min", s.getMinDuration());
gen.writeNumberField("max", s.getMaxDuration());
gen.writeNumberField("avg", s.getAvgDuration());
gen.writeEndObject();
}
gen.writeEndArray();
gen.writeNumberField("total", total);
gen.writeEndObject();
}
});
}
use of com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping in project service-proxy by membrane.
the class DynamicAdminPageInterceptor method handleProxySaveRequest.
@Mapping("/admin/proxy/save/?(\\?.*)?")
public Response handleProxySaveRequest(Map<String, String> params, String relativeRootPath) throws Exception {
if (readOnly)
return createReadOnlyErrorResponse();
log.debug("adding proxy rule");
log.debug("name: " + params.get("name"));
log.debug("port: " + params.get("port"));
Rule r = new ProxyRule(new ProxyRuleKey(Integer.parseInt(params.get("port")), null));
r.setName(params.get("name"));
router.getRuleManager().addProxyAndOpenPortIfNew(r);
return respond(getProxyPage(params, relativeRootPath));
}
Aggregations