use of com.predic8.wsdl.Operation in project service-proxy by membrane.
the class QuickstartSOAPTest method doit.
@Test
public void doit() throws IOException, InterruptedException {
File baseDir = getExampleDir("quickstart-soap");
Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
try {
ProxiesXmlUtil pxu = new ProxiesXmlUtil(new File(baseDir, "proxies.xml"));
pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + " xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + " xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + " http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + " <router>\r\n" + " \r\n" + " <soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + " <path>/MyBLZService</path>\r\n" + " </soapProxy>\r\n" + " \r\n" + " <serviceProxy port=\"9000\">\r\n" + " <basicAuthentication>\r\n" + " <user name=\"admin\" password=\"membrane\" />\r\n" + " </basicAuthentication> \r\n" + " <adminConsole />\r\n" + " </serviceProxy>\r\n" + " \r\n" + " </router>\r\n" + "</spring:beans>", sl);
String endpoint = "http://localhost:2000/MyBLZService";
String result = getAndAssert200(endpoint + "?wsdl");
assertContains("wsdl:documentation", result);
// assert that rewriting did take place
assertContains("localhost:2000/MyBLZService", result);
result = AssertUtils.postAndAssert200(endpoint, "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:blz=\"http://thomas-bayer.com/blz/\">\r\n" + " <soapenv:Header/>\r\n" + " <soapenv:Body>\r\n" + " <blz:getBank>\r\n" + " <blz:blz>37050198</blz:blz>\r\n" + " </blz:getBank>\r\n" + " </soapenv:Body>\r\n" + "</soapenv:Envelope>");
assertContains("Sparkasse", result);
AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "membrane");
result = getAndAssert200("http://localhost:9000/admin/");
result.contains("BLZService");
String invalidRequest = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:blz=\"http://thomas-bayer.com/blz/\">\r\n" + " <soapenv:Header/>\r\n" + " <soapenv:Body>\r\n" + " <blz:getBank>\r\n" + " <blz:blz>37050198</blz:blz>\r\n" + " <foo />\r\n" + " </blz:getBank>\r\n" + " </soapenv:Body>\r\n" + "</soapenv:Envelope>";
result = postAndAssert(500, endpoint, invalidRequest);
assertContains(".java:", result);
AssertUtils.closeConnections();
AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "membrane");
pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + " xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + " xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + " http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + " <router>\r\n" + " \r\n" + " <soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + " <path>/MyBLZService</path>\r\n" + " <soapStackTraceFilter/>\r\n" + " </soapProxy>\r\n" + " \r\n" + " <serviceProxy port=\"9000\">\r\n" + " <basicAuthentication>\r\n" + " <user name=\"admin\" password=\"membrane\" />\r\n" + " </basicAuthentication> \r\n" + " <adminConsole />\r\n" + " </serviceProxy>\r\n" + " \r\n" + " </router>\r\n" + "</spring:beans>", sl);
result = postAndAssert(500, endpoint, invalidRequest);
assertContainsNot(".java:", result);
AssertUtils.closeConnections();
AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "membrane");
pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + " xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + " xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + " http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + " <router>\r\n" + " \r\n" + " <soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + " <path>/MyBLZService</path>\r\n" + " <soapStackTraceFilter/>\r\n" + " <validator/>\r\n" + " </soapProxy>\r\n" + " \r\n" + " <serviceProxy port=\"9000\">\r\n" + " <basicAuthentication>\r\n" + " <user name=\"admin\" password=\"membrane\" />\r\n" + " </basicAuthentication> \r\n" + " <adminConsole />\r\n" + " </serviceProxy>\r\n" + " \r\n" + " </router>\r\n" + "</spring:beans>", sl);
result = postAndAssert(400, endpoint, invalidRequest);
assertContains("Validation failed", result);
result = getAndAssert200("http://localhost:9000/admin/service-proxy/show?name=BLZService%3A2000");
result.contains("1 of 1 messages have been invalid");
result = getAndAssert200(endpoint);
assertContains("Target Namespace", result);
result = getAndAssert200(endpoint + "/operation/BLZServiceSOAP11Binding/BLZServicePortType/getBank");
assertContains("blz>?XXX?", result);
AssertUtils.closeConnections();
pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + " xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + " xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + " http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + " <router>\r\n" + " \r\n" + " <soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + " <path>/MyBLZService</path>\r\n" + " <soapStackTraceFilter/>\r\n" + " <validator/>\r\n" + " </soapProxy>\r\n" + " \r\n" + " <serviceProxy port=\"9000\">\r\n" + " <basicAuthentication>\r\n" + " <user name=\"admin\" password=\"membrane\" />\r\n" + " </basicAuthentication> \r\n" + " <adminConsole />\r\n" + " </serviceProxy>\r\n" + " \r\n" + " <serviceProxy port=\"2000\">\r\n" + " <index />\r\n" + " </serviceProxy>\r\n" + " \r\n" + " </router>\r\n" + "</spring:beans>", sl);
result = getAndAssert200("http://localhost:2000");
assertContains("/MyBLZService", result);
} finally {
sl.killScript();
}
}
use of com.predic8.wsdl.Operation in project service-proxy by membrane.
the class TestServiceInterceptor method handleOperation.
private Response handleOperation(Element operation, boolean soap11) {
if (!operation.getNamespaceURI().equals("http://thomas-bayer.com/blz/"))
throw new AssertionError("Unknown operation namespace.");
if (operation.getLocalName().equals("getBank")) {
NodeList children = operation.getChildNodes();
Element param = 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() + ".");
param = (Element) children.item(i);
}
if (param == null)
throw new AssertionError("No parameter child of operation element found.");
if (!param.getNamespaceURI().equals("http://thomas-bayer.com/blz/") || !param.getLocalName().equals("blz"))
throw new AssertionError("Unknown parameter element.");
children = param.getChildNodes();
if (children.getLength() != 1)
throw new AssertionError("Parameter element has children.length != 1");
if (!(children.item(0) instanceof Text))
throw new AssertionError("Parameter element has non-text child.");
Text text = (Text) children.item(0);
String blz = text.getNodeValue();
return getBank(blz, soap11);
} else {
throw new AssertionError("Unknown operation.");
}
}
use of com.predic8.wsdl.Operation in project service-proxy by membrane.
the class TestServiceInterceptor method handleSOAP11.
private Response handleSOAP11(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.SOAP11_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, true);
}
use of com.predic8.wsdl.Operation 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.wsdl.Operation 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();
}
}
Aggregations