Best Citrus code snippet using com.consol.citrus.xml.schema.WsdlXsdSchema.getWsdlDefinition
Source:WsdlXsdSchema.java
...79 public Resource loadSchemaResources() {80 Assert.notNull(wsdl, "wsdl file resource is required");81 Assert.isTrue(wsdl.exists(), "wsdl file resource '" + wsdl + " does not exist");82 try {83 return loadSchemas(getWsdlDefinition(wsdl));84 } catch (Exception e) {85 throw new BeanCreationException("Failed to load schema types from WSDL file", e);86 }87 }88 /**89 * Loads nested schema type definitions from wsdl.90 * @throws IOException91 * @throws WSDLException92 * @throws TransformerFactoryConfigurationError93 * @throws TransformerException94 */95 private Resource loadSchemas(Definition definition) throws WSDLException, IOException, TransformerException, TransformerFactoryConfigurationError {96 Types types = definition.getTypes();97 Resource targetXsd = null;98 Resource firstSchemaInWSDL = null;99 if (types != null) {100 List<?> schemaTypes = types.getExtensibilityElements();101 for (Object schemaObject : schemaTypes) {102 if (schemaObject instanceof SchemaImpl) {103 SchemaImpl schema = (SchemaImpl) schemaObject;104 inheritNamespaces(schema, definition);105 addImportedSchemas(schema);106 addIncludedSchemas(schema);107 if (!importedSchemas.contains(getTargetNamespace(schema))) {108 ByteArrayOutputStream bos = new ByteArrayOutputStream();109 Source source = new DOMSource(schema.getElement());110 Result result = new StreamResult(bos);111 TransformerFactory.newInstance().newTransformer().transform(source, result);112 Resource schemaResource = new ByteArrayResource(bos.toByteArray());113 importedSchemas.add(getTargetNamespace(schema));114 schemaResources.add(schemaResource);115 if (definition.getTargetNamespace().equals(getTargetNamespace(schema)) && targetXsd == null) {116 targetXsd = schemaResource;117 } else if (targetXsd == null && firstSchemaInWSDL == null) {118 firstSchemaInWSDL = schemaResource;119 }120 }121 } else {122 LOG.warn("Found unsupported schema type implementation " + schemaObject.getClass());123 }124 }125 }126 for (Object imports : definition.getImports().values()) {127 for (Import wsdlImport : (Vector<Import>)imports) {128 String schemaLocation;129 URI locationURI = URI.create(wsdlImport.getLocationURI());130 if (locationURI.isAbsolute()) {131 schemaLocation = wsdlImport.getLocationURI();132 } else {133 schemaLocation = definition.getDocumentBaseURI().substring(0, definition.getDocumentBaseURI().lastIndexOf('/') + 1) + wsdlImport.getLocationURI();134 }135 if (schemaLocation.startsWith("jar:")) {136 loadSchemas(getWsdlDefinition(new UrlResource(schemaLocation)));137 } else {138 loadSchemas(getWsdlDefinition(new FileSystemResource(schemaLocation)));139 }140 }141 }142 if (targetXsd == null) {143 // Obviously no schema resource in WSDL did match the targetNamespace, just use the first schema resource found as main schema144 if (firstSchemaInWSDL != null) {145 targetXsd = firstSchemaInWSDL;146 } else if (!CollectionUtils.isEmpty(schemaResources)) {147 targetXsd = schemaResources.get(0);148 }149 }150 return targetXsd;151 }152 /**153 * Adds WSDL level namespaces to schema definition if necessary.154 * @param schema155 * @param wsdl156 */157 @SuppressWarnings("unchecked")158 private void inheritNamespaces(SchemaImpl schema, Definition wsdl) {159 Map<String, String> wsdlNamespaces = wsdl.getNamespaces();160 for (Entry<String, String> nsEntry: wsdlNamespaces.entrySet()) {161 if (StringUtils.hasText(nsEntry.getKey())) {162 if (!schema.getElement().hasAttributeNS(AbstractSchemaCollection.WWW_W3_ORG_2000_XMLNS, nsEntry.getKey())) {163 schema.getElement().setAttributeNS(AbstractSchemaCollection.WWW_W3_ORG_2000_XMLNS, "xmlns:" + nsEntry.getKey(), nsEntry.getValue());164 }165 } else { // handle default namespace166 if (!schema.getElement().hasAttribute("xmlns")) {167 schema.getElement().setAttributeNS(AbstractSchemaCollection.WWW_W3_ORG_2000_XMLNS, "xmlns" + nsEntry.getKey(), nsEntry.getValue());168 }169 }170 }171 }172 /**173 * Reads WSDL definition from resource.174 * @param wsdl175 * @return176 * @throws IOException177 * @throws WSDLException178 */179 private Definition getWsdlDefinition(Resource wsdl) {180 try {181 Definition definition;182 if (wsdl.getURI().toString().startsWith("jar:")) {183 // Locate WSDL imports in Jar files184 definition = WSDLFactory.newInstance().newWSDLReader().readWSDL(new JarWSDLLocator(wsdl));185 } else {186 definition = WSDLFactory.newInstance().newWSDLReader().readWSDL(wsdl.getURI().getPath(), new InputSource(wsdl.getInputStream()));187 }188 return definition;189 } catch (IOException e) {190 throw new CitrusRuntimeException("Failed to read wsdl file resource", e);191 } catch (WSDLException e) {192 throw new CitrusRuntimeException("Failed to wsdl schema instance", e);193 }...
getWsdlDefinition
Using AI Code Generation
1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4import com.consol.citrus.ws.client.WebServiceClient;5import com.consol.citrus.ws.server.WebServiceServer;6import org.springframework.beans.factory.annotation.Autowired;7import org.springframework.core.io.ClassPathResource;8import org.springframework.ws.soap.SoapVersion;9import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;10import org.testng.annotations.Test;11public class WsdlXsdSchemaIT extends TestNGCitrusTestRunner {12 private WebServiceClient webServiceClient;13 private WebServiceServer webServiceServer;14 public void testWsdlXsdSchema() {15 variable("messageId", "citrus:randomUUID()");16 variable("timestamp", "citrus:currentDate('yyyy-MM-dd')");17 variable("sender", "citrus:concat('citrus:currentDate(''yyyy-MM-dd'')', 'T', 'citrus:currentDate(''HH:mm:ss'')', 'Z')");18 webServiceServer(autoStart = true)19 .receive()20 "<MessageId>${messageId}</MessageId>" +21 "<Timestamp>${timestamp}</Timestamp>" +22 "<Sender>${sender}</Sender>" +23 "</ns0:echoRequest>");24 webServiceClient()25 .send()26 .soap()27 .version(SoapVersion.SOAP_12)28 "<MessageId>${messageId}</MessageId>" +29 "<Timestamp>${timestamp}</Timestamp>" +30 "<Sender>${sender}</Sender>" +31 "</ns0:echoRequest>");32 webServiceClient()33 .receive()34 .soap()35 .version(SoapVersion.SOAP_12)
getWsdlDefinition
Using AI Code Generation
1WsdlXsdSchema schema = new WsdlXsdSchema();2schema.setSchemaRepository("classpath:com/consol/citrus/wsdl");3schema.setWsdlDefinition("classpath:com/consol/citrus/wsdl/HelloService.wsdl");4WsdlXsdSchema schema = new WsdlXsdSchema();5schema.setSchemaRepository("classpath:com/consol/citrus/wsdl");6schema.setWsdlDefinition("classpath:com/consol/citrus/wsdl/HelloService.wsdl");7schema.setSchemaName("HelloService");8WsdlXsdSchema schema = new WsdlXsdSchema();9schema.setSchemaRepository("classpath:com/consol/citrus/wsdl");10schema.setWsdlDefinition("classpath:com/consol/citrus/wsdl/HelloService.wsdl");11schema.setSchemaName("HelloService");12schema.setSchemaType(SchemaType.WSDL);13WsdlXsdSchema schema = new WsdlXsdSchema();14schema.setSchemaRepository("classpath:com/consol/citrus/wsdl");15schema.setWsdlDefinition("classpath:com/consol/citrus/wsdl/HelloService.wsdl");16schema.setSchemaType(SchemaType.WSDL);17WsdlXsdSchema schema = new WsdlXsdSchema();18schema.setSchemaRepository("classpath:com/consol/citrus/wsdl");19schema.setWsdlDefinition("classpath:com/consol/citrus/wsdl/HelloService.wsdl");20schema.setSchemaType(SchemaType.WSDL);21schema.setSchemaVersion("1.0");
getWsdlDefinition
Using AI Code Generation
1WsdlXsdSchema schema = new WsdlXsdSchema("classpath:com/consol/citrus/wsdl/HelloService.wsdl");2String wsdlDefinition = schema.getWsdlDefinition();3System.out.println(wsdlDefinition);4XsdSchema schema = new XsdSchema("classpath:com/consol/citrus/wsdl/HelloService.xsd");5String wsdlDefinition = schema.getWsdlDefinition();6System.out.println(wsdlDefinition);7XsdSchema schema = new XsdSchema("classpath:com/consol/citrus/wsdl/HelloService.xsd");8String wsdlDefinition = schema.getWsdlDefinition();9System.out.println(wsdlDefinition);10XsdSchema schema = new XsdSchema("classpath:com/consol/citrus/wsdl/HelloService.xsd");11String wsdlDefinition = schema.getWsdlDefinition();12System.out.println(wsdlDefinition);13XsdSchema schema = new XsdSchema("classpath:com/consol/citrus/wsdl/HelloService.xsd");14String wsdlDefinition = schema.getWsdlDefinition();15System.out.println(wsdlDefinition);16XsdSchema schema = new XsdSchema("classpath:com/consol/citrus/wsdl/HelloService.xsd");17String wsdlDefinition = schema.getWsdlDefinition();18System.out.println(wsdlDefinition);19XsdSchema schema = new XsdSchema("classpath:com/consol/citrus/wsdl/HelloService.xsd");20String wsdlDefinition = schema.getWsdlDefinition();21System.out.println(wsdlDefinition);22XsdSchema schema = new XsdSchema("classpath:com/consol/c
getWsdlDefinition
Using AI Code Generation
1WsdlXsdSchema schema = new WsdlXsdSchema();2schema.setSchemaValidation(true);3schema.setSchemaValidationEventHandler(new DefaultValidationEventHandler());4schema.initialize();5WsdlXsdSchema schema = new WsdlXsdSchema();6schema.setSchemaValidation(true);7schema.setSchemaValidationEventHandler(new DefaultValidationEventHandler());8schema.initialize();9WsdlXsdSchema schema = new WsdlXsdSchema();10schema.setSchemaValidation(true);11schema.setSchemaValidationEventHandler(new DefaultValidationEventHandler());12schema.initialize();13WsdlXsdSchema schema = new WsdlXsdSchema();14schema.setSchemaValidation(true);15schema.setSchemaValidationEventHandler(new DefaultValidationEventHandler());16schema.initialize();17WsdlXsdSchema schema = new WsdlXsdSchema();18schema.setSchemaValidation(true);19schema.setSchemaValidationEventHandler(new DefaultValidationEventHandler());20schema.initialize();21WsdlXsdSchema schema = new WsdlXsdSchema();
getWsdlDefinition
Using AI Code Generation
1WsdlXsdSchema schema = new WsdlXsdSchema();2schema.setSchemaRepository(new ClassPathSchemaRepository("wsdl/"));3schema.setSchemaName("MyService.wsdl");4Definition definition = schema.getWsdlDefinition();5Map<QName, Service> services = definition.getServices();6QName serviceQName = services.keySet().iterator().next();7Service service = definition.getService(serviceQName);8Map<QName, Port> ports = service.getPorts();9QName portQName = ports.keySet().iterator().next();10Port port = service.getPort(portQName);11QName bindingQName = port.getBinding().getQName();12Binding binding = definition.getBinding(bindingQName);13BindingOperation bindingOperation = binding.getBindingOperation("MyOperation", null, null);14BindingInput bindingInput = bindingOperation.getBindingInput();15List<ExtensibilityElement> elements = bindingInput.getExtensibilityElements();16SOAPBody soapBody = (SOAPBody) elements.get(0);17List parts = soapBody.getParts();18System.out.println("Parts: " + parts);
getWsdlDefinition
Using AI Code Generation
1 public void test() {2 description("Test to call the SOAP webservice");3 http()4 .client("httpClient")5 .send()6 .header("Content-Type", "text/xml")7 .payload(new ClassPathResource("request.xml"));8 http()9 .client("httpClient")10 .receive()11 .response(HttpStatus.OK)12 .payload(new ClassPathResource("response.xml"));13 WsdlXsdSchema schema = new WsdlXsdSchema();14 schema.setWsdlDefinition(getWsdlDefinition());15 echo("Schema: ${schema.toString()}");16 soap()17 .client("soapClient")18 .send()19 .schemaValidation(true)20 .schema(schema);21 soap()22 .client("soapClient")23 .receive()24 .response(HttpStatus.OK)25 .schemaValidation(true)26 .schema(schema);27 }28 public WsdlDefinition getWsdlDefinition() {29 WsdlDefinition wsdlDefinition = new WsdlDefinition();30 wsdlDefinition.setWsdl(getWsdlResource());31 wsdlDefinition.setSchema(getSchemaResource());32 return wsdlDefinition;33 }34 public Resource getWsdlResource() {35 return new ClassPathResource("soapws.wsdl");36 }37 public Resource getSchemaResource() {38 return new ClassPathResource("soapws.xsd");39 }
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!