Pages

Sunday, 1 June 2014

Running a REST Client developed using JDeveloper as a standalone client

UseCase:
Suppose you have a working Jersey based RESTful client/proxy (java client) generated using JDeveloper, and, you want to use this proxy as a standalone code. This post describes how this usecase can be achieved.
JDeveloper version used : 12.1.2.0.0
Eclipse version : Kepler

Steps:
In JDeveloper
Add a main() method to your REST proxy code and run it. The log will show you some lines as below before displaying the response of your code.

D:\12.1.2\jdeveloper\mywork\RESTClientApp\.adf
D:\12.1.2\jdeveloper\mywork\RESTClientApp\Project1\classes
D:\12.1.2\oracle_common\modules\asm-3.1.jar
D:\12.1.2\oracle_common\modules\jersey-core-1.17.1.jar
D:\12.1.2\oracle_common\modules\jersey-server-1.17.1.jar
D:\12.1.2\oracle_common\modules\jersey-servlet-1.17.1.jar
D:\12.1.2\oracle_common\modules\jersey-json-1.17.1.jar
D:\12.1.2\oracle_common\modules\jersey-client-1.17.1.jar
 -Djavax.net.ssl.trustStore=......Dhttps.proxyHost=localhost -Dhttps.proxyPort=8099 project1.EmpRESTClient

Here, note down all the JARs that are listed out along with the location from where they are coming. You will use this location later to pick these JARs. You can then comment out the main method. Next, deploy the Client project as a JAR as shown.

                      


                      


In Eclipse
In Eclipse, create a new folder called 'lib' under a Java project. Copy the application JAR created by you earlier into this folder. Also, copy the JARs noted down on running the main method. and paste them in this 'lib' folder.
Refresh your app in Eclipse to see the newly added JARs. Now select all the JARs from withing the IDE and right click and select Build Path -> Add to Build Path.
Thats it! You should be able to consume the client coded in JDev easily.
If you miss out on some JAR, you will end up with ClassNotFoundExceptions.


No comments:

Post a Comment