com.predic8.wsdl.Definitions Java Examples
The following examples show how to use
com.predic8.wsdl.Definitions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WSDLResource.java From irontest with Apache License 2.0 | 6 votes |
@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; }
Example #2
Source File: WSDLCustomParser.java From zap-extensions with Apache License 2.0 | 6 votes |
private void parseWSDLFile(File file) { if (file == null) return; try { if (View.isInitialised()) { // Switch to the output panel, if in GUI mode View.getSingleton().getOutputPanel().setTabFocus(); } // WSDL file parsing. WSDLParser parser = new WSDLParser(); final String path = file.getAbsolutePath(); Definitions wsdl = parser.parse(path); parseWSDL(wsdl, true); } catch (ResourceDownloadException rde) { String exMsg = Constant.messages.getString( "soap.topmenu.tools.importWSDL.fail", file.getAbsolutePath()); LOG.warn(exMsg); if (View.isInitialised()) { View.getSingleton().showWarningDialog(exMsg); } } catch (Exception e) { LOG.error(e.getMessage(), e); } }
Example #3
Source File: WSDLCustomParser.java From zap-extensions with Apache License 2.0 | 6 votes |
private boolean parseWSDLContent(String content, boolean sendMessages) { if (content == null || content.trim().length() <= 0) { return false; } else { // WSDL parsing. WSDLParser parser = new WSDLParser(); try { InputStream contentI = new ByteArrayInputStream(content.getBytes("UTF-8")); Definitions wsdl = parser.parse(contentI); contentI.close(); parseWSDL(wsdl, sendMessages); return true; } catch (Exception e) { LOG.error("There was an error while parsing WSDL content. ", e); return false; } } }
Example #4
Source File: ImportWSDLTestCase.java From zap-extensions with Apache License 2.0 | 6 votes |
@BeforeEach public void setUp() throws URIException, NullPointerException { ImportWSDL.destroy(); /* Retrieves singleton instance. */ singleton = ImportWSDL.getInstance(); /* Makes test request. */ testRequest = new HttpMessage(); HttpRequestHeader header = new HttpRequestHeader(); header.setURI(new URI(TEST_URI, true)); testRequest.setRequestHeader(header); HttpRequestBody body = new HttpRequestBody(); body.append("test"); body.setLength(4); testRequest.setRequestBody(body); /* Empty configuration object. */ soapConfig = new SOAPMsgConfig(); soapConfig.setWsdl(new Definitions()); soapConfig.setSoapVersion(1); soapConfig.setParams(new HashMap<String, String>()); soapConfig.setPort(new Port()); soapConfig.setBindOp(new BindingOperation()); }
Example #5
Source File: WSDLResource.java From irontest with Apache License 2.0 | 5 votes |
@GET @Path("/{wsdlUrl}/bindings/{bindingName}/operations/{operationName}") public SOAPOperationInfo getOperationInfo(@PathParam("wsdlUrl") String wsdlUrl, @PathParam("bindingName") String bindingName, @PathParam("operationName") String operationName) { SOAPOperationInfo info = new SOAPOperationInfo(); WSDLParser parser = new WSDLParser(); Definitions definition = parser.parse(wsdlUrl); StringWriter writer = new StringWriter(); SOARequestCreator creator = new SOARequestCreator(definition, new RequestTemplateCreator(), new MarkupBuilder(writer)); creator.createRequest(null, operationName, bindingName); info.setSampleRequest(writer.toString()); return info; }
Example #6
Source File: SOAPMsgConfig.java From zap-extensions with Apache License 2.0 | 5 votes |
public SOAPMsgConfig( Definitions wsdl, int soapVersion, HashMap<String, String> params, Port port, BindingOperation bindOp) { this.setWsdl(wsdl); this.setSoapVersion(soapVersion); this.setParams(params); this.setPort(port); this.setBindOp(bindOp); }
Example #7
Source File: WSDLCustomParser.java From zap-extensions with Apache License 2.0 | 5 votes |
private int detectSoapVersion(Definitions wsdl, String soapPrefix) { String soapNamespace = wsdl.getNamespace(soapPrefix).toString(); if (soapNamespace.trim().equals("http://schemas.xmlsoap.org/wsdl/soap12/")) { return 2; } else { return 1; } }
Example #8
Source File: WSDLCustomParser.java From zap-extensions with Apache License 2.0 | 5 votes |
private List<Part> detectParameters(Definitions wsdl, BindingOperation bindOp) { for (PortType pt : wsdl.getPortTypes()) { for (Operation op : pt.getOperations()) { if (op.getName().trim().equals(bindOp.getName().trim())) { return op.getInput().getMessage().getParts(); } } } return null; }
Example #9
Source File: SOAPMsgConfigTestCase.java From zap-extensions with Apache License 2.0 | 5 votes |
@BeforeEach public void setUp() { /* Empty configuration object. */ soapConfig = new SOAPMsgConfig(); soapConfig.setWsdl(new Definitions()); soapConfig.setSoapVersion(1); soapConfig.setParams(new HashMap<String, String>()); soapConfig.setPort(new Port()); soapConfig.setBindOp(new BindingOperation()); }
Example #10
Source File: SOAPMsgConfigTestCase.java From zap-extensions with Apache License 2.0 | 5 votes |
@Test public void isCompleteTest() { /* Positive case. */ assertTrue(soapConfig.isComplete()); /* Negative cases. */ soapConfig.setWsdl(null); assertFalse(soapConfig.isComplete()); // Null WSDL. soapConfig.setWsdl(new Definitions()); soapConfig.setSoapVersion(0); assertFalse(soapConfig.isComplete()); // SOAP version < 1 soapConfig.setSoapVersion(3); assertFalse(soapConfig.isComplete()); // SOAP version > 2 soapConfig.setSoapVersion(1); soapConfig.setParams(null); assertFalse(soapConfig.isComplete()); // Null params. soapConfig.setParams(new HashMap<String, String>()); soapConfig.setPort(null); assertFalse(soapConfig.isComplete()); // Null port. soapConfig.setPort(new Port()); soapConfig.setBindOp(null); assertFalse(soapConfig.isComplete()); // Null binding operation. soapConfig.setBindOp(new BindingOperation()); }
Example #11
Source File: SOAPMsgConfig.java From zap-extensions with Apache License 2.0 | 4 votes |
public Definitions getWsdl() { return wsdl; }
Example #12
Source File: SOAPMsgConfig.java From zap-extensions with Apache License 2.0 | 4 votes |
public void setWsdl(Definitions wsdl) { this.wsdl = wsdl; }
Example #13
Source File: WSDLCustomParser.java From zap-extensions with Apache License 2.0 | 4 votes |
private void parseWSDL(Definitions wsdl, boolean sendMessages) { StringBuilder sb = new StringBuilder(); List<Service> services = wsdl.getServices(); keyIndex++; /* Endpoint identification. */ for (Service service : services) { for (Port port : service.getPorts()) { Binding binding = port.getBinding(); AbstractBinding innerBinding = binding.getBinding(); String soapPrefix = innerBinding.getPrefix(); int soapVersion = detectSoapVersion( wsdl, soapPrefix); // SOAP 1.X, where X is represented by this // variable. /* If the binding is not a SOAP binding, it is ignored. */ String style = detectStyle(innerBinding); if (style != null && (style.equals("document") || style.equals("rpc"))) { List<BindingOperation> operations = binding.getOperations(); String endpointLocation = port.getAddress().getLocation().toString(); sb.append( "\n|-- Port detected: " + port.getName() + " (" + endpointLocation + ")\n"); /* Identifies operations for each endpoint.. */ for (BindingOperation bindOp : operations) { String opDisplayName = "/" + bindOp.getName() + " (v1." + soapVersion + ")"; sb.append( "|\t|-- SOAP 1." + soapVersion + " Operation: " + bindOp.getName()); /* Adds this operation to the global operations chart. */ recordOperation(keyIndex, bindOp); /* Identifies operation's parameters. */ List<Part> requestParts = detectParameters(wsdl, bindOp); /* Set values to parameters. */ HashMap<String, String> formParams = new HashMap<String, String>(); for (Part part : requestParts) { Element element = part.getElement(); if (element != null) { formParams.putAll(fillParameters(element, null)); } } /* Connection test for each operation. */ /* Basic message creation. */ SOAPMsgConfig soapConfig = new SOAPMsgConfig(wsdl, soapVersion, formParams, port, bindOp); lastConfig = soapConfig; HttpMessage requestMessage = createSoapRequest(soapConfig); if (sendMessages) sendSoapRequest(keyIndex, requestMessage, opDisplayName, sb); } // bindingOperations loop } // Binding check if } // Ports loop } printOutput(sb); }
Example #14
Source File: WSDLCustomParser.java From zap-extensions with Apache License 2.0 | 4 votes |
public HttpMessage createSoapRequest(SOAPMsgConfig soapConfig) { if (soapConfig == null || !soapConfig.isComplete()) return null; /* Retrieving configuration variables. */ Definitions wsdl = soapConfig.getWsdl(); HashMap<String, String> formParams = soapConfig.getParams(); Port port = soapConfig.getPort(); int soapVersion = soapConfig.getSoapVersion(); BindingOperation bindOp = soapConfig.getBindOp(); /* Start message crafting. */ StringWriter writerSOAPReq = new StringWriter(); SOARequestCreator creator = new SOARequestCreator(wsdl, new RequestCreator(), new MarkupBuilder(writerSOAPReq)); creator.setBuilder(new MarkupBuilder(writerSOAPReq)); creator.setDefinitions(wsdl); creator.setFormParams(formParams); creator.setCreator(new RequestCreator()); try { Binding binding = port.getBinding(); creator.createRequest( binding.getPortType().getName(), bindOp.getName(), binding.getName()); // LOG.info("[ExtensionImportWSDL] "+writerSOAPReq); /* HTTP Request. */ String endpointLocation = port.getAddress().getLocation().toString(); HttpMessage httpRequest = new HttpMessage(new URI(endpointLocation, false)); /* Body. */ HttpRequestBody httpReqBody = httpRequest.getRequestBody(); /* [MARK] Not sure if all servers would handle this encoding type. */ httpReqBody.append( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n" + writerSOAPReq.getBuffer().toString()); httpRequest.setRequestBody(httpReqBody); /* Header. */ HttpRequestHeader httpReqHeader = httpRequest.getRequestHeader(); httpReqHeader.setMethod("POST"); /* Sets headers according to SOAP version. */ if (soapVersion == 1) { httpReqHeader.setHeader(HttpHeader.CONTENT_TYPE, "text/xml; charset=UTF-8"); httpReqHeader.setHeader("SOAPAction", bindOp.getOperation().getSoapAction()); } else if (soapVersion == 2) { String contentType = "application/soap+xml; charset=UTF-8"; String action = bindOp.getOperation().getSoapAction(); if (!action.trim().equals("")) contentType += "; action=" + action; httpReqHeader.setHeader(HttpHeader.CONTENT_TYPE, contentType); } httpReqHeader.setContentLength(httpReqBody.length()); httpRequest.setRequestHeader(httpReqHeader); /* Saves the message and its configuration. */ wsdlSingleton.putConfiguration(httpRequest, soapConfig); return httpRequest; } catch (Exception e) { LOG.error( "Unable to generate request for operation '" + bindOp.getName() + "'\n" + e.getMessage(), e); return null; } }