私はSOAPリクエストとレスポンスを呼び出すためにjavax.xml.soapライブラリを使用しました。私はSOAP UIでうまく動作するwsdlエンドポイントのURLを持っています。私は、同じ使用してJavaを検証する必要がある、と私は以下のように、実際のものとは異なるevnelopに見えるSOAPリクエストを作成JAVAライブラリを使用してXML SOAPエンベロープを変更するにはどうすればよいですか?
JAVAの要求ペイロード:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webservicex.com/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<web:GetCitiesByCountry>
<web:CountryName>US</web:CountryName>
</web:GetCitiesByCountry>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SOAPの要求ペイロード:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET">
<soapenv:Header/>
<soapenv:Body>
<web:GetCitiesByCountry>
<!--Optional:-->
<web:CountryName>US</web:CountryName>
</web:GetCitiesByCountry>
</soapenv:Body>
</soapenv:Envelope>
JAVAリクエストペイロードが期待どおりに機能していないため、以下のエラー応答がスローされます。
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://www.webservicex.com/GetCitiesByCountry.
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>
私は封筒を除いて、両方の要求ペイロードの間に違いを見つけることができませんでした、と私は
SOAPConstants.SOAP_1_1_PROTOCOLと1_2 PROTOCOLが、運を使って、エンベロープを修正しようとしました。
私はこれまで試み以下のコード:
private static SOAPMessage createSOAPRequest() throws Exception
{
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
//Tried to change the envelop which is not working
/*MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPMessage soapMessage = messageFactory.createMessage();
soapMessage.getSOAPPart().setPrefix("soapenv");
soapMessage.getSOAPPart().removeMimeHeader("SOAP-ENV");
soapMessage.getSOAPHeader().setPrefix("soapenv");
soapMessage.getSOAPBody().setPrefix("soapenv");
messageFactory.createMessage();*/
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://www.webservicex.com/";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("web", serverURI);
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement(
"GetCitiesByCountry", "web");
SOAPElement soapBodyElem1 soapBodyElem.addChildElement("CountryName",
"web");
soapBodyElem1.addTextNode("US");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI + "GetCitiesByCountry");
System.out.println(soapMessage.getSOAPBody());
soapMessage.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message:");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
Iは、要求ペイロードをコピーしsopaenvするSOAP-ENVからエンベロープを変更しSOAPUIで呼び出さ適切な応答を返すことです。だから誰かがどのように私はJavaライブラリを使用してエンベロープタグを変更することができます教えてもらえますか?
で試すことができます。スタックトレースを見つけてください:_ServerがHTTPヘッダーSOAPActionの値を認識しませんでした:http://www.webservicex.NET/GetCitiesByCountry._ – ArrchanaMohan
soap ui workspace xmlを投稿できますか? – harry
問題は、javaがJavaクラスへのバイトの受信ストリームを逆シリアル化するためのルールを含むスキーマまたはxsdを見つけることができないことです。毎回働く最も単純な方法は、 Mavenジョブはwsdlを受け取り、Jaxbクラスを生成します。 – harry