java – Problem testing a SOAP web service

Question:

I am implementing a SOAP web service in Java in an application that uses Struts in the presentation layer and I am having trouble testing it. The IDE I am using is Netbeans and I did the service using the wizard provided by the IDE. The application successfully deploys to a GlassFish server and the web service I am deploying is properly exposed. The address of the generated WSDL is:

http: // localhost: 8080 / Medications / webServices / TestWSDL? WSDL

The problem occurs when I want to test the service by changing the URL to http: // localhost: 8080 / Medicamentos / webServices / TestWSDL? Tester , link that should show me a page to enter the necessary data to test the service, but it redirects me to the page endpoint information ( http: // localhost: 8080 / Medicamentos / webServices / TestWSDL ). In the struts.xml file I have already told Struts to exclude the / webServices / * routes so that they are handled by the servlet in charge of the web service:

<constant name="struts.action.excludePattern" value="/webServices/.*"/>

My web.xml file:

<display-name>Medicamentos</display-name>
<!-- Spring/Hibernate conf -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--Struts filter and interceptor -->
<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Sticky session -->
<distributable/>
<listener>
    <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
    <servlet-name>TestWSDL</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>TestWSDL</servlet-name>
    <url-pattern>/webServices/*</url-pattern>
</servlet-mapping>

Do I have to add something extra to exclude the url so that I can test the web service or do I have something wrong with the regex ?. I have already tested the service using SoapUI and the like, but would like to be able to test from browser via URL.

Answer:

Glassfish internally uses the org.glassfish.webservices.JAXWSServlet servlet . It looks for two strings in the query-string of the request URL:

  • endpoint ? Tester : This forwards the request to another servlet , org.glassfish.webservices.monitoring.WebServiceTesterServlet , which generates a client with wsimport from the WSDL obtained with a request adding ?WSDL to the URL and generates the HTML for the test page .
  • endpoint ? WSDL : This generates the WSDL using an instance of com.sun.xml.ws.api.streaming.XMLStreamWriterFactory and writes it to the request.

However, in your case, you have registered the com.sun.xml.ws.transport.http.servlet.WSServletContextListener and the com.sun.xml.ws.transport.http.servlet.WSServlet , which does not have that option.

If the Glassfish you are using supports Java EE 6 or higher, just write down the class that implements the web service with @WebService without the need to map a servlet . And then you will have the test page available. *

────────────
* It is important to disable this option in productive environments, either through the sun-web.xml file or sun-ejb-jar.xml specifying false in the debugging-enabled element.

Scroll to Top