0

我正在尝试将肥皂信封发送到 Web 服务,但在 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 库。我尝试使用 org.apache.xmlbeans.impl.soap 库,但我得到:

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

仍然在soapConnection.call 线上。

任何帮助将非常感激。

4

0 回答 0