Thursday, 28 July 2016

Accessing SOAP Web Services Using JAX WS

1. The 3rd Party has published its Web service and shared the wsdl, Lets saythe wsdl is named
http://testws.omer.co.in/apiservice/ApiService.svc?wsdl

2. As a Consumer of the above wsdl, first the Entities and Services need to be extracted from the wsdl provided

This can be done using a tool which is a part of JDK i.e. wsimport

The command that is to be executed is as below :
C:\>wsimport -keep -verbose http://testws.omer.co.in/apiservice/ApiService.svc?wsdl
parsing WSDL...

generating code...
com\omer\ws\ApiService.java
com\omer\ws\IApiService.java
ApiService.java -> would contain all the connection details which would be used to connect to server at the 3rd Party server
IApiService -> this would contain the services that are to be used by the Consumer

Below is the piece of Client code

@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;
@SuppressWarnings("rawtypes")
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. 
// The name of the endPoint / Port may vary through out Web Services depending on how they have been written
IApiService iApiService = apiService.getBasicEndpoint();
String entryResponse = iApiService.enterIdea(ideaXml, null, null);
R result = jaxbMarshallingService.unMarshalling(entryResponse, clazz);
return result;
}
}


Volatile keyword, Synchronized keyword and Lock interface

Volatile Marking a member variable as volatile, makes sure, when ever the member variable is accessed, its value is always read from the...