Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP error code: 302 when calling https webservice

I am trying to call a SOAP RPC style web service and getting the following error:

Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 302:

This is a https web service and I have imported the certificate into cacerts thru browser but getting same result. Please note that, I can consume a REST webservice from the same machine without importing the certificate.

What I am missing when calling a SOAP service? Is it my client issue or something need to be done on the server side. I have access to the server.

like image 511
JoyLahi Avatar asked May 21 '14 16:05

JoyLahi


3 Answers

HTTP status code 302 is a redirect, and so is unlikely due to a certificate problem. My initial guess is that you need to add a / (or remove it) from your URL. Some http server frameworks will redirect when a resource does not end in a /, so, instead of:

GET /myRpcEndpoint

Try

GET /myRpcEndpoint/

The other possibility is that this resource requires authentication and the server is redirecting you to a login page. If you want to know what is going on (and not guess), take a look a the the response headers for the 302. There will be a Location header telling you where the server wants you to go instead.

like image 88
erik.j.johnson Avatar answered Oct 15 '22 01:10

erik.j.johnson


Had a similar issue where client code would receive a HTTP 302 error code when communicating with https and would work fine when communicating with http. In client code,you might need to specify the endpoint address on the request context using the BindingProvider.ENDPOINT_ADDRESS_PROPERTY property. Following the JAX-WS paradigm, the example below should work. Please note that only the BindingProvider.ENDPOINT_ADDRESS_PROPERTY needs to be defined, the rest of your code should remain the same.

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

    ObjectFactory factory = new ObjectFactory();

    GetProducts_Service service = new GetProducts_Service();
    GetProducts getProducts = service.getGetProductsPort();
    final BindingProvider getProductsBP = (BindingProvider) getProducts;
    getProductsBP.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
            "https://example.server.net/ExampleServicesWar/GetProducts");

    GetProductsRequest request = factory.createGetProductsRequest();        
    GetProductsResponse response=getProducts.getProducts(request);      
    List<Product> products=response.getProducts();

}
like image 33
Rami Del Toro Avatar answered Oct 14 '22 23:10

Rami Del Toro


All you have to is to use correct end point url

((BindingProvider)port).getRequestContext().put(BindingProvider.
        ENDPOINT_ADDRESS_PROPERTY, "https://yourservice");

Need to import at the top:

import javax.xml.ws.BindingProvider;

port is Method call:

full source:

private static String getApplicationStatus(java.lang.String remoteAccessKey, java.lang.Integer responseId) {
    net.quotit.oes._2010.ws.applicationstatusupdate.OASStatusUpdateService service = new net.quotit.oes._2010.ws.applicationstatusupdate.OASStatusUpdateService();
    net.quotit.oes._2010.ws.applicationstatusupdate.IApplicationStatusUpdate port = service.getStatusUpdate();
    ((BindingProvider)port).getRequestContext().put(BindingProvider.
        ENDPOINT_ADDRESS_PROPERTY, "https://servicename/basic");

    return port.getApplicationStatus(remoteAccessKey, responseId);
}
like image 35
Ramesh Bas Avatar answered Oct 14 '22 23:10

Ramesh Bas