I’ve created some web services using CXF and code-firts approach. Here is my configuration and code:
web.xml:
...
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
applicationContext.xml:
<jaxws:endpoint implementor="#testService" address="/test" />
TestService.java:
@Service
@WebService
public class TestService {
@WebMethod
public String random() {
return "random=" + Math.random();
}
}
This way, a request to http://localhost:8080/myWebApp/ws/test?wsdl gets a beautiful WSDL, which contains:
<wsdl:service name="TestServiceService">
<wsdl:port binding="tns:TestServiceServiceSoapBinding" name="TestServicePort">
<soap:address location="http://localhost:8080/myWebApp/ws/test"/>
</wsdl:port>
</wsdl:service>
The problem is I want a different location depending on the HttpServletRequest object. So, I need to overwrite some way the WSDL generation code. I’ve looked for where is this content created, without success.
Which is the best approach to solve this issue?
With CXF 2.4.x, the WSDL is sent back via org.apache.cxf.frontend.WSDLGetInterceptor. You could look in there for ideas on how to change things or similar.
What exactly are you trying to change about it? If it’s just the location on the soap:address, you can just stick an interceptor that would run before it that would call:
or similar.