Java アプリケーションで Apache CXF (2.6.1) を使用して、サード パーティの Web サービスを利用しています。しかし、特に問題があります。特に、スタブの生成中にデータバインディングに JAXB を使用すると、クライアントは常に「--uuid:e47f145b-38f7-4402-8eec-657d71bc8ad4...」のような「ヘッダー」を含むリクエストを送信します (参照以下のクライアント要求)、つまり、XML 部分の他に、いくつかの特別な情報があります...
この特別な情報により、サーバーからのエラー応答が「コンテンツはプロローグで許可されていません」(以下のサーバー応答を参照) の原因になっているようです。つまり、サーバーはそのような本文を予期していません。ここで興味深いのは、データバインディングに XMLBEANS を使用してスタブを生成すると、すべてが正常に機能し始めることです (要求本文にはそのような「特別な」情報はなく、XML のみです)。グーグルで調べた後、クライアントが何らかの理由でMTOM(JAXBを使用)を使用しようとしていると思われ、それをオフにする方法がわかりません。MTOMをオフにするために、次のことをすでに試しました(運が悪い):
((BindingProvider)port).getRequestContext().put("mtom-enabled", Boolean.FALSE);
((BindingProvider)port).getRequestContext().put("write.attachments", Boolean.FALSE);
((BindingProvider)port).setMTOMEnabled(false);
XMLBEANSに比べてはるかにコンパクトなので、本当にJAXBに移行したいのですが...
クライアントコード:
AdminServiceV2 ws = new AdminServiceV2();
AdminV2 port = ws.getAdminPortV2();
Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
authorizationPolicy.setUserName("user1");
authorizationPolicy.setPassword("password1");
authorizationPolicy.setAuthorizationType("Basic");
http.setAuthorization(authorizationPolicy);
try {
port.getUsersInfo("user1");
} catch (Exception e) {
e.printStackTrace();
}
クライアントのリクエスト:
--uuid:e47f145b-38f7-4402-8eec-657d71bc8ad4
Content-Type: text/xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:getUsersInfo xmlns:ns2="http://service.admin.ws.five9.com/v2/"><userNamePattern>user1</userNamePattern></ns2:getUsersInfo></soap:Body></soap:Envelope>
--uuid:e47f145b-38f7-4402-8eec-657d71bc8ad4--
サーバーの応答:
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body><env:Fault xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><faultcode>env:Client</faultcode><faultstring>org.xml.sax.SAXParseException: Content is not allowed in prolog.</faultstring></env:Fault></env:Body></env:Envelope>
ありがとう、コンスタンチン