Deploying Services to OC4J with RESTful support
OC4J container provide support for RESTful services. OC4J installation comes with web service assembling tool (wsa) which take an extra optional parameter to give REST support. This post explains step by step approach to implement and deply RESTful services to OC4J.
1. Interface Code
package demo.service;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface StringService extends Remote{
public String toUppercase(String str) throws RemoteException;
public String toLowerCase(String str)throws RemoteException;
}
2. Implementation for Interface
package demo.service;
import java.rmi.Remote;
import java.rmi.RemoteException;
public class StringServiceImpl {
public StringServiceImpl() {
}
public String toUppercase(String str){
return str.toUpperCase();
}
public String toLowerCase(String str){
return str.toLowerCase();
}
}
3. Compile these files and put under classes folder
4. Use following command to run WSA tool to generate archive file , use proper paths
java -jar D:\jdev10134\webservices\lib\wsa.jar -assemble -appName StringApplication -serviceName StringService -interfaceName demo.service.StringService -className demo.service.StringServiceImpl -input ./classes/ -output build -use literal -ear dist/tools.ear -uri StringServices -restSupport true
Here in this command, restSupport is appended to command so that WSA tool treat the service as RESTful.
5. Above command creates two folders build and dist.
6. Deploy dist/*.ear file to OC4J instance through admin console
7. Use following url to invoke service
http://localhost:8888/StringApplication/StringServices/toLowerCase?String_1=INPUT
Output will be :
<ns0:toLowerCaseResponseElement xmlns:ns0="http://demo.service/">
<ns0:result>yogesh</ns0:result>
</ns0:toLowerCaseResponseElement>
Things to Notice:
URL is made up as
http://<host_address>:<port>/<application_name>/<Service_name>/<operation_name>?<param_name>=”<value>”
Here you will find <service_name> and <application_name> are mentioned as per wsa command parameters, <operation_name> and <param_value> will present in generated WSDL file under build directory.
Comments
Post a Comment