SOAP调用上的UnknownHostException

时间:2016-04-20 10:09:40

标签: java web-services soap unknown-host

我正在尝试将肥皂信封发送到网络服务,但我在soapConnection.call行遇到“java.net.UnknownHostException:socgentest.service-now.com”异常:

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();
    }

}

我也用这段代码得到了例外:

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

Globals.impulseInstance的价值是:“socgentest.service-now.com”

我不明白为什么会出现这种错误,因为我可以通过SOAP和Java中的REST使用VBA代码成功访问Web服务,但不能使用Java / SOAP ...

我正在使用javax.xml.soap lib。我尝试使用org.apache.xmlbeans.impl.soap lib,但我得到了:

“org.apache.xmlbeans.impl.soap.SOAPException:无法为SOAP创建消息工厂:org.apache.axis2.saaj.MessageFactoryImpl无法强制转换为org.apache.xmlbeans.impl.soap.MessageFactory”< / p>

仍在soapConnection.call行。

非常感谢任何帮助。

0 个答案:

没有答案