How to use JarWSDLLocator class of com.consol.citrus.xml.schema.locator package

Best Citrus code snippet using com.consol.citrus.xml.schema.locator.JarWSDLLocator

Source:WsdlXsdSchema.java Github

copy

Full Screen

...14 * limitations under the License.15 */16package com.consol.citrus.xml.schema;17import com.consol.citrus.exceptions.CitrusRuntimeException;18import com.consol.citrus.xml.schema.locator.JarWSDLLocator;19import com.ibm.wsdl.extensions.schema.SchemaImpl;20import org.slf4j.Logger;21import org.slf4j.LoggerFactory;22import org.springframework.beans.factory.BeanCreationException;23import org.springframework.core.io.*;24import org.springframework.util.*;25import org.xml.sax.InputSource;26import javax.wsdl.*;27import javax.wsdl.extensions.schema.Schema;28import javax.wsdl.factory.WSDLFactory;29import javax.xml.transform.*;30import javax.xml.transform.dom.DOMSource;31import javax.xml.transform.stream.StreamResult;32import java.io.ByteArrayOutputStream;33import java.io.IOException;34import java.net.URI;35import java.util.*;36import java.util.Map.Entry;37/**38 * Wrapper implementation takes care of nested WSDL schema types. Exposes those WSDL schema types as39 * xsd schema instances for schema repository. WSDL may contain several schema types which get40 * exposed under a single target namespace (defined on WSDL level).41 * 42 * @author Christoph Deppisch43 * @since 1.344 */45public class WsdlXsdSchema extends AbstractSchemaCollection {46 /** WSDL file resource */47 private Resource wsdl;48 /** Logger */49 private static Logger log = LoggerFactory.getLogger(WsdlXsdSchema.class);50 /**51 * Default constructor52 */53 public WsdlXsdSchema() {54 super();55 }56 57 /**58 * Constructor using wsdl resource.59 * @param wsdl60 */61 public WsdlXsdSchema(Resource wsdl) {62 super();63 this.wsdl = wsdl;64 }65 @Override66 public Resource loadSchemaResources() {67 Assert.notNull(wsdl, "wsdl file resource is required");68 Assert.isTrue(wsdl.exists(), "wsdl file resource '" + wsdl + " does not exist");69 try {70 return loadSchemas(getWsdlDefinition(wsdl));71 } catch (Exception e) {72 throw new BeanCreationException("Failed to load schema types from WSDL file", e);73 }74 }75 /**76 * Loads nested schema type definitions from wsdl.77 * @throws IOException 78 * @throws WSDLException 79 * @throws TransformerFactoryConfigurationError80 * @throws TransformerException81 */82 private Resource loadSchemas(Definition definition) throws WSDLException, IOException, TransformerException, TransformerFactoryConfigurationError {83 Types types = definition.getTypes();84 Resource targetXsd = null;85 Resource firstSchemaInWSDL = null;86 if (types != null) {87 List<?> schemaTypes = types.getExtensibilityElements();88 for (Object schemaObject : schemaTypes) {89 if (schemaObject instanceof SchemaImpl) {90 SchemaImpl schema = (SchemaImpl) schemaObject;91 inheritNamespaces(schema, definition);92 addImportedSchemas(schema);93 addIncludedSchemas(schema);94 if (!importedSchemas.contains(getTargetNamespace(schema))) {95 ByteArrayOutputStream bos = new ByteArrayOutputStream();96 Source source = new DOMSource(schema.getElement());97 Result result = new StreamResult(bos);98 TransformerFactory.newInstance().newTransformer().transform(source, result);99 Resource schemaResource = new ByteArrayResource(bos.toByteArray());100 importedSchemas.add(getTargetNamespace(schema));101 schemaResources.add(schemaResource);102 if (definition.getTargetNamespace().equals(getTargetNamespace(schema)) && targetXsd == null) {103 targetXsd = schemaResource;104 } else if (targetXsd == null && firstSchemaInWSDL == null) {105 firstSchemaInWSDL = schemaResource;106 }107 }108 } else {109 log.warn("Found unsupported schema type implementation " + schemaObject.getClass());110 }111 }112 }113 for (Object imports : definition.getImports().values()) {114 for (Import wsdlImport : (Vector<Import>)imports) {115 String schemaLocation;116 URI locationURI = URI.create(wsdlImport.getLocationURI());117 if (locationURI.isAbsolute()) {118 schemaLocation = wsdlImport.getLocationURI();119 } else {120 schemaLocation = definition.getDocumentBaseURI().substring(0, definition.getDocumentBaseURI().lastIndexOf('/') + 1) + wsdlImport.getLocationURI();121 }122 loadSchemas(getWsdlDefinition(new FileSystemResource(schemaLocation)));123 }124 }125 if (targetXsd == null) {126 // Obviously no schema resource in WSDL did match the targetNamespace, just use the first schema resource found as main schema127 if (firstSchemaInWSDL != null) {128 targetXsd = firstSchemaInWSDL;129 } else if (!CollectionUtils.isEmpty(schemaResources)) {130 targetXsd = schemaResources.get(0);131 }132 }133 return targetXsd;134 }135 /**136 * Adds WSDL level namespaces to schema definition if necessary.137 * @param schema138 * @param wsdl139 */140 @SuppressWarnings("unchecked")141 private void inheritNamespaces(SchemaImpl schema, Definition wsdl) {142 Map<String, String> wsdlNamespaces = wsdl.getNamespaces();143 144 for (Entry<String, String> nsEntry: wsdlNamespaces.entrySet()) {145 if (StringUtils.hasText(nsEntry.getKey())) {146 if (!schema.getElement().hasAttributeNS(WWW_W3_ORG_2000_XMLNS, nsEntry.getKey())) {147 schema.getElement().setAttributeNS(WWW_W3_ORG_2000_XMLNS, "xmlns:" + nsEntry.getKey(), nsEntry.getValue());148 }149 } else { // handle default namespace150 if (!schema.getElement().hasAttribute("xmlns")) {151 schema.getElement().setAttributeNS(WWW_W3_ORG_2000_XMLNS, "xmlns" + nsEntry.getKey(), nsEntry.getValue());152 }153 }154 }155 }156 /**157 * Reads WSDL definition from resource.158 * @param wsdl159 * @return160 * @throws IOException161 * @throws WSDLException162 */163 private Definition getWsdlDefinition(Resource wsdl) {164 try {165 Definition definition;166 if (wsdl.getURI().toString().startsWith("jar:")) {167 // Locate WSDL imports in Jar files168 definition = WSDLFactory.newInstance().newWSDLReader().readWSDL(new JarWSDLLocator(wsdl));169 } else {170 definition = WSDLFactory.newInstance().newWSDLReader().readWSDL(wsdl.getURI().getPath(), new InputSource(wsdl.getInputStream()));171 }172 return definition;173 } catch (IOException e) {174 throw new CitrusRuntimeException("Failed to read wsdl file resource", e);175 } catch (WSDLException e) {176 throw new CitrusRuntimeException("Failed to wsdl schema instance", e);177 }178 }179 /**180 * Reads target namespace from schema definition element.181 * @param schema182 * @return...

Full Screen

Full Screen

Source:JarWSDLLocatorTest.java Github

copy

Full Screen

...17import org.springframework.core.io.ClassPathResource;18import org.springframework.core.io.Resource;19import org.testng.Assert;20import org.testng.annotations.Test;21public class JarWSDLLocatorTest {22 private Resource wsdl = new ClassPathResource("com/consol/citrus/validation/SampleService.wsdl");23 @Test24 public void testGetImportInputSource() throws Exception {25 JarWSDLLocator locator = new JarWSDLLocator(wsdl);26 Assert.assertNotNull(locator.getBaseInputSource());27 Assert.assertNotNull(locator.getBaseURI());28 Assert.assertTrue(locator.getBaseURI().endsWith("com/consol/citrus/validation/SampleService.wsdl"));29 Assert.assertNull(locator.getLatestImportURI());30 Assert.assertNull(locator.getImportInputSource(locator.getBaseURI(), "invalid.xsd"));31 Assert.assertTrue(locator.getLatestImportURI().endsWith("com/consol/citrus/validation/invalid.xsd"));32 Assert.assertNotNull(locator.getImportInputSource(locator.getBaseURI(), "types.xsd"));33 Assert.assertTrue(locator.getLatestImportURI().endsWith("com/consol/citrus/validation/types.xsd"));34 }35}...

Full Screen

Full Screen

JarWSDLLocator

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.xml.schema.locator;2import java.io.File;3import java.io.IOException;4import java.net.MalformedURLException;5import java.net.URI;6import java.net.URISyntaxException;7import java.net.URL;8import org.apache.commons.logging.Log;9import org.apache.commons.logging.LogFactory;10import org.springframework.core.io.Resource;11import org.springframework.core.io.support.PathMatchingResourcePatternResolver;12import org.springframework.core.io.support.ResourcePatternResolver;13import org.springframework.util.Assert;14public class JarWSDLLocator extends WSDLLocator {15 private static Log log = LogFactory.getLog(JarWSDLLocator.class);16 private static ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();17 private URI baseURI;18 private Resource resource;19 private URL resourceURL;20 public JarWSDLLocator() {21 super();22 }23 public JarWSDLLocator(URI baseURI, URL resourceURL) {24 super();25 this.baseURI = baseURI;26 this.resourceURL = resourceURL;27 }28 public JarWSDLLocator(String baseURI, String resourceURL) {29 super();30 try {31 this.baseURI = new URI(baseURI);32 this.resourceURL = new URL(resourceURL);33 } catch (URISyntaxException e) {34 throw new RuntimeException(e);35 } catch (MalformedURLException e) {36 throw new RuntimeException(e);37 }38 }39 * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)40 public InputSource resolveEntity(String publicId, String systemId) {41 try {42 if (resourceURL != null) {43 log.debug("Resolving entity using resource URL: " + resourceURL);44 return new InputSource(resourceURL.openStream());45 } else if (baseURI != null) {46 log.debug("Resolving entity using base URI: " + baseURI);47 return new InputSource(new URL(baseURI.resolve(systemId).toString()).openStream());48 } else if

Full Screen

Full Screen

JarWSDLLocator

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.xml.schema.locator.JarWSDLLocator;2import com.consol.citrus.xml.schema.locator.WSDLLocator;3import com.consol.citrus.xml.schema.locator.WSDLLocatorFactory;4import com.consol.citrus.xml.schema.locator.WSDLLocatorStrategy;5public class WSDLLocatorFactory {6 public static WSDLLocator getWSDLLocator(String wsdlLocation, String wsdlUrl) {7 if (wsdlLocation.startsWith("classpath:") || wsdlLocation.startsWith("file:")) {8 return new ClassPathWSDLLocator(wsdlLocation, wsdlUrl);9 } else if (wsdlLocation.startsWith("jar:")) {10 return new JarWSDLLocator(wsdlLocation, wsdlUrl);11 } else {12 throw new CitrusRuntimeException("Unsupported WSDL locator strategy for location: " + wsdlLocation);13 }14 }15}16import com.consol.citrus.xml.schema.locator.WSDLLocator;17import com.consol.citrus.xml.schema.locator.WSDLLocatorStrategy;18import org.slf4j.Logger;19import org.slf4j.LoggerFactory;20import org.springframework.core.io.Resource;21import org.springframework.util.StringUtils;22import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;23import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition;24import java.io.IOException;25import java.net.URL;26public class JarWSDLLocator implements WSDLLocator {27 private static Logger log = LoggerFactory.getLogger(JarWSDLLocator.class);28 private String wsdlLocation;29 private String wsdlUrl;30 public JarWSDLLocator(String wsdlLocation, String wsdlUrl) {31 this.wsdlLocation = wsdlLocation;32 this.wsdlUrl = wsdlUrl;33 }34 public Resource getWSDLResource()

Full Screen

Full Screen

JarWSDLLocator

Using AI Code Generation

copy

Full Screen

1public class JarWSDLLocatorTest {2 public static void main(String[] args) {3 JarWSDLLocator locator = new JarWSDLLocator("com.consol.citrus.samples.wsdl", "HelloService.wsdl");4 try {5 locator.getBaseInputSource();6 } catch (IOException e) {7 e.printStackTrace();8 }9 }10}

Full Screen

Full Screen

JarWSDLLocator

Using AI Code Generation

copy

Full Screen

1public class JarWSDLLocatorTest {2 public static void main(String[] args) throws Exception {3 JarWSDLLocator locator = new JarWSDLLocator("wsdl/HelloWorld.wsdl");4 WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();5 reader.setFeature("javax.wsdl.verbose", true);6 reader.setFeature("javax.wsdl.importDocuments", true);7 reader.setFeature("javax.wsdl.extensions.soap", true);8 reader.setFeature("javax.wsdl.extensions.soap12", true);9 reader.setFeature("javax.wsdl.extensions.mime", true);10 reader.setFeature("javax.wsdl.extensions.http", true);11 reader.setFeature("javax.wsdl.extensions.schema", true);12 reader.setFeature("javax.wsdl.extensions.schema.importDocuments", true);

Full Screen

Full Screen

JarWSDLLocator

Using AI Code Generation

copy

Full Screen

1import org.springframework.context.support.ClassPathXmlApplicationContext;2public class 4 {3 public static void main(String[] args) {4 ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:4.xml");5 ctx.start();6 }7}8package com.consol.citrus.ws;9import org.springframework.context.support.ClassPathXmlApplicationContext;

Full Screen

Full Screen

JarWSDLLocator

Using AI Code Generation

copy

Full Screen

1public class JarWSDLLocatorTest {2 public static void main(String[] args) {3 jarWSDLLocator.setClassLoader(JarWSDLLocatorTest.class.getClassLoader());4 WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();5 reader.setFeature("javax.wsdl.verbose", true);6 reader.setFeature("javax.wsdl.importDocuments", true);7 reader.setFeature("javax.wsdl.extensions.soap", true);8 reader.setFeature("javax.wsdl.extensions.mime", true);9 reader.setFeature("javax.wsdl.extensions.schema", true);10 reader.setExtensionRegistry(ExtensionRegistry.newInstance());11 reader.setFeature("javax.wsdl.extensions.soap12", true);12 Definition definition = reader.readWSDL(jarWSDLLocator);13 System.out.println(definition);14 }15}

Full Screen

Full Screen

JarWSDLLocator

Using AI Code Generation

copy

Full Screen

1public class JarWSDLLocatorTest {2 public static void main(String[] args) {3 System.out.println(locator.getBaseInputSource().getSystemId());4 System.out.println(locator.getBaseInputSource().getByteStream());5 }6}7import com.consol.citrus.xml.schema

Full Screen

Full Screen

JarWSDLLocator

Using AI Code Generation

copy

Full Screen

1public class JarWSDLLocatorTest extends TestCase {2 private JarWSDLLocator locator;3 private String wsdlURL = "jar:file:/C:/Users/krishna/Desktop/Citrus-2.5.1-SNAPSHOT.jar!/com/consol/citrus/wsdl/sample.wsdl";4 private String wsdlPath = "wsdl/sample.wsdl";5 protected void setUp() throws Exception {6 locator = new JarWSDLLocator(wsdlURL);7 }8 public void testGetBaseInputSource() throws Exception {9 InputSource inputSource = locator.getBaseInputSource();10 assertNotNull(inputSource);11 assertEquals(wsdlPath, inputSource.getSystemId());12 }13 public void testGetImportInputSource() throws Exception {14 assertNotNull(inputSource);15 assertEquals(wsdlPath, inputSource.getSystemId());16 }17 public void testGetBaseURI() throws Exception {18 assertEquals(wsdlLocation, locator.getBaseURI());19 }20 public void testGetLatestImportURI() throws Exception {21 assertEquals(wsdlLocation, locator.getLatestImportURI());22 }23}24package com.consol.citrus.xml.schema.locator;25import java.io.ByteArrayInputStream;26import java.io.ByteArrayOutputStream;27import java.io.IOException;28import java.io.InputStream;29import java.net.URL;30import java.util.jar.JarEntry;31import java.util.jar.JarFile;32import org.slf4j.Logger;33import org.slf4j.LoggerFactory;34import org.springframework.core.io.Resource;35import org.springframework.util.Assert;36import org.springframework.util.StringUtils;37import org.xml.sax.InputSource;38public class JarWSDLLocator implements WSDLLocator {39 private static Logger log = LoggerFactory.getLogger(JarWSDLLocator.class);40 private String jarFileURL;41 private JarFile jarFile;42 private JarEntry jarEntry;

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful