Create A Simple Web Service From Java Code Using Jdeveloper
Create A Simple Web Service From Java Code Using Jdeveloper
Create A Simple Web Service From Java Code Using Jdeveloper
Oracle
Blogs Home
Products & Services
Downloads
Support
Partners
Communities
About
Login
Oracle Blog
We will use bottom up development, meaning we will create a new web service based on existing Java code.
The following instructions will create a new application and add a project to contain the web service.
Start JDeveloper.
Select Application-> New from the Main Menu.
In the Create Generic Application dialog set the application Name to WebServiceExamples
Select Generic Application and choose the Next button
https://blogs.oracle.com/bwb/resource/webservices/Create_a_simple_Web_Service_fr... 27/02/2014
Create a simple Web Service from Java Code using JDeveloper Page 2 of 7
Select the Next button and set the Default Package to departmentdetailsservice
DepartmentFinder.java - This is the main class, it will return the details for a given department number.
DepartmentDetails.java - This java bean contains the department details for a given department.
Fault.java - This class represents a ault that can be returned when an error occurs.
In the Application Navigator pane, right click on the DepartmentDetailsService project and select New.
Select Java from the General Category on the left and select Java Class from the item list on the right.
Press the Ok button.
https://blogs.oracle.com/bwb/resource/webservices/Create_a_simple_Web_Service_fr... 27/02/2014
Create a simple Web Service from Java Code using JDeveloper Page 3 of 7
Next open the DepartmentFinder.java class and replace the default file contents
with the code in the following file.
DepartmentFinder.java
DepartmentDetails.java
DepartmentFinderFault.java
FaultBean.java
We can test the class using the main() method in the DepartmentFinder class.
Right click on the DepartmentFinder.java file in the Application Navigator and choose Run
https://blogs.oracle.com/bwb/resource/webservices/Create_a_simple_Web_Service_fr... 27/02/2014
Create a simple Web Service from Java Code using JDeveloper Page 4 of 7
Connect to the Enterprise manager console using a browser, and supply the credentials defined for your weblogic server
For example http://localhost:7001/em weblogic/welcome1
Expand the Farm node and locate the Application Deployment named
WebServicesExamples-DepartmentDetailsService-context-root(AdminServer)
The server name in parenthesis indicates the server hosting the deployment, your server name may differ from the one shown above.
Select the node and press the Test Icon under the Web Services Section in the right pane.
https://blogs.oracle.com/bwb/resource/webservices/Create_a_simple_Web_Service_fr... 27/02/2014
Create a simple Web Service from Java Code using JDeveloper Page 5 of 7
After a second or so the Response button tab should be automatically selected and the service results displayed.
https://blogs.oracle.com/bwb/resource/webservices/Create_a_simple_Web_Service_fr... 27/02/2014
Create a simple Web Service from Java Code using JDeveloper Page 6 of 7
This service is now available and can be consumed by Mediator or BPEL components.
Note the url for the WSDL of the deployed web service is available in the WSDL field in the top of the test page.
For example
http://10.0.2.15:7001/WebServiceExamples-DepartmentDetailsService-context-root/DepartmentFinderPort?wsdl
Pasting this url into a browser should return the wsdl for the service.
This url will be required when creating partner links to the service.
Finishing Touches
Here is the updated getDepartmentByMgrEmailId() showing both @WebMethod and @WebParam annotations
@WebMethod
public DepartmentDetails getDepartmentByMgrEmailId(@WebParam(name = "mgrEmailId")
String mgrEmailId) throws DepartmentFinderFault {
https://blogs.oracle.com/bwb/resource/webservices/Create_a_simple_Web_Service_fr... 27/02/2014
Create a simple Web Service from Java Code using JDeveloper Page 7 of 7
Changes to the service interface such as adding annotations require the wsdl to be regenerated.
Right click on the DepartmentFinder.java source file and choose-> Web Service Properties from the Context Menu.
In the resulting dialog select the methods entry, confirm the available get Methods are all selected and Press the OK button.
The WSDL will be regenerated
https://blogs.oracle.com/bwb/resource/webservices/Create_a_simple_Web_Service_fr... 27/02/2014