简体   繁体   English

@WebService Jaxws-如何在方法而非肥皂信封上获取名称空间

[英]@WebService jaxws - how to get namespace on method not soap envelope

I am trying to create a @WebService with java 8 and jax-ws. 我正在尝试使用Java 8和jax-ws创建一个@WebService。 However, I can't seem to find combination that will move the xmls " http://com.test.mymethod/mymethod " off of the envelope and onto the method. 但是,我似乎找不到找到将xmls“ http://com.test.mymethod/mymethod ”从信封移到方法上的组合。 Instead every method I try adds it to the Envbelope and then puts ser: prefix before the MyWebmethod. 相反,我尝试的每种方法都将其添加到Envbelope中,然后在MyWebmethod之前添加ser:前缀。 (which would be good if I was creating and sending out wsdl but I have to match request format already in use elsewhere) (如果我创建并发送wsdl,但是必须匹配其他地方已经使用的请求格式,那会很好)

desired request format: 所需的请求格式:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <MyWebmethod xmlns="http://com.test.mymethod/mymethod">

I think the only feasible way to to this (apart from asking: "Why is a semantically identical response not desired?" - but I am afraid of the answer :-) ) would be to "post-process" the response. 我认为解决此问题的唯一可行方法(除了问:“为什么不希望在语义上相同的响应?”-但我害怕答案:-))将是“后处理”响应。

The obvious solution would be to define a SOAPHandler for the Service-Endpoint. 显而易见的解决方案是为服务端点定义一个SOAPHandler This should be a straight-forward process: 这应该是一个简单的过程:

  1. Grab a sample response from your service (let's call this the "input XML" for the following steps). 从您的服务中获取示例响应(以下步骤将其称为“输入XML”)。
  2. Create a XSL Template to transform your input XML to the desired output form. 创建一个XSL模板,将您的输入XML转换为所需的输出形式。
  3. Annotate your @Webservice with a @HandlerChain annotation. @HandlerChain批注为@Webservice批注。
  4. Create the handler chain .xml file to define your SOAP handler (there is a basic example of the whole process of defining handlers over at mkyong: http://www.mkyong.com/webservices/jax-ws/jax-ws-soap-handler-in-server-side/ ) 创建处理程序链.xml文件来定义您的SOAP处理程序(在mkyong上有一个定义处理程序的整个过程的基本示例: http ://www.mkyong.com/webservices/jax-ws/jax-ws-soap -处理程序在服务器端/
  5. Use your XSLT from step 2 in the SOAP handler to transfrom the response's DOM. 使用SOAP处理程序中第2步中的XSLT来转换响应的DOM。

That being said - I am not 100% positive that you will be able to sufficiently influence the output of the handler chain. 话虽这么说-我不是100%肯定您将能够充分影响处理程序链的输出。 There is a very real chance that the resulting textual representation after the application server has serialized your DOM is still non-satisfactory. 应用程序服务器对DOM进行序列化之后,最终的文本表示形式仍然很有可能无法令人满意。

The second option would be to define a ServletFilter and have it rewrite the textual output of your webservice endpoint. 第二个选择是定义一个ServletFilter并重写ServletFilter端点的文本输出。 That will most certainly give you complete control over the output form - but at the (significant) cost of regenerating a DOM to feed into you XSL template. 无疑,这将使您完全控制输出表单-但以重新生成DOM并将其输入XSL模板的(显着)成本为代价。

All in all: Why would you go through all the pain? 总而言之: 您为什么要经历所有的痛苦? I am seriously curious. 我很好奇。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM