Search code examples
javajakarta-eejax-rsjax-ws

Unsupported Content-type:application/json in java webservice call


I am able to set content type using cxf library but I don't know how to set Authorization header. Whenever I set user name and password then it set Authorization header and encode whole value and add Basic. I don't want to do this. I want to add Authorization header with plain string which ever I provide. Please help me to solve out this problem.

AMPServices services = new AMPServices();
        CoreXmlPort coreXmlPort = services.getAMPSoapService();
        Client client = ClientProxy.getClient(coreXmlPort);           

        HTTPConduit httpConduit = (HTTPConduit) client.getConduit();

        HTTPClientPolicy httpClientPolicy=httpConduit.getClient();
        String contentType=httpClientPolicy.getContentType();
        contentType="application/soap+xml; type=vnd.iShip.AMP.SOAP; charset=UTF-8";
        httpClientPolicy.setContentType(contentType);

        AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
        authorizationPolicy.setUserName("username");
        authorizationPolicy.setPassword("password");

        httpConduit.setAuthorization(authorizationPolicy);

It generates following request xml.

POST https://api.iship.com/Root/Enterprises/Pitney%20Bowes/Progistics; HTTP/1.1
Content-Type: application/soap+xml; type=vnd.iShip.AMP.SOAP; charset=UTF-8
Accept: */*
Authorization: Basic aXNoaXAgcGIvd3NkZXZlbDowNzZhNjFjYTM5MDcxODAxODVjNWRkMjM2YTdkMzZhNGQ1ODg5OWFj
User-Agent: Apache CXF 3.1.0
Cache-Control: no-cache
Pragma: no-cache
Host: api.iship.com
Connection: keep-alive
Content-Length: 246

But I want this type of request

POST https://api.iship.com/Root/Enterprises/Pitney%20Bowes/Progistics; HTTP/1.1
Content-Type: application/soap+xml; type=vnd.iShip.AMP.SOAP; charset=UTF-8
Accept: */*
Authorization: username;password
User-Agent: Apache CXF 3.1.0
Cache-Control: no-cache
Pragma: no-cache
Host: api.iship.com
Connection: keep-alive
Content-Length: 246

But I was not able to do it. Please help me to solve out this problem.

Thanks, Awadhendra


Solution

  • I think you are trying to call is a RestFul Service, so that's why the server side always response with a different content type than you expected (json instead of soap/xml). Is your url endpoint based on http protocol? If yes, do you need send additional parameters to this url?