错误:在JAVA STAND ALONE:严重:SAAJ0537:内容类型无效。可能是错误消息而不是SOAP消息

时间:2016-05-09 07:42:45

标签: java soap webservice-client

以下是我的JAVA独立类SOAP客户端。我也使用密钥库。但我正在

  

严重:SAAJ0537:内容类型无效。可能是错误消息   而不是SOAP消息

例外,努力尝试,无法弄明白。我也附上了洛杉矶,

CODE:

public class SOAPClient {

    public static void main(String args[]) throws Exception {

        String keyStore = "XXXX/keystore_s1_ariba_uat.jks";

        System.getProperties().setProperty("javax.net.ssl.keyStore",keyStore);
        System.getProperties().setProperty("javax.net.ssl.keyStorePassword","XXXX");
        System.getProperties().setProperty("javax.net.ssl.trustStore", keyStore);

        System.getProperties().setProperty("http.proxyHost", "web-proxy.XXXX.XXXX.net");
        System.getProperties().setProperty("https.proxyHost", "web-proxy.XXXX.XXXX.net");
        System.getProperties().setProperty("http.proxyPort", "8080");
        System.getProperties().setProperty("https.proxyPort", "8080");

        // Create SOAP Connection
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection = soapConnectionFactory.createConnection();

        // Send SOAP Message to SOAP Server
        String url = "https://s1.ariba.com/Sourcing/soap/hpegp-T/ContractHeaderExport?wsdl&validate=false";

        SOAPMessage soapMessage = createSOAPRequest();
        SOAPMessage soapResponse = soapConnection.call(soapMessage, url);

        // print SOAP Response
        System.out.print("Response SOAP Message:");
        soapResponse.writeTo(System.out);

        soapConnection.close();
    }


    private static SOAPMessage createSOAPRequest() throws Exception {
        MessageFactory messageFactory = MessageFactory.newInstance();
        //MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);

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

        String serverURI = "urn:Ariba:Sourcing:vrealm_995";

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

        // SOAP header        
        SOAPHeader soapHeader = envelope.getHeader();
        soapHeader.setPrefix("soapenv");

        SOAPElement soapHeaderElem = soapHeader.addChildElement("Headers", "urn");
        SOAPElement soapHeaderElemVarient = soapHeaderElem.addChildElement("variant", "urn");
        soapHeaderElemVarient.addTextNode("?");
        SOAPElement soapHeaderElemPartition = soapHeaderElem.addChildElement("partition", "urn");
        soapHeaderElemPartition.addTextNode("?");

        // SOAP Body
        SOAPBody soapBody = envelope.getBody();
        soapBody.setPrefix("soapenv");
        SOAPElement soapBodyElem = soapBody.addChildElement("ContractHeaderExportRequest", "urn");

        Name variantName = envelope.createName("variant");
        Name partitionName = envelope.createName("partition");
        soapBodyElem.addAttribute(variantName, "?");
        soapBodyElem.addAttribute(partitionName, "?");

        SOAPElement soapBodyElemWSContractHeader = soapBodyElem.addChildElement("WSContractHeaderExportInputBean_Item", "urn");
        SOAPElement soapBodyElemItem = soapBodyElemWSContractHeader.addChildElement("item", "urn");

        SOAPElement soapBodyElemClassName = soapBodyElemItem.addChildElement("ClassName", "urn");
        soapBodyElemClassName.addTextNode("ariba.collaborate.contracts.ContractWorkspace");

        SOAPElement soapBodyElemFromDate = soapBodyElemItem.addChildElement("FromDate", "urn");
        soapBodyElemFromDate.addTextNode("2015-01-01T12:00:00Z");

        SOAPElement soapBodyElemToDate = soapBodyElemItem.addChildElement("ToDate", "urn");
        soapBodyElemToDate.addTextNode("2016-04-29T12:00:00Z");

        //Mime Header
        MimeHeaders headers = soapMessage.getMimeHeaders();
        //headers.addHeader("SOAPAction", serverURI + "ContractHeaderExportRequest");
        headers.addHeader("SOAPAction", serverURI + "ContractHeaderExportRequest");
        headers.setHeader("Content-Type", "text/xml; charset=utf-8");
        //headers.setHeader("Content-Type", "text/html; charset=utf-8");

        soapMessage.saveChanges();

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

        return soapMessage;
    }

}

日志:

  

2016年5月9日下午12:14:19   com.sun.xml.internal.messaging.saaj.soap.MessageImpl   identifyContentType SEVERE:SAAJ0537:无效的内容类型。可能   错误消息而不是SOAP消息线程中的异常" main"   com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:   com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:无效   内容类型:text / html的。这是一条错误消息而不是SOAP   响应?在   com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:148)     在com.rnd.ws.soap.SOAPClient.main(SOAPClient.java:45)引起:   com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:无效   内容类型:text / html的。这是一条错误消息而不是SOAP   响应?在   com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType(MessageImpl.java:602)     在   com.sun.xml.internal.messaging.saaj.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:86)     在   com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:328)     在   com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:144)     ......还有1个

原因:

  

com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:无效   内容类型:text / html的。这是一条错误消息而不是SOAP   响应?在   com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType(MessageImpl.java:602)     在   com.sun.xml.internal.messaging.saaj.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:86)     在   com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:328)     在   com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:144)     在com.rnd.ws.soap.SOAPClient.main(SOAPClient.java:45)

有什么可以帮助我吗?

0 个答案:

没有答案