首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用SAAJ错误的Java客户端:严重: SAAJ0008:不良响应;未经授权

使用SAAJ错误的Java客户端:严重: SAAJ0008:不良响应;未经授权
EN

Stack Overflow用户
提问于 2016-07-18 17:16:16
回答 1查看 7.9K关注 0票数 1

我为Primevera P6 for服务编写了一个使用SAAJ的Java代码。我收到以下身份验证错误。我正在为代码提供http用户名+密码,但它会产生错误:严重: SAAJ0008:错误响应;未经授权。有谁能帮我解决这个问题吗?很久以来,我一直困在这个问题上。web服务的wsdl是:https://sunpower-p6.oracleindustry.com/p6ws-token/services/ProjectService?wsdl

错误:请求SOAP消息= 11106 20167.18 1:03:19 com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection发布严重: SAAJ0008:坏响应;未经授权的com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:坏响应:(401未经授权)

我的代码:

代码语言:javascript
复制
public class TestClient {

    /*
     Method used to create the SOAP Request
    */
    private static SOAPMessage createSOAPRequest() throws Exception {

        // Next, create the actual message
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage    soapMessage    = messageFactory.createMessage();
        SOAPPart       soapPart       = soapMessage.getSOAPPart();


        String serverURI = "http://xmlns.oracle.com/Primavera/P6/WS/Project/V2";

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

        //start: setting HTTP headers - optional, comment out if not needed
        String      authorization = Base64Coder.encodeString("xyz:abc");
        MimeHeaders hd            = soapMessage.getMimeHeaders();
        hd.addHeader("Authorization", "Basic " + authorization);
        //end: setting HTTP headers

        // Create and populate the body
        SOAPBody soapBody = envelope.getBody();

        // Create the main element and namespace
        SOAPElement soapBodyElem  = soapBody.addChildElement("ReadProjects", "ProjectService");
        SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("Field", "ProjectService");
        SOAPElement soapBodyElem2 = soapBodyElem1.addChildElement("Id", "ProjectService");
        soapBodyElem2.addTextNode("11106");

        hd.addHeader("SOAPAction", serverURI + "ReadProjects");

        // Save the message
        soapMessage.saveChanges();

        // Check the input
        System.out.println("Request SOAP Message = ");
        soapMessage.writeTo(System.out);
        System.out.println();
        return soapMessage;
    }

    /**
     * Method used to print the SOAP Response
     */
    private static void printSOAPResponse(SOAPMessage soapResponse) throws Exception {
        // Create the transformer
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer        transformer        = transformerFactory.newTransformer();

        // Extract the content of the reply
        Source sourceContent = soapResponse.getSOAPPart().getContent();

        // Set the output for the transformation
        System.out.println("\nResponse SOAP Message = ");
        StreamResult result = new StreamResult(System.out);
        transformer.transform(sourceContent, result);
        System.out.println();
    }

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

        try {
            // First create the connection
            SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
            SOAPConnection        soapConnection        = soapConnectionFactory.createConnection();
            //System.out.println(soapConnection);

            //Send SOAP Message to SOAP Server
            String url = "https://sunpower-p6.oracleindustry.com/p6ws-token/services/ProjectService?wsdl";
            // Send the message and get the reply
            SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);

            // Process the SOAP Response
            printSOAPResponse(soapResponse);

            soapConnection.close();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }
}
EN

回答 1

Stack Overflow用户

发布于 2017-02-28 14:52:25

我意识到这是一个老问题,但我想给将来在这里结束的任何人留下一些帮助(就像我一样)。在这方面,我最近经历过一些可能的情况。

  1. 检查您的详细信息是否正确,或连接是否可能。在继续前进之前,要百分之百肯定。
  2. 如果您的数据库没有为某些设置正确配置(例如,在JBoss上),您将收到未经授权的错误。在我的情况下,当数据源文件试图连接时没有正确读取,导致客户端出现未经授权的错误。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38442507

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档