16

JAXWSを使用して、構築しているJavaアプリケーション用のWebServiceクライアントを生成しています。

JAXWSがSOAPプロトコルで使用するXMLを構築すると、次の名前空間プレフィックスが生成されます。

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
   <env:Body ...>
       <!-- body goes here -->
   </env:Body>
</env:Envelope>

私の問題は、クライアントが接続しているサーバーを管理するカウンターパート(大規模な送金会社)が、XMLNS(XML名前空間プレフィックスが)でない限り、 WebService呼び出しの受け入れを拒否することです(理由は聞かないでくださいsoapenv)。このような:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body ...>
       <!-- body goes here -->
   </soapenv:Body>
</soapenv:Envelope>

だから私の質問は:

プレフィックスとしてではsoapenvなくを使用してクライアントを生成するようにJAXWS(または他のJava WSクライアントテクノロジー)に命令する方法はありますか?この情報を設定するためのAPI呼び出しはありますか?envXMLNS

ありがとう!

4

2 に答える 2

21

多分あなたにとっては遅いかもしれませんし、これがうまくいくかどうかはわかりませんが、試してみることができます.

最初に SoapHandler を実装する必要があり、handleMessageメソッドでSOAPMessage. そのプレフィックスを直接変更できるかどうかはわかりませんが、試すことができます:

public class MySoapHandler implements SOAPHandler<SOAPMessageContext>
{

  @Override
  public boolean handleMessage(SOAPMessageContext soapMessageContext)
  {
    try
    {
      SOAPMessage message = soapMessageContext.getMessage();
      // I haven't tested this
      message.getSOAPHeader().setPrefix("soapenv");
      soapMessageContext.setMessage(message);
    }
    catch (SOAPException e)
    {
      // Handle exception
    }

    return true;
  }

  ...
}

次に、次を作成する必要がありますHandlerResolver

public class MyHandlerResolver implements HandlerResolver
{
  @Override
  public List<Handler> getHandlerChain(PortInfo portInfo)
  {
    List<Handler> handlerChain = Lists.newArrayList();
    Handler soapHandler = new MySoapHandler();
    String bindingID = portInfo.getBindingID();

    if (bindingID.equals("http://schemas.xmlsoap.org/wsdl/soap/http"))
    {
      handlerChain.add(soapHandler);
    }
    else if (bindingID.equals("http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/"))
    {
      handlerChain.add(soapHandler);
    }

    return handlerChain;
  }
}

HandlerResolver最後に、クライアント サービスにを追加する必要があります。

Service service = Service.create(wsdlLoc, serviceName);
service.setHandlerResolver(new MyHandlerResolver());
于 2011-01-24T12:40:37.703 に答える