0

I'm trying to send a soap envelope to a webservice but I'm encountering a "java.net.UnknownHostException: socgentest.service-now.com" exception at the soapConnection.call line :

public static void updateTicket(String ticketId, String field, String value) {

    try {

        System.setProperty("http.proxySet", "true");
        System.setProperty("http.proxyHost", "***");
        System.setProperty("http.proxyPort", "8080");
        System.setProperty("http.proxyUser", "***");
        System.setProperty("http.proxyPassword", "***");

        MessageFactory messageFactory;
        messageFactory = MessageFactory.newInstance();

        SOAPMessage soapMessage = messageFactory.createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();

        String serverURI = "http://www.service-now.com/impulse_generic.ws";

        // SOAP Envelope
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.addNamespaceDeclaration("imp", serverURI);

        String caseType;

        if (ticketId.contains("INC"))
            caseType = "incident";
        else if (ticketId.contains("RITM"))
            caseType = "request";
        else
            caseType = "incident";

        if (Globals.soapAction == null)
            Globals.soapAction = "remote_update";

        if (Globals.soapAction.equals("remote_update"))
            Globals.correlationId = ticketId;        

        SOAPBody soapBody = envelope.getBody();

        SOAPElement soapBodyElem = soapBody.addChildElement("insert", "imp");

        SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("caseType", "imp");
        soapBodyElem1.addTextNode(caseType);
        SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("action", "imp");
        soapBodyElem2.addTextNode(Globals.soapAction);
        SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("correlation_id", "imp");
        soapBodyElem3.addTextNode(Globals.correlationId);
        SOAPElement soapBodyElem4 = soapBodyElem.addChildElement("sys_id", "imp");
        soapBodyElem4.addTextNode(ticketId);
        SOAPElement soapBodyElem5 = soapBodyElem.addChildElement(field, "imp");
        soapBodyElem5.addTextNode(value);

        String auth = new sun.misc.BASE64Encoder().encode("***:***".getBytes());

        MimeHeaders headers = soapMessage.getMimeHeaders();
        headers.addHeader("SOAPAction", serverURI);  //+ "impulse_generic.ws");
        headers.addHeader("Authorization", "Basic " + auth);

        soapMessage.saveChanges();

        try {

            System.out.print("Request SOAP Message = ");
            soapMessage.writeTo(System.out);
            System.out.println();

        } catch (IOException e) {
            //CommonMethods.msgBox(e.getStackTrace().toString());
            e.printStackTrace();
        }

            SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
            SOAPConnection soapConnection = soapConnectionFactory.createConnection();

            String url = "https://" + Globals.impulseInstance + "/" + "impulse_generic_ws.do?SOAP";
            SOAPMessage soapResponse = soapConnection.call(soapMessage, url);

            soapConnection.close();


    } catch (SOAPException e) {
        //CommonMethods.msgBox(e.getStackTrace().toString());
        e.printStackTrace();
    }

}

I also get the exception with this piece of code :

//              InetAddress impulseAddress = null;
//              
//              try {
//                  impulseAddress = java.net.InetAddress.getByName(Globals.impulseInstance);
//              } catch (UnknownHostException e) {
//                  // TODO Auto-generated catch block
//                  e.printStackTrace();
//              }

Value of Globals.impulseInstance is : "socgentest.service-now.com"

I don't understand why this error occurs because I can reach the webservice succesfully with VBA code through SOAP and through REST in Java but not with Java/SOAP...

I'm using javax.xml.soap lib. I tried with the org.apache.xmlbeans.impl.soap lib instead but I get :

"org.apache.xmlbeans.impl.soap.SOAPException: Unable to create message factory for SOAP: org.apache.axis2.saaj.MessageFactoryImpl cannot be cast to org.apache.xmlbeans.impl.soap.MessageFactory"

Still on the soapConnection.call line.

Any help would be much appreciated.

Jokas
  • 23
  • 7

0 Answers0