When a Consumer is hitting a third Party API which may require credentials. Without which the connection would not be possible.
There are a couple of ways on how to pass the credentials. They might vary depending upon the type of security set by the 3rd Party API. The credentials may be required as part of HTTP headers or as a part of SOAP envelope.
1. As part of SOAP Envelop -> The below piece of code is to be invoked after the object iApiSerivce has been created in the previous Post
There are a couple of ways on how to pass the credentials. They might vary depending upon the type of security set by the 3rd Party API. The credentials may be required as part of HTTP headers or as a part of SOAP envelope.
1. As part of SOAP Envelop -> The below piece of code is to be invoked after the object iApiSerivce has been created in the previous Post
@Component
@Service("rDC2Client")
public class RDC2ClientImpl<T, R> implements RDC2Client<T, R> {
private static final Logger LOG = LoggerFactory.getLogger(RDC2ClientImpl.class);
private static final String WS_URL = "http://testws.omer.co.in/apiservice/ApiService.svc?wsdl";
@WebServiceRef(wsdlLocation = WS_URL)
ApiService apiService;
public R processingRequest(final T object, final Class<R> clazz) throws RemoteException, SOAPException {
LOG.info("Starting ..processingRequest");
apiService = new ApiService();
// Retrieves a proxy to the service, also known as a port, by invoking getBasicEndpoint on the service.
IApiService iApiService = apiService.getBasicEndpoint();
final Binding binding = ((BindingProvider) iApiService).getBinding();
List<javax.xml.ws.handler.Handler> handlerList = binding.getHandlerChain();
if (handlerList == null)
handlerList = new ArrayList<javax.xml.ws.handler.Handler>();
handlerList.add(new SecurityHandler());
binding.setHandlerChain(handlerList);
String entryResponse = iApiService.enterIdea(ideaXml, null, null);
return result;
}
}
No comments:
Post a Comment