为下面的结构生成XML SOAP请求

时间:2014-10-21 14:19:10

标签: java xml soap

我在下面给出了结构

< soapenv:Envelope xmlns:soapenv =" http://schemas.xmlsoap.org/soap/envelope/"的xmlns:瓮="瓮:SRM_RequestInterface_WS">

< soapenv:Header>

  <urn:AuthenticationInfo>

     <urn:userName>admin</urn:userName>

     <urn:password>Password</urn:password>

  </urn:AuthenticationInfo>

&LT; / soapenv:标题&gt;

&LT; soapenv:车身&GT;

  <urn:Request_Query_Service>

     <urn:Request_Number>REQ00000041</urn:Request_Number>

  </urn:Request_Query_Service>

&LT; / soapenv:车身与GT;

&LT; / soapenv:信封&GT;

我已经用Java编写了上述请求的代码

private static SOAPMessage createSOAPRequest(Map params)抛出异常

{

                MessageFactory messageFactory = MessageFactory.newInstance();

                SOAPMessage soapMessage = messageFactory.createMessage();
                SOAPPart soapPart = soapMessage.getSOAPPart();
                String serverURI = "urn:SRM_RequestInterface_WS";
                SOAPEnvelope envelope = soapPart.getEnvelope();

                envelope.addNamespaceDeclaration("urn", serverURI);

                SOAPHeader header=envelope.getHeader();


                SOAPElement soapBodyElem = header.addChildElement("AuthenticationInfo", "urn");


                SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("userName");
                soapBodyElem1.addTextNode("admin");

                SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("password");
                soapBodyElem2.addTextNode("Password1!");


                SOAPBody soapBody = envelope.getBody();
                SOAPElement soapBodyElem3 = soapBody.addChildElement("Request_Query_Service", "urn");

                SOAPElement soapBodyElem4 = soapBodyElem3.addChildElement("Request_Number");
                soapBodyElem4.addTextNode("REQ00000041");


                soapMessage.saveChanges();

                ByteArrayOutputStream out = new ByteArrayOutputStream();
                if(Validator.isNotNull(out)){
                    soapMessage.writeTo(out);

                }
                    return soapMessage;     

            }  

向服务器发送SOAP请求时发生错误 com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:java.security.PrivilegedActionException:com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:消息发送失败&#34;

有人可以TELL以上java程序获取正确的结构,以便正确编写给定的SOAP请求吗?

1 个答案:

答案 0 :(得分:0)

private static SOAPMessage createSOAPRequest(Map params)抛出异常{

                MessageFactory messageFactory = MessageFactory.newInstance();
                SOAPMessage soapMessage = messageFactory.createMessage();
                SOAPPart soapPart = soapMessage.getSOAPPart();
                String serverURI = "http://ws.myweb.com/";
                SOAPEnvelope envelope = soapPart.getEnvelope();
                envelope.addNamespaceDeclaration("ws", serverURI);

                SOAPBody soapBody = envelope.getBody();
                SOAPElement soapBodyElem = soapBody.addChildElement("search", "ws");

                SOAPElement soapBodyElem11 = soapBodyElem.addChildElement("ARloginSchemaSearch");
                SOAPElement soapBodyElem1 = soapBodyElem11.addChildElement("server");
                soapBodyElem1.addTextNode("it.dev.local");

                SOAPElement soapBodyElem2 = soapBodyElem11.addChildElement("user");
                soapBodyElem2.addTextNode("Alex");

                SOAPElement soapBodyElem3 = soapBodyElem11.addChildElement("password");
                soapBodyElem3.addTextNode("password");


                SOAPElement soapBodyElem6 = soapBodyElem11.addChildElement("tcpport");
                soapBodyElem6.addTextNode("51100");

                SOAPElement soapBodyElem7 = soapBodyElem11.addChildElement("rpcqueue");
                soapBodyElem7.addTextNode("452180");

                SOAPElement soapBodyElem8 = soapBodyElem.addChildElement("search-formName");


                SOAPElement soapBodyElem9 = soapBodyElem.addChildElement("search-QueryString");

                soapBodyElem9.addTextNode("'ID'  "+'"'+params.get("id"));

                SOAPElement soapBodyElem10 = soapBodyElem.addChildElement("search-resultFieldsList");

                SOAPElement  soapBodyElem12=soapBodyElem10.addChildElement("arrayList"); 
                soapBodyElem12.addTextNode("ID");

                soapMessage.saveChanges();

                ByteArrayOutputStream out = new ByteArrayOutputStream();

                if(Validator.isNotNull(out))
                {
                    soapMessage.writeTo(out);

               }

               return soapMessage;
             }