Ошибка saaj: плохой отклик 302

Я делаю с java saaj клиент веб-службы. Я проверил свой код на веб-сервисе без аутентификации. Там все отлично работает. Но когда я тестирую его на веб-сервисе с аутентификацией, я получаю сообщение об ошибке: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Неверный ответ: (302Перемещено временно

Я отладил его, и в основном возникает ошибка, когда я вызываю "createsoaprequest", я думаю. Но обычно мой код для отправки пользовательских данных правильный.

Веб-сервис использует базовую HTTP-аутентификацию.

закрытое статическое SOAPMessage createSOAPRequest() создает исключение {

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

    String serverURI = "http://www.nedap.com/aeosws/schema";
    System.out.println("2");
    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("ProjectService", serverURI);
    System.out.println("3");
    //start: setting HTTP headers - optional, comment out if not needed
    String username = "administrator";
    String password = "admin";

    String authorization = new sun.misc.BASE64Encoder().encode((username+":"+password).getBytes());
    MimeHeaders hd = soapMessage.getMimeHeaders();
    hd.addHeader("Authorization", "Basic " + authorization);
    //end: setting HTTP headers
    System.out.println("4");

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

    // Create the main element and namespace
    SOAPElement soapBodyElem = soapBody.addChildElement("EmployeeAdd", "ProjectService");
    SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("LastName", "ProjectService");
    soapBodyElem2.addTextNode("a");
    System.out.println("5");

    hd.addHeader("SOAPAction", serverURI  + "ReadProjects");
    System.out.println("6");
    // Save the message
    soapMessage.saveChanges();
    System.out.println("7");

    // Check the input
    System.out.println("Request SOAP Message = ");
    soapMessage.writeTo(System.out);
    System.out.println();
    System.out.println("8");
    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 {
        System.out.println("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
        // First create the connection
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        System.out.println("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeedddddddddddddddddd");
        SOAPConnection soapConnection = soapConnectionFactory.createConnection();
        System.out.println("10");
        System.out.println(soapConnection);

        //Send SOAP Message to SOAP Server
        String url = "http://gtstvs01:8080/aeosws?wsdl";
        System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaa");
        // Send the message and get the reply
        SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
        System.out.println("aaaazzzzzzzza");
        // Process the SOAP Response
        printSOAPResponse(soapResponse);

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

}

}

0 ответов

Другие вопросы по тегам