Xsd schema not represented by wsdl

I am developing a WebService with JAX-WS (I am using the wsimport target for jaxws-maven-plugin). I wrote a WSDL that imports an XSD schema.

WEB-INF/wsdl/service.wsdl WEB-INF/wsdl/service.xsd 

I also created web service classes and created the endpoint and that’s it. So far, everything has worked perfectly. When I was working on Tomcat 7, everything is fine. I can access wsdl in my browser:

 http://localhost:8080/webService/servlet-url?wsdl 

but I cannot access the xsd schema. The problem is this wsdl:

 <xsd:schema> <xsd:import namespace="http://ws.service/domain/1.0" schemaLocation="service.xsd"/> </xsd:schema> 

Of course, while generating the wsdl and xsd classes are on the local path, but I want them to be remotely accessible when the web service is started. I know that schemaLocation should be something like this: "http: // localhost: 8080 / webService / servlet-url? Xsd = 1".

In wsdl, presented in the browser, the import is as follows:

 <xsd:schema> <xsd:import namespace="http://ws.service/domain/1.0" schemaLocation="http://localhost:8080/webService/servlet-url?wsdl&resource=service.xsd"/> </xsd:schema> 

localhost: 8080 / webService / servlet? wsdl gives me:

 wsdl:definitions targetNamespace="http://ws.serv.com/Service/1.0" name="emuiaService"> <wsdl:types> <xsd:schema> <xsd:import namespace="http://ws.serv.com/Service/domain/1.0" schemaLocation="schema.xsd"/> </xsd:schema> </wsdl:types> <wsdl:message name="halloMsg"> <wsdl:part name="parameters" element="dom:halloRequest"/> </wsdl:message> <wsdl:message name="halloResponseMsg"> <wsdl:part name="return" element="dom:halloResponse"/> </wsdl:message> 

etc.

+7
source share
2 answers

I almost can't believe it was such a difficult problem!

I searched like crazy to find a solution to this particular problem! Then I struggled to find a solution on my own. Through a debugger that executed the default java-6-openjdk javax.xml.ws.spi.Provider ("w770") implementation in the JRE, which creates the javax.xml.ws.Endpoint objects that you use to publish web services) I finally found out some things that helped me develop a solution that at least works in Java SE, at least in my current JRE, which:

 java version "1.6.0_33" OpenJDK Runtime Environment (IcedTea6 1.13.5) (6b33-1.13.5-1ubuntu0.12.04) OpenJDK Server VM (build 23.25-b01, mixed mode) 

Whether this solution is applicable in Java EE, I do not know yet.

Here's how I solved it:

 package myservice; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Arrays; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; import javax.xml.ws.Endpoint; public class App { private static final String MY_SERVICE_XSD = "/wsdl/MyService.xsd"; public static void main( String[] args ) { Endpoint ep = Endpoint.create(new MyEndpointImpl()); ep.setMetadata(Arrays.asList(sourceFromResource(MY_SERVICE_XSD))); ep.publish("http://localhost:8080/svc/hello"); } private static Source sourceFromResource(String name) { URL resource = App.class.getResource(name); String systemId = resource.toExternalForm(); InputStream inputStream; try { inputStream = resource.openStream(); } catch (IOException e) { throw new RuntimeException("Failed to create InputStream from resource \""+ name +"\"", e); } return new StreamSource(inputStream, systemId); } } 

Most importantly, I first use the Endpoint # create method (rather than Endpoint # publish) to get an unpublished endpoint. Then I add the XSD file as "metadata" to the (not yet published) endpoint (code "ep.setMetaData (...)"). Then I publish the endpoint (code "ep.publish (...)").

Now when I access http://localhost:8080/svc/hello?wsdl , I get:

  <definitions targetNamespace="http://somewhere.net/my/namespace" name="MyService"> <types> <xsd:schema> <xsd:import namespace="http://somewhere.net/my/namespace" schemaLocation="http://localhost:8080/svc/hello?xsd=1"/> </xsd:schema> </types> ... </definitions> 

and my xsd file is available from http://localhost:8080/svc/hello?xsd=1 !

Note that my MyService.wsdl file on disk still contains:

  <xsd:schema> <xsd:import namespace="http://somewhere.net/my/namespace" schemaLocation="MyService.xsd"></xsd:import> </xsd:schema> 
+4
source

OK, we are going.

To a WSDL file to modify something like this

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <wsdl:definitions targetNamespace="http://service.wsr.company.com/" name="webServiceExample" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://servicio.wsr.baz.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> 

In this small snippet, xmlns tags are important. They are used to deploy the XSD schema. Further

 <wsdl:types> <xs:schema xmlns:tns="http://service.wsr.company.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://service.wsr.company.com/" version="1.0"> ... </xs:schema> </wsdl:types> 

In this tag below you will get what you have in the service.xsd file or show it in http://localhost:8080/webService/servlet-url?xsd=1 , we continue

  <wsdl:message name="your_method_name"> <wsdl:part name="parameters" element="tns:your_method_name"/> </wsdl:message> <wsdl:message name="your_method_nameResponse"> <wsdl:part name="parameters" element="tns:your_method_nameResponse"/> </wsdl:message> 

Those tags above show your method name. Further

  <wsdl:portType name="webServiceExample"> <wsdl:operation name="your_method_name"> <wsdl:input message="tns:your_method_name"/> <wsdl:output message="tns:your_method_nameResponse"/> </wsdl:operation> </wsdl:portType> 

The ones above tar are for entering your operation. Proceed

  <wsdl:binding name="webServiceExamplePortBinding" type="tns:webServiceExample"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> <wsdl:operation name="your_method_name"> <soap:operation soapAction=""/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> 

Following:)

  <wsdl:service name="webServiceExample"> <wsdl:port name="webServiceExamplePort" binding="tns:webServiceExamplePortBinding"> <soap:address location="REPLACE_WITH_ACTUAL_URL"/> </wsdl:port> 

And finally finished :)

Please note that you need to change the current tag with the <wsdl:...></wsdl:...>

You save it, the public, and enjoy the XSD scheme presented in WSDL .

I hope to help you. Ciao.

0
source

All Articles