简体   繁体   English

通过Java调用Web服务时,获取javax.xml.soap.SOAPException:Oracle Weblogic服务器上未指定Content-Type错误

[英]Getting javax.xml.soap.SOAPException: Content-Type not specified error on Oracle weblogic server while calling web service through Java

I have written a java code using Jdeveloper tool to call external web service. 我已经使用Jdeveloper工具编写了一个Java代码来调用外部Web服务。 When I am running my code from Jdeveloper it is working fine. 当我从Jdeveloper运行我的代码时,它运行良好。 But I am deploying my code on Oracle weblogic 10.3.6 server and try to run this code then It is giving me below error - 但是我将我的代码部署在Oracle weblogic 10.3.6服务器上,然后尝试运行此代码,然后出现以下错误-

javax.xml.soap.SOAPException: Content-Type not specified javax.xml.soap.SOAPException:未指定Content-Type

Here is my code - 这是我的代码-

    public static String callTestService(String soapRequestXml, String url)  {


        try{

        final boolean isHttps = url.toLowerCase().startsWith("https");
        HttpsURLConnection httpsConnection = null;
                // Open HTTPS connection

                // Create a trust manager that does not validate certificate chains
                       TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
                               public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                                   return null;
                               }
                               public void checkClientTrusted(X509Certificate[] certs, String authType) {
                               }
                               public void checkServerTrusted(X509Certificate[] certs, String authType) {
                               }
                           }
                       };

                if (isHttps) {
                    // Create SSL context and trust all certificates
                    SSLContext sslContext = SSLContext.getInstance("SSL");
                    //TrustManager[] trustAll= new TrustManager[] {new TrustAllCertificates()};
                   sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
                    // Set trust all certificates context to HttpsURLConnection
                    HttpsURLConnection
                            .setDefaultSSLSocketFactory(sslContext.getSocketFactory());
                    // Open HTTPS connection
                  //  URL url1 = new URL(url);
                  URL url1 = new URL(null, url, new sun.net.www.protocol.https.Handler());
                    httpsConnection = (HttpsURLConnection) url1.openConnection();
                    // Trust all hosts
             //       httpsConnection.setHostnameVerifier(new TrustAllHosts());
                    // Connect

                    //Use below (2 lines) if Host name verification needs to turned off
                    MyHostnameVerifier HostVerifier = new MyHostnameVerifier();
                    httpsConnection.setHostnameVerifier(HostVerifier);
                    httpsConnection.connect();
                }
        // Create SOAP Connection
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection = soapConnectionFactory.createConnection();
        System.out.println("create connection");
     // SOAPMessage soapRequest = MessageFactory.newInstance().createMessage(new MimeHeaders(),
       //        new ByteArrayInputStream(soapRequestXml.getBytes()));

        SOAPMessage soapRequest = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage(new MimeHeaders() ,
                 new ByteArrayInputStream(soapRequestXml.getBytes(Charset.forName("UTF-8"))));
           // SOAPMessage s = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
           // SOAPPart soapPart = soapRequest.getSOAPPart();

                // SOAP Envelope
               // SOAPEnvelope envelope = soapPart.getEnvelope();
               // envelope.addNamespaceDeclaration("Dokumentai", "http://vmi.lt/ais/xsd/daa");

    //  MessageFactory messageFactory = MessageFactory.newInstance();
        //SOAPMessage soapRequest = messageFactory.createMessage(new MimeHeaders(),soapRequestXml);
     // MessageFactory messageFactory = MessageFactory.newInstance();
      //  SOAPMessage soapRequest = messageFactory.createMessage();
    //  SOAPPart soapPart = soapRequest.getSOAPPart();
    //   SOAPEnvelope envelope = soapPart.getEnvelope();
     //   SOAPBody soapBody = envelope.getBody();
      //soapBody.setTextContent(soapRequestXml);
     // soapRequest.setContentDescription(soapRequestXml);

   // SOAPPart soapPart = soapRequest.getSOAPPart();
    //SOAPEnvelope envelope = soapPart.getEnvelope();

     // String serverURI = "myhost";


   //  envelope.addNamespaceDeclaration("xmlns",
     //  "http://vmi.lt/ais/xsd/daa");






     // SOAP Envelope


   //  SOAPEnvelope envelope = soapPart.setContent(soapRequestXml);
       // System.out.println("SOAP "+ soapRequest.writeTo(System.out));

        MimeHeaders headers = soapRequest.getMimeHeaders();
    headers.setHeader("SOAPAction",
          "http://vmi.lt/ais/ws/handleMessage");
           MimeHeaders headers1 = soapRequest.getMimeHeaders();
            headers1.setHeader("Content-Type", "application/soap+xml; charset=utf-8");
        soapRequest.saveChanges();
        soapRequest.writeTo(System.out);
        System.out.println("call request url");








        // Send SOAP Message to SOAP Server
        SOAPMessage soapResponse = soapConnection.call(soapRequest, url);
            soapResponse.setProperty("Content-Type", "application/xml; charset=utf-8");
            soapResponse.setContentDescription("application/xml; charset=utf-8");

        ByteArrayOutputStream soapResponseBaos = new ByteArrayOutputStream();
        soapResponse.writeTo(soapResponseBaos);
        String soapResponseXml = soapResponseBaos.toString();

        return soapResponseXml;

        }catch(Exception e){

            return e.toString();
            }
    }

I have tried many different things but it works fine when i call web service directly from Jdeveloper but fails when I call from Oracle web logic server. 我已经尝试了许多不同的方法,但是当我直接从Jdeveloper调用Web服务时,它工作正常,但是当我从Oracle Web逻辑服务器调用时,它却失败了。

Could you please help me with this? 你能帮我这个忙吗?

I have fixed this issue.Please make following changes in the code. 我已解决此问题。请在代码中进行以下更改。

MimeHeaders headers1 = new MimeHeaders(); MimeHeaders headers1 =新的MimeHeaders();

             headers1.setHeader("Content-Type", "text/xml");
             headers1.setHeader("Encoding", "UTF-8");
//    SOAPMessage soapRequest =
  //      MessageFactory.newInstance().createMessage(new MimeHeaders(),
    //                                               new ByteArrayInputStream(soapRequestXml.getBytes(Charset.forName("UTF-8"))));

    SOAPMessage soapRequest = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL).createMessage(headers1 ,
             new ByteArrayInputStream(soapRequestXml.getBytes(Charset.forName("UTF-8"))));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javax.xml.ws.WebServiceException:javax.xml.soap.SOAPException:错误代码QName必须使用名称空间限定! 在weblogic服务器12c中部署时 - javax.xml.ws.WebServiceException: javax.xml.soap.SOAPException: Fault code QName must be namespace qualified! when deploying in weblogic server 12c javax.xml.soap.SOAPException:无法解析 SOAP 文档 - javax.xml.soap.SOAPException: Unable to parse SOAP document javax.xml.soap.SOAPException:java.security.ProviderException:无法派生密钥 - javax.xml.soap.SOAPException: java.security.ProviderException: Could not derive key 从 Postman 调用 SOAP API 时出错:无效的内容类型:应用程序/xml。 这是错误消息而不是 SOAP 响应吗? - Getting Error while calling SOAP API from Postman: Invalid Content-Type:application/xml. Is this an error message instead of a SOAP response? javax.xml.soap.SOAPException:无法找到前缀名称空间:wsse HEADER安全性 - javax.xml.soap.SOAPException:unable to find namespace for prefix: wsse HEADER Security javax.xml.soap.SOAPException:标题子元素“用户名”必须是命名空间限定的 - javax.xml.soap.SOAPException: Header child element 'username' must be namespace qualified java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException while Generating Java Class62104F65FACCBEE50 - java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException while Generating Java Class from WSDL java.lang.NoClassDefFoundError : javax/xml/soap/SOAPException - java.lang.NoClassDefFoundError : javax/xml/soap/SOAPException 调用Web服务时出现javax.xml.ws.soap.SOAPFaultException - javax.xml.ws.soap.SOAPFaultException when calling web service Java Web 应用程序在 weblogic 上调用 SOAP 服务在生产中不稳定 - Java web application calling a SOAP service on weblogic is unstable in production
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM