protected void attachPathToProject(String projectPath) throws XmlException, IOException, SoapUIException { project = new WsdlProject( projectPath ); }
@Override public String handleRequest(WsdlOperation operationInst, WsdlRequest request, String[] params) throws SoapUIException { // generate the request content from the schema String requestXML = operationInst.createRequest( true ); // 对 requestContent 进行动态补全 SoapVersion soapVersion = operationInst.getInterface().getSoapVersion(); return SoapuiRequestUtils.buildSoapMessage(requestXML, soapVersion, params); }
public WsdlInterfaceInfo(WsdlInterface wsdlInterface) { this.interfaceName = wsdlInterface.getName(); this.interfaceType = wsdlInterface.getInterfaceType(); this.interfaceDesc = wsdlInterface.getDescription(); this.soapVersion = wsdlInterface.getSoapVersion(); this.adrress = wsdlInterface.getEndpoints(); int operationNum = wsdlInterface.getOperationCount(); List<WsdlOperationInfo> operations = new ArrayList<WsdlOperationInfo>(); for (int i = 0; i < operationNum; i++) { WsdlOperation operation = (WsdlOperation) wsdlInterface.getOperationAt(i); WsdlOperationInfo operationInfo = new WsdlOperationInfo(operation); operations.add(operationInfo); } this.operations = operations; }
public SoapuiResponse<WsdlRequest> invokeAt(String wsdlUrl, int index, boolean async, String[] params, SoapRequestHandler<String[]> requestHandler) throws SoapUIException, SubmitException { // get desired operation WsdlOperation operationInst = wsdlTemplate.getOperationAt(wsdlUrl, index); // create a new empty request for that operation String requestName = "Request" + DigestUtils.md5Hex(wsdlUrl + "$operation-" + index); WsdlRequest request = operationInst.getRequestByName(requestName); if (null == request) { request = operationInst.addNewRequest(requestName); } if (null != requestHandler) { requestHandler.handleRequest(operationInst, request, params); } // MessageExchange exchange = new WsdlResponseMessageExchange(request); // MessageExchange exchange = new RestResponseMessageExchange(request); // MessageExchange exchange = new HttpResponseMessageExchange(request); // generate the request content from the schema String requestXML = arrayParamHandler.handleRequest(operationInst, request, params); request.setRequestContent(requestXML); WsdlSubmitContext context = new WsdlSubmitContext(request); // submit the request WsdlSubmit<WsdlRequest> submit = request.submit(context, async); // wait for the response return new SoapuiResponse<WsdlRequest>(submit.getRequest(), submit.getResponse(), async ? submit.waitUntilFinished() : submit.getStatus(), submit.getError()); }
public WsdlOperationInfo(WsdlOperation operation) { WsdlInterface wsdlInterface = operation.getInterface(); this.operationName = operation.getName(); this.operationDesc = operation.getDescription(); this.operationType = operation.getOperationType(); this.requestXml = operation.createRequest(true); this.responseXml = operation.createResponse(true); this.soapVersion = wsdlInterface.getSoapVersion(); this.soapAction = this.soapVersion.getSoapActionHeader(operation.getAction()); // 处理targetNameSpace this.targetNameSpace = requestXml.substring(requestXml.lastIndexOf("\"http://") + 1, requestXml.lastIndexOf("\">")); if (this.soapVersion.getEnvelopeNamespace().equalsIgnoreCase(Constants.SOAP11_ENVELOPE_NS)) { targetXsd = "11"; } else if (this.soapVersion.getEnvelopeNamespace().equalsIgnoreCase(Constants.SOAP12_ENVELOPE_NS)) { targetXsd = "12"; } try { this.inputNames = Lists.newArrayList(); this.inputTypes = Lists.newArrayList(); SoapuiRequestUtils.extractRequest(this.requestXml, this.soapVersion, this.inputNames, this.inputTypes); } catch (SoapUIException e) { e.printStackTrace(); } }
WsdlOperation wo = wi.getOperationByName(mockOperation.getName()); operation.setInputName(wo.getInputName()); operation.setOutputName(wo.getOutputName()); operation.setDispatcher(wmo.getDispatchStyle()); MockOperationDispatcher dispatcher = wmo.getDispatcher(); if (dispatcher instanceof QueryMatchMockOperationDispatcher){ QueryMatchMockOperationDispatcher qmDispatcher = (QueryMatchMockOperationDispatcher) dispatcher; String query = qmDispatcher.getQueryAt(0).getQuery(); operation.setDispatcherRules(query); String script = sDispatcher.getMockOperation().getScript(); operation.setDispatcherRules(script);
public WsdlInfo(String wsdlUrl) throws SoapUIException { try { this.wsdlUrl = wsdlUrl; // create new project WsdlProject project = new WsdlProject(); WsdlInterface[] wsdlInterfaces = WsdlImporter.importWsdl(project, wsdlUrl); if (null != wsdlInterfaces) { List<WsdlInterfaceInfo> interfaces = new ArrayList<WsdlInterfaceInfo>(); for (WsdlInterface wsdlInterface : wsdlInterfaces) { WsdlInterfaceInfo interfaceInfo = new WsdlInterfaceInfo(wsdlInterface); interfaces.add(interfaceInfo); } this.interfaces = interfaces; } } catch (Exception e) { throw new SoapUIException("Failed to import WSDL '" + wsdlUrl + "'.", e); } }
public WsdlOperation getOperationByName(String wsdlUrl, String operationName) throws SoapUIException { WsdlInterface[] wsdlInterfaces = getWsdlInterfaces(wsdlUrl); WsdlOperation operationInst; for (WsdlInterface wsdlInterface : wsdlInterfaces) { operationInst = wsdlInterface.getOperationByName(operationName); if (operationInst != null) { return operationInst; } } throw new UnsupportedOperationException( "Operation '" + operationName + "' not supported by WSDL '" + wsdlUrl + "'."); }
@Override public List<Service> getServiceDefinitions() throws MockRepositoryImportException { List<Service> result = new ArrayList<>(); // Add Soap and then Rest services definitions. result.addAll(getSoapServiceDefinitions(project.getMockServiceList())); result.addAll(getRestServiceDefinitions(project.getRestMockServiceList())); return result; }
@Override public Map<Request, Response> getMessageDefinitions(Service service, Operation operation) throws MockRepositoryImportException { // First try with a Soap Service mock... MockService mockService = project.getMockServiceByName(service.getName()); if (mockService != null){ try { return getSoapMessageDefinitions(mockService, operation); } catch (XPathExpressionException xpe) { log.error("Got a XPathExpressionException while retrieving soap messages", xpe); throw new MockRepositoryImportException("XPathExpressionExcpetion while retrieving soap messages", xpe); } } // ... then with a Rest Service mock. RestMockService restMockService = project.getRestMockServiceByName(service.getName()); if (restMockService != null){ return getRestMessageDefinitions(restMockService, operation); } return new HashMap<>(); }
public WsdlOperation getOperationAt(String wsdlUrl, int index) throws SoapUIException { WsdlInterface[] wsdlInterfaces = getWsdlInterfaces(wsdlUrl); WsdlOperation operationInst; for (WsdlInterface wsdlInterface : wsdlInterfaces) { operationInst = wsdlInterface.getOperationAt(index); if (operationInst != null) { return operationInst; } } throw new UnsupportedOperationException("Operation not found by WSDL '" + wsdlUrl + "'."); }
public List<Operation> getOperationList(String wsdlUrl) throws SoapUIException { List<Operation> operationList = Lists.newArrayList(); WsdlInterface[] wsdlInterfaces = getWsdlInterfaces(wsdlUrl); for (WsdlInterface wsdlInterface : wsdlInterfaces) { operationList.addAll(wsdlInterface.getOperationList()); } return operationList; }
public Map<String, Operation> getOperations(String wsdlUrl) throws SoapUIException { Map<String, Operation> result = new HashMap<String, Operation>(); WsdlInterface[] wsdlInterfaces = getWsdlInterfaces(wsdlUrl); for (WsdlInterface wsdlInterface : wsdlInterfaces) { result.putAll(wsdlInterface.getOperations()); } return result; }
public SoapuiResponse<WsdlRequest> invokeByName(String wsdlUrl, String operationName, boolean async, Map<String, Object> params, SoapRequestHandler<Map<String, Object>> requestHandler) throws SoapUIException, SubmitException { // get desired operation WsdlOperation operationInst = wsdlTemplate.getOperationByName(wsdlUrl, operationName); // create a new empty request for that operation String requestName = "Request" + DigestUtils.md5Hex(wsdlUrl + "$" + operationName); WsdlRequest request = operationInst.getRequestByName(requestName); if (null == request) { request = operationInst.addNewRequest(requestName); } if (null != requestHandler) { requestHandler.handleRequest(operationInst, request, params); } // generate the request content from the schema String requestXML = mapParamHandler.handleRequest(operationInst, request, params); request.setRequestContent(requestXML); WsdlSubmitContext context = new WsdlSubmitContext(request); // submit the request WsdlSubmit<WsdlRequest> submit = request.submit(context, async); // wait for the response return new SoapuiResponse<WsdlRequest>(submit.getRequest(), submit.getResponse(), async ? submit.waitUntilFinished() : submit.getStatus(), submit.getError()); }
/** * Build a new importer. * @param projectFilePath The path to local SoapUI project file * @throws IOException if project file cannot be found */ public SoapUIProjectImporter(String projectFilePath) throws IOException{ try{ project = new WsdlProject(projectFilePath); } catch (Exception e) { throw new IOException("SoapUI project file"); } }
@Override public String handleRequest(WsdlOperation operationInst, WsdlRequest request, Map<String, Object> params) throws SoapUIException { // generate the request content from the schema String requestXML = operationInst.createRequest( true ); // 对 requestContent 进行动态补全 SoapVersion soapVersion = operationInst.getInterface().getSoapVersion(); return SoapuiRequestUtils.buildSoapMessage(requestXML, soapVersion, params); }
public SoapuiResponse<WsdlRequest> invokeByName(String wsdlUrl, String operationName, boolean async, String[] params, SoapRequestHandler<String[]> requestHandler) throws SoapUIException, SubmitException { // get desired operation WsdlOperation operationInst = wsdlTemplate.getOperationByName(wsdlUrl, operationName); // create a new empty request for that operation String requestName = "Request" + DigestUtils.md5Hex(wsdlUrl + "$" + operationName); WsdlRequest request = operationInst.getRequestByName(requestName); if (null == request) { request = operationInst.addNewRequest(requestName); } if (null != requestHandler) { requestHandler.handleRequest(operationInst, request, params); } // generate the request content from the schema String requestXML = arrayParamHandler.handleRequest(operationInst, request, params); request.setRequestContent(requestXML); // WsdlRequestConfig config = new WsdlRequestConfigImpl(null); // request.setConfig(config); WsdlSubmitContext context = new WsdlSubmitContext(request); // submit the request WsdlSubmit<WsdlRequest> submit = request.submit(context, async); // wait for the response return new SoapuiResponse<WsdlRequest>(submit.getRequest(), submit.getResponse(), async ? submit.waitUntilFinished() : submit.getStatus(), submit.getError()); }
/** * Build a new SoapUITestStepsRunner for a project. * @param projectFilePath The path to SoapUI project file * @throws java.io.IOException if file cannot be found or accessed. */ public SoapUITestStepsRunner(String projectFilePath) throws IOException{ try{ project = new WsdlProject(projectFilePath); } catch (Exception e) { throw new IOException("SoapUI project file cannot be found or accessed"); } }
public SoapuiResponse<WsdlRequest> invokeAt(String wsdlUrl, int index, boolean async, Map<String, Object> params, SoapRequestHandler<Map<String, Object>> requestHandler) throws SoapUIException, SubmitException { // get desired operation WsdlOperation operationInst = wsdlTemplate.getOperationAt(wsdlUrl, index); // create a new empty request for that operation String requestName = "Request" + DigestUtils.md5Hex(wsdlUrl + "$operation-" + index); WsdlRequest request = operationInst.getRequestByName(requestName); if (null == request) { request = operationInst.addNewRequest(requestName); } // MessageExchange exchange = new WsdlResponseMessageExchange(request); // MessageExchange exchange = new RestResponseMessageExchange(request); // MessageExchange exchange = new HttpResponseMessageExchange(request); if (null != requestHandler) { requestHandler.handleRequest(operationInst, request, params); } // generate the request content from the schema String requestXML = mapParamHandler.handleRequest(operationInst, request, params); request.setRequestContent(requestXML); WsdlSubmitContext context = new WsdlSubmitContext(request); // submit the request WsdlSubmit<WsdlRequest> submit = request.submit(context, async); // wait for the response return new SoapuiResponse<WsdlRequest>(submit.getRequest(), submit.getResponse(), async ? submit.waitUntilFinished() : submit.getStatus(), submit.getError()); }
public SoapuiWsdlTemplate() throws SoapUIException, XmlException, IOException { this(new WsdlProject(), new SoapuiProperties()); }