use of com.predic8.membrane.core.http.Response in project service-proxy by membrane.
the class ParameterizedRequest method validateRequest.
public Response validateRequest() throws Exception {
Response resp;
resp = checkForMissingParameters();
if (resp.getClass() != NoResponse.class)
return resp;
resp = processWithParameters();
if (resp.getClass() != NoResponse.class)
return resp;
return getResponse();
}
use of com.predic8.membrane.core.http.Response in project service-proxy by membrane.
the class WebServiceExplorerInterceptor method createOperationResponse.
@Mapping("[^?]*/operation/([^/?]+)/([^/?]+)/([^/?]+)")
public Response createOperationResponse(QueryParameter params, String relativeRootPath) throws Exception {
try {
final String bindingName = params.getGroup(1);
final String portName = params.getGroup(2);
final String operationName = params.getGroup(3);
final Definitions w = getParsedWSDL();
final Service service = getService(w);
StringWriter sw = new StringWriter();
new StandardPage(sw, null) {
@Override
protected void createContent() {
h1().text("Service Proxy for " + service.getName());
h2().text("Operation: " + operationName).end();
h3().text("Sample Request").end();
pre().text(generateSampleRequest(portName, operationName, bindingName, w)).end();
}
};
return Response.ok(sw.toString()).build();
} catch (IllegalArgumentException e) {
log.error("", e);
return Response.internalServerError().build();
}
}
use of com.predic8.membrane.core.http.Response 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.http.Response in project service-proxy by membrane.
the class TestServiceInterceptor method handleSOAP12.
private Response handleSOAP12(Element envelope) {
Element body = null;
NodeList children = envelope.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i) instanceof Text) {
String text = ((Text) children.item(i)).getNodeValue();
for (int j = 0; j < text.length(); j++) if (!Character.isWhitespace(text.charAt(j)))
throw new AssertionError("Found non-whitespace text.");
continue;
}
if (!(children.item(i) instanceof Element))
throw new AssertionError("Non-element child of <Envelope> found: " + children.item(i).getNodeName() + ".");
Element item = (Element) children.item(i);
if (!item.getNamespaceURI().equals(Constants.SOAP12_NS))
throw new AssertionError("Non-SOAP child element of <Envelope> found.");
if (item.getLocalName().equals("Body"))
body = item;
}
if (body == null)
throw new AssertionError("No SOAP <Body> found.");
children = body.getChildNodes();
Element operation = null;
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i) instanceof Text) {
String text = ((Text) children.item(i)).getNodeValue();
for (int j = 0; j < text.length(); j++) if (!Character.isWhitespace(text.charAt(j)))
throw new AssertionError("Found non-whitespace text.");
continue;
}
if (!(children.item(i) instanceof Element))
throw new AssertionError("Non-element child of <Body> found: " + children.item(i).getNodeName() + ".");
operation = (Element) children.item(i);
}
if (operation == null)
throw new AssertionError("No SOAP <Body> found.");
return handleOperation(operation, false);
}
use of com.predic8.membrane.core.http.Response in project service-proxy by membrane.
the class SOAP2RESTInterceptor method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
// save SOAP operationName and namespace in exchange properties to generically construct response name
soe.handleRequest(exc);
// apply request XSLT
transformAndReplaceBody(exc.getRequest(), requestXSLT, new StreamSource(exc.getRequest().getBodyAsStreamDecoded()), exc.getStringProperties());
// fill Request object from HTTP-XML
Header header = exc.getRequest().getHeader();
header.removeFields(Header.CONTENT_TYPE);
header.setContentType(MimeType.TEXT_XML_UTF8);
XML2HTTP.unwrapMessageIfNecessary(exc.getRequest());
// reset exchange destination to new request URI
exc.getDestinations().clear();
di.handleRequest(exc);
return Outcome.CONTINUE;
}
Aggregations