Created
August 13, 2012 14:37
-
-
Save dmorgantini/3341293 to your computer and use it in GitHub Desktop.
Use SOAP with dropwizard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.helloworld.resources; | |
import javax.jws.WebMethod; | |
@javax.jws.WebService( | |
name = "AddNumbersPortType", | |
serviceName = "AddNumbersService", | |
targetNamespace = "http://duke.example.org") | |
@javax.jws.soap.SOAPBinding( | |
style = javax.jws.soap.SOAPBinding.Style.DOCUMENT, | |
use = javax.jws.soap.SOAPBinding.Use.LITERAL, | |
parameterStyle = javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED) | |
public class AddNumbersService { | |
@WebMethod | |
public int Add(int a, int b) { | |
return a + b; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>com.sun.xml.ws</groupId> | |
<artifactId>jaxws-rt</artifactId> | |
<version>2.2.6-2</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SoapBundle implements Bundle { | |
@Override | |
public void initialize(Environment environment) { | |
environment.addServlet(new com.sun.xml.ws.transport.http.servlet.WSServlet(), "/SOAP/*"); | |
environment.addServletListeners(new com.sun.xml.ws.transport.http.servlet.WSServletContextListener()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<endpoints | |
xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" | |
version="2.0"> | |
<endpoint | |
name="HelloWorld" | |
implementation="com.example.helloworld.resources.AddNumbersService" | |
url-pattern="/SOAP/add"/> | |
</endpoints> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The missing "/WEB-INF/sun-jaxws.xml" is caused due to the WSServletContextListener trying to fetch the URL to sunJaxWsXml. Stepping through the code got me to the ContextHandler which checks the _baseResource value, which was never set when setting the servlet.
The most important bit is to set the resource base, without which the context would never find xml file, no matter where you place the file.
I am using dropwizard 0.7.1 and I add this to the run method of my Application class.
ServletEnvironment servlet = environment.servlets();
servlet.setResourceBase("/");
servlet.addServlet("/SOAP/*", new com.sun.xml.ws.transport.http.servlet.WSServlet());
servlet.addServletListeners(new com.sun.xml.ws.transport.http.servlet.WSServletContextListener());
And then ensure /WEB-INF/sun-jaxws.xml exists in the root directory.