'Generating and accessing WSDL on Tomcat with Maven
I have a JAX-WS server that I package with Maven and deploy on Tomcat. The pom.xml generates the WSDL file automatically with the trick from Use Maven to trigger a wsgen & wsimport in a row, using wsdlLocation. I only use the first part, that is:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-wsdl</id>
<phase>process-classes</phase>
<goals>
<goal>wsgen</goal>
</goals>
<configuration>
<sei>packageName.endpointName</sei>
<genWsdl>true</genWsdl>
</configuration>
</execution>
</executions>
</plugin>
This is the generated WSDL:
<wsp:Policy wsu:Id="NAMEServerPortBinding_MTOM_Policy">
<ns1:OptimizedMimeSerialization wsp:Optional="true" xmlns:ns1="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization"/>
</wsp:Policy>
<types>
<xsd:schema>
<xsd:import namespace="http://PACKAGE/" schemaLocation="SERVER_schema1.xsd"/>
</xsd:schema>
</types>
<etc...>
<service name="NAME">
<port name="NAMEPort" binding="tns:NAMEPortBinding">
<soap:address location="REPLACE_WITH_ACTUAL_URL"/>
</port>
</service>
</definitions>
My web.xml:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>serverName</servlet-name>
<servlet-class>
com.sun.xml.ws.transport.http.servlet.WSServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>serverName</servlet-name>
<url-pattern>/serverName/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>120</session-timeout>
</session-config>
</web-app>
And my sun-jaxws.xml:
<endpoints version="2.0"
xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">
<endpoint implementation="package.ServerEndpoint" name="serverName"
url-pattern="/serverLink"/>
</endpoints>
I have made sure that Tomcat did deploy and start the webserver, I have checked that the WSDL is indeed inside the server in Tomcat, and yet I cannot figure out how to access it so I can go on to finishing the client and testing the whole thing. I've looked at over a dozen tutorials and most of them seem to get to this point and then say "and here some magic happens, you open a browser and this shows up:"
https://www.java2blog.com/wp-content/uploads/2013/03/WebserviceOutput.gif
The image used is always the same, and indeed I have seen this when working on Glassfish, but I cannot for the life of me figure out what I must do to make it happen on Tomcat. Both the link http://localhost:8080/server-1.0/serverName/serverLink and http://localhost:8080/server-1.0/serverName return a "404 Not Found: Invalid Request". Appending ?wsdl to either one does not change the result. The answer to accessing wsdl on Tomcat suggests installing Metro, which I did, unfortunately to no avail.
All code shown is summarized and has variable names changed. If more information is required, I will be happy to provide it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|