Клиент Java, использующий ошибку SAAJ: СЕРЬЕЗНАЯ: SAAJ0008: неправильный ответ; НесанкционированныйJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Клиент Java, использующий ошибку SAAJ: СЕРЬЕЗНАЯ: SAAJ0008: неправильный ответ; Несанкционированный

Сообщение Anonymous »

Я написал клиентский код Java с использованием SAAJ для веб-сервисов Primevera P6. Я получаю следующую ошибку аутентификации. Я указываю имя пользователя и пароль http для кода, но он выдает ошибку: СЕРЬЕЗНАЯ: SAAJ0008: Bad Response; Несанкционированный. Может ли кто-нибудь помочь мне с этой проблемой. Я застрял в этой проблеме уже давно. Wsdl веб-службы: https://sunpower-p6.oracleindustry.com/ ... rvice?wsdl.

ОШИБКА:
Запрос сообщения SOAP =
11106
18 июля 2016 г., 13:03:19 com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection post
СЕРЬЕЗНЫЙ: SAAJ0008: плохой ответ; Несанкционировано
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Неверный ответ: (401Несанкционировано

Мой код:

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/ ... rvice?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());
}

}
}


Подробнее здесь: https://stackoverflow.com/questions/384 ... authorized
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»