采用代码优先方法生成自定义 WSDL
我使用 CXF 和代码优先方法创建了一些 Web 服务。这是我的配置和代码:
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();
}
}
这样,请求 http://localhost:8080/myWebApp/ws/test?wsdl 得到一个漂亮的 WSDL,其中包含:
<wsdl:service name="TestServiceService">
<wsdl:port binding="tns:TestServiceServiceSoapBinding" name="TestServicePort">
<soap:address location="http://localhost:8080/myWebApp/ws/test"/>
</wsdl:port>
</wsdl:service>
问题我想要一个不同的位置,具体取决于 HttpServletRequest 对象。因此,我需要以某种方式覆盖 WSDL 生成代码。我一直在寻找此内容是在哪里创建的,但没有成功。
解决这个问题的最佳方法是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 CXF 2.4.x,WSDL 通过 org.apache.cxf.frontend.WSDLGetInterceptor 发回。您可以在那里寻找有关如何改变事物或类似事物的想法。
您究竟想改变什么?如果它只是soap:address 上的位置,您可以只粘贴一个在其之前运行的拦截器,该拦截器将调用:
或类似的内容。
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.