use of com.predic8.wsdl.Definitions 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.wsdl.Definitions in project service-proxy by membrane.
the class SOAPProxy method parseWSDL.
/**
* @return error or null for success
*/
private void parseWSDL() throws Exception {
WSDLParserContext ctx = new WSDLParserContext();
ctx.setInput(ResolverMap.combine(router.getBaseLocation(), wsdl));
try {
WSDLParser wsdlParser = new WSDLParser();
wsdlParser.setResourceResolver(resolverMap.toExternalResolver().toExternalResolver());
Definitions definitions = wsdlParser.parse(ctx);
List<Service> services = definitions.getServices();
if (services.size() != 1)
throw new IllegalArgumentException("There are " + services.size() + " services defined in the WSDL, but exactly 1 is required for soapProxy.");
Service service = services.get(0);
if (StringUtils.isEmpty(name))
name = StringUtils.isEmpty(service.getName()) ? definitions.getName() : service.getName();
List<Port> ports = service.getPorts();
Port port = selectPort(ports, portName);
String location = port.getAddress().getLocation();
if (location == null)
throw new IllegalArgumentException("In the WSDL, there is no @location defined on the port.");
try {
URL url = new URL(location);
target.setHost(url.getHost());
if (url.getPort() != -1)
target.setPort(url.getPort());
else
target.setPort(url.getDefaultPort());
if (key.getPath() == null) {
key.setUsePathPattern(true);
key.setPathRegExp(false);
key.setPath(url.getPath());
} else {
String query = "";
if (url.getQuery() != null) {
query = "?" + url.getQuery();
}
targetPath = url.getPath() + query;
}
if (location.startsWith("https")) {
SSLParser sslOutboundParser = new SSLParser();
target.setSslParser(sslOutboundParser);
}
((ServiceProxyKey) key).setMethod("*");
} catch (MalformedURLException e) {
throw new IllegalArgumentException("WSDL endpoint location '" + location + "' is not an URL.", e);
}
return;
} catch (Exception e) {
Throwable f = e;
while (f.getCause() != null && !(f instanceof ResourceRetrievalException)) f = f.getCause();
if (f instanceof ResourceRetrievalException) {
ResourceRetrievalException rre = (ResourceRetrievalException) f;
if (rre.getStatus() >= 400)
throw rre;
Throwable cause = rre.getCause();
if (cause != null) {
if (cause instanceof UnknownHostException)
throw (UnknownHostException) cause;
else if (cause instanceof ConnectException)
throw (ConnectException) cause;
}
}
throw new IllegalArgumentException("Could not download the WSDL '" + wsdl + "'.", e);
}
}
use of com.predic8.wsdl.Definitions in project carbon-business-process by wso2.
the class HTRenderingApiImpl method createSoapTemplate.
/**
* Function to create response message template
*
* @param SrcWsdl source wsld : wsdl file path or url
* @param portType callback port type
* @param operation callback operation name
* @param binding callback binding
* @return DOM element of response message template
* @throws IOException If error occurred while parsing string xml to Dom element
* @throws SAXException If error occurred while parsing string xml to Dom element
*/
private static Element createSoapTemplate(String SrcWsdl, String portType, String operation, String binding) throws IOException, SAXException {
WSDLParser parser = new WSDLParser();
// BPS-677
int fileLocationPrefixIndex = SrcWsdl.indexOf(HumanTaskConstants.FILE_LOCATION_FILE_PREFIX);
if (SrcWsdl.indexOf(HumanTaskConstants.FILE_LOCATION_FILE_PREFIX) != -1) {
SrcWsdl = SrcWsdl.substring(fileLocationPrefixIndex + HumanTaskConstants.FILE_LOCATION_FILE_PREFIX.length());
}
Definitions wsdl = parser.parse(SrcWsdl);
StringWriter writer = new StringWriter();
// SOAPRequestCreator constructor: SOARequestCreator(Definitions, Creator, MarkupBuilder)
SOARequestCreator creator = new SOARequestCreator(wsdl, new RequestTemplateCreator(), new MarkupBuilder(writer));
// creator.createRequest(PortType name, Operation name, Binding name);
creator.createRequest(portType, operation, binding);
Element outGenMessageDom = DOMUtils.stringToDOM(writer.toString());
Element outMsgElement = null;
NodeList nodes = outGenMessageDom.getElementsByTagNameNS(outGenMessageDom.getNamespaceURI(), "Body").item(0).getChildNodes();
if (nodes != null) {
for (int i = 0; i < nodes.getLength(); i++) {
if (nodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
outMsgElement = (Element) nodes.item(i);
break;
}
}
}
if (outMsgElement != null) {
// convert element to string and back to element to remove Owner Document
return DOMUtils.stringToDOM(DOMUtils.domToString(outMsgElement));
}
return null;
}
use of com.predic8.wsdl.Definitions in project irontest by zheng-wang.
the class WSDLResource method getWSDLBindings.
@GET
@Path("/{wsdlUrl}/bindings")
public List<WSDLBinding> getWSDLBindings(@PathParam("wsdlUrl") String wsdlUrl) throws UnsupportedEncodingException {
List<WSDLBinding> result = new ArrayList<WSDLBinding>();
WSDLParser parser = new WSDLParser();
parser.setResourceResolver(new SSLTrustedExternalResolver());
Definitions definition = parser.parse(wsdlUrl);
for (Binding binding : definition.getBindings()) {
List<String> operationNames = new ArrayList<String>();
for (BindingOperation operation : binding.getOperations()) {
operationNames.add(operation.getName());
}
result.add(new WSDLBinding(binding.getName(), operationNames));
}
return result;
}
Aggregations