'Java client using SAAJ error: SEVERE: SAAJ0008: Bad Response while calling a soap webservice

While calling a Soap web service through Java code I am getting bad response 302 found. If I hit same url through postman it gives a response.

Can anyone provide a reason and a solution for this problem

CODE:

// Create SOAP Connection

        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();

        SOAPConnection soapConnection = soapConnectionFactory.createConnection();



        // Send SOAP Message to SOAP Server

        String url = "http://localhost:8080/xyz";

        SOAPMessage soapResponse = null;

        try

        {

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

        }

        catch (SOAPException e)

        {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }

        catch (Exception e)

        {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }

Error:

Mar 01, 2022 8:29:10 PM com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection post SEVERE: SAAJ0008: Bad Response; Found com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (302Found at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(Unknown Source) at SeibelClient.main(SeibelClient.java:58) Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (400Bad request at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(Unknown Source) ... 2 more

Can anyone suggest a solution for this.

Also If I am hitting the url and the Soap message through postman it gives a response but while hitting through a java code it gives the above error.

Can it be a security or a certificate issue.

Also 302 is a redirected code but as you can see in the error it does not gives a new location



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source