0

I have Structure given below

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

< soapenv:Header>

  <urn:AuthenticationInfo>

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

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

  </urn:AuthenticationInfo>

< / soapenv: Header>

< soapenv:Body>

  <urn:Request_Query_Service>

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

  </urn:Request_Query_Service>

< /soapenv:Body>

< /soapenv:Envelope>

I have written code for the above request in Java

private static SOAPMessage createSOAPRequest(Map params) throws Exception

{

                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;     

            }  

Error occurred while sending SOAP Request to Server com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: java.security.PrivilegedActionException: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Message send failed"

Can Someone TELL Above java program to get correct structure for given SOAP request is correctly written or not ??

1 Answer 1

0

private static SOAPMessage createSOAPRequest(Map params) throws Exception {

                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;
             }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.