How Does The Json Web Services Workspace Work
This tutorial guides you through the steps of creating a simple Oracle Mobile Awarding Framework (MAF) application based on a REST-JSON spider web service.
Read more...
| Assumptions: |
|---|
| To consummate this tutorial you lot must have installed JDeveloper 12.one.3 and have installed the MAF Extension. Y'all must as well take the Android SDK version iv.2.two API level 17 installed. If yous choose, you tin deploy the application to a connected Android device. The tutorial demonstrates deploying the application to an Android emulator. You launch the emulator using the Android Virtual Device (AVD) Director, which is part of Android SDK Tools. If you are using an iOS surroundings, you tin utilize the post-obit tutorial to set up the development surroundings: Set Up and Configure an iOS Environment. If you lot are using an Android environment, yous can use the following tutorial: Set Up and Configure an Android Environs. You must have admission to an Oracle enterprise or XE database that has the Oracle Hr sample schema installed and unlocked. This tutorial is for people who are new to Residual services, merely is not a. For your convenience, almost of the implementation lawmaking is provided for you in text files you find in the tutorial's Doctor / CODE_TXT binder. That mode information technology volition save you from typing the code lines directly, you can simply re-create and paste. We'll explain what each piece of lawmaking does as nosotros go along. |
Sample Implementation Overview
The sample application that you build by following the hands-on instructions uses helper classes on the mobile client to access the remote JSON Residuum service and to parse the JSON payload into Java objects.
This tutorial guides yous through the steps of creating a sample Oracle Mobile Awarding Framework (MAF) application based on a Residuum-JSON spider web service.
To save you from typing and to proceed you focused on building the mobile application, most of the Java content has been pre-built for yous to re-create and paste the code when needed. This tutorial reinforces spending time developing a sensible client infrastructure which simplifies your work and supports MAF all-time practices.
The paradigm beneath, shows the course hierarchy used by this sample. The DeptEmpDC data service class exposes collections of departments and employee data as well as methods to dispense information, which is create, update and delete. The data service class is what yous expose equally the MAF data control – thus the file name postfix "DC".
The DepartmentsEntity and EmployeesEntity classes stand for data objects, as well known as entities. These are the classes that carry departments and employee state and are used in MAF to display and update data.
When data is read to or from Balance services, some additional processing is required. In our example, two helper classes (DepartmentsResultArray and EmployeesResultArray) take intendance of the JSON conversion. Each class mimics the structure of a specific JSON payload so that a MAF specific framework class can exist used to copy the contents of a JSON payload into the Java object structure.
The DepartmentsEntityToJson class and the equivalent for the employees entity class translates Coffee objects back to a JSON format for the write operations.
Finally the DeptEmpURI form contains methods that render the request URIs for a specific REST request like search, update, read and delete. The helper class really saves the developer to need to know about the available Residuum URIs on the server side. The form abstracts mobile awarding development from the server side REST implementation.
The RestCallerUtil course wraps the MAF calls to the Rest service, thus further simplifying the REST interaction, avoiding you to write unnecessary boilerplate code over and over once again.
This is not a tutorial on writing Rest services and thus this certificate simply explains what the service does and how to deploy the service to a local Weblogic Server example.
| Purpose | Duration | Awarding |
|---|---|---|
This tutorial shows you how to develop an application with Mobile Application Framework and REST JSON services. To run into the completed awarding for this tutorial, starter application and code files, click the Download button to download a aught of the the solution awarding, and unzip it to your JDeveloper mywork folder. Solutions for other tutorial parts tin be downloaded at the beginning of each part. | ii.5 hours | |
First, you demand to open up the sample workspace that contains the Residue service sources and then configure the database connexion to point to your local database and Hour schema.
-
Unzip the tutorial maf_rest_json_files zip file to the machine that has Oracle JDeveloper installed.
-
Re-create the TutorialHrRestService sample resource folder located in the MAF REST Tutorial/ MAF_REST_SRC directory to a local directory path that does not have a blank character in its name. Note that failing to do so may cause a problem when testing the MAF mobile application on the Android emulator.
-
Open Oracle JDeveloper 12.one.3
-
Select Awarding > Open from the menu.
-
Browse to the location you copied the TutorialHrRestService folder to, open it and select the TutorialHrRestService.jws workspace file.
Press OK to open the file in JDeveloper. -
Oracle JDeveloper should testify 2 projects: EjbHrModel, the EJB project that queries and updates the database, and RestService, the JAX-RS annotated POJO project that exposes functionality of the EjbHrModel projection as Residue service.
The EJB model that is exposed past the REST service is built on top of the Departments and Employees tables in the Oracle HR sample schema.
-
Select Window > Database > Databases from the JDeveloper card to open the database configuration browser window.
-
Click the Databases tab in the JDeveloper Applications window.
So expand the TutorialHrRestService node and select the hrconn entry with the right mouse button. -
In the opened menu, select Backdrop.
-
In the opened Edit Database Connections dialog, change the configuration settings for Username, Countersign, Host Name, JDBC Port and SID according to your local database setup and Hr schema installation. If you lot run an XE database, the pre-configured setting may already be sufficient.
-
Click the Test Connection push to verify the database connection working
And then, OK the dialog when your connection works.
.
For this tutorial, the integrated WLS in Oracle JDeveloper is used for deploying and testing the REST service.
-
Start the Oracle WebLogic Server (WLS) by selecting Run -> Start Server Instance (IntegratedWebLogicServer).
-
If this is the first time you lot've run the integrated Oracle WLS, a Create Default Domain dialog box will open up. Create and set the password for the default Oracle WLS domain.
Note: For the integrated Oracle Web Logic Server to mind for all of the aliases that indicate to your motorcar including "localhost" and the IP address of your figurer, don't select an accost from (Listen Address).
-
Click OK to save your changes and to create and configure the default domain for Oracle ADF. The Oracle WebLogic Server will create a default domain and start the server..
-
Await for the integrated Oracle WLS to commencement before proceeding to the steps in the next department. The first time you start the server, it builds the WLS domain, which may take several minutes.
Working with Residual is all about working with resource addressed past compatible resource locators (URLs). The term resources is abstruse in REST and tin range from a person, an order, or a booking to a list of employees, rows queried from a database table, and more than.
In this tutorial service, the resources that are exposed are Departments and Employees from the Hr schema. The information query is performed by an EJB / Toplink model that is exposed to the mobile customer through a Residual service developed with JAX-RS annotated POJO classes. In the following yous volition explore and test the REST service using the Oracle JDeveloper HTTP Analyzer to learn well-nigh the configured REST URIs and how to work with them.
-
In Oracle JDeveloper, switch to the Applications tab and expand the RestService project node.
-
Expand the Awarding Resources node and the maf.lawmaking.corner.sample.rs parcel within
You see four packages -
Expand the services package node and select the HrRestService entry with the correct mouse button.
Then, select Examination Web Service from the context menu to run the Residue service in the JDeveloper Http Analyzer.
-
JDeveloper deploys the Exam service to the integrated WLS server instance and should open the HTTP Analyzer for you. The HTTP Analyzer allows you to scan the available Residuum URI mappings and to run them to verify the service.
If not already displayed, open the JDeveloper log window using Window > Log from the menu. The log window shows the progress of the Residuum service deployment but also all errors that potentially may occur when testing the Remainder service.
In case of a successful deployment you should see two links at the finish of the log messages, a WADL (Spider web Application Description Linguistic communication) reference and the Target URL reference showing the REST Service root URL. The root URL, http://127.0.0.1:7101/hrrest/resources/hrappsrvc, will be needed later in MAF to create the REST connection. The WADL file provides a description of the REST service, list all the methods and responses. You can click the WADL link and and so test the Residue service from there if you like.[Application TutorialHrRestService running on IntegratedWebLogicServer]
Target Application WADL -- http://localhost:7101/hrrest/resources/awarding.wadl
Target URL -- http://127.0.0.1:7101/hrrest/resources/hrappsrvc
-
The Http Analyzer should open up directly after deployment displaying the URL, WADL URI and possible operations.
-
In the Operations belongings, open the list of available operations to see a listing of methods and Residuum URI mappings.
Then, expand the departments node and select the getDepartmentsList GET entry.Hint: If you don't see the list, ensure the Residue Structure tab at the bottom of the HTTP Analyzer window is selected.
-
Find the value of URL field: http://localhost:7101/hrrest/resources/hrappsrvc/departments. The URL field shows the Residuum URL that the Get request utilize. The getDepartmentsList is the method that is mapped to the URI, an implementation particular you run into in the HTTP analyzer during testing only not later in MAF.
Printing the Ship Request push to issue a Get asking to the deployed service URL.
-
Based on the configuration, you should see a JSON response showing a list of departments, similar to the image below.
-
Expand the Request HTTP Headers section above the Ship Request push button.
-
Change the value for the Take header property so information technology only contains awarding/xml. Then, click into another header field to have the change the to Accept header
-
Printing the Send Request button again and you lot should see the aforementioned listing of departments returned from the Balance service, this time in XML format.
-
Side by side, lets create a new department. In the Operations listing, select create PUT awarding/json to signal the type of JSON formatted REST request.
Like earlier , the request is issued to the http://localhost:7101/hrrest/resources/hrappsrvc/departments REST URL. This fourth dimension however the http method used is PUT, which is mapped to a method in the Residue Java implementation that creates a new section.
Complete the input form as shown in the image below and press the Send Request button. As a response y'all should see the message displayed below the Response HTTP Headers label on the correct side of the analyzer.
-
In JDeveloper, select Window > Database > Databases from the carte. Expand the TutorialHrRestService > hrconn > Tables nodes.
-
Double click on the Departments table entry.
Then, click on the Data tab at the bottom of the tabular array overview editor and scroll down to detect the newly created tape.
Then, shut the Departments table tab and switch back to the HTTP Analyzer.
-
In the Operations list, expand the departments > remove/{departmentId} node and select the delete DELETE entry.
-
Detect the change in the URL field
http://localhost:7101/hrrest/resources/hrappsrvc/departments/remove/departmentId
Replace the departmentId part of the URL with the value 1234, so it now reads: http://localhost:7101/hrrest/resources/hrappsrvc/departments/remove/1234
In the URL, the departmentId appendix is a URL parameter that the REST service interprets for the DELETE method.
-
Click the Send Asking button again for the Balance service to remove department 1234. In the HTTP Analyzer tab, you should encounter a 200 OK message for the DELETE method, as the response. This indicates the row has been deleted from the database.
If you check the data in the Departments tab, yous'll meet the grooming department is no longer listed.
-
Open the Operations listing again and expand the departments > {departmentId}/employees node. Then, select the getEmployeesInDepartment GET entry.
-
Change the URL field value from
http://localhost:7101/hrrest/resource/hrappsrvc/departments/departmentId/employees
to
http://localhost:7101/hrrest/resource/hrappsrvc/departments/60/employees
which will query all employees working in the IT department (60) and press the Send Request button. As a outcome a JSON formatted response should be shown as in the image below.
Notation: The response payload is JSON equally configured in the REST service for requests that take JSON and XML.
If you change the Take header value for the request to awarding/xml only and so the same request would return XML as the response format.
Besides the JSON string is displayed with a "{" at the offset and a "}" at the end with the "employees" string containing the employee collection.In JSON, collections are surrounded with foursquare brackets "[" and "]" and objects are once more surrounded by curly braces, "{" and "}".
Too, JSON payloads are quite flexible and tin can contain a mix of single key:value pairs, collections or objects.
-
As an optional task, get back to the log window and click on the WADL link displayed in the log output to open the WADL overview editor record.
Use the WADL dialog to further explore and test (pressing the Exam button adjacent to a URI entry) the Remainder Service. The test button brings you back to the HTTP analyzer with the URL prepare to the request URI you lot want to test.
lists : Contains helper classes, to work with JAXB for Java object to XML and JSON conversion
resources : Holds the implementation classes of the departments and employees resource. This is where JAX-RS annotations are added to configure and map methods to REST URIs. For readability and manageability, the actual code that accesses the EJB layer is defined in classes in the base package. The two classes in the resources bundle merely contain Residue specific code and annotations
services : Contains Departments and Employees resources which are accessible from a single root service, the HrRestService. This class contains the root URI annotation and beside of this dispatches to the two classes in the resources bundle. The HrRestService.coffee class is the Residuum service that you will actually run and test.
xsd : The XSD schema files are required if yous wanted to configure the REST service with its XML payload in MAF. Doing so tells the JDeveloper IDE which payload structure is returned or expected by a REST URI phone call allowing the correct data command structure to exist generated automatically.
In this pace, create the MAF mobile customer workspace to hold all the component for application.
-
In JDeveloper, select File > New > Application from the menu and in the New Gallery, select General > Applications > Mobile Awarding Framework Application.
Then click OK. -
Set the Application Name to MAFREST and maf.code.corner.hr as the Application Parcel Prefix.
Make sure the Directory holding does non contain any blank characters, as this may cause issues during deployment.
Then click End (this will keep the default naming conventions, which is ApplicationController and ViewController for the workspace projects). -
The applications needs to access the web services through the device'due south network.
In Application Resource, open up the in maf-application.xml and in the Device Admission, select the Network checkbox.
Your MAF application needs a connectedness to access the REST service. In a existent world situation, the Residue service could be housed on a remote server, with the database on a different i. However in this tutorial, everything is local to the development machine. Here is the root URL to access the Residual service:
http://127.0.0.1:7101/hrrest/resource/hrappsrvc
Note: If the URL of the deployed Remainder service changes, you tin can hands change the root URL or set up it to contain either the host proper noun or IP address.
In this next section, create the connection to access the Balance service..
-
With the correct mouse button, click onto the ViewController project node and select New > From Gallery.
Expand the Full general > Connections nodes and select the Remainder Connection item.
Click OK.
-
Utilise the values below to populate the Create REST Connection dialog and click the Exam Connection to verify access to the REST service.
Name DeptEmpRestConn URL Endpoint http://127.0.0.ane:7101/hrrest/resources/hrappsrvc
Note: Yous tin can modify your Residue, or whatsoever, connection past expanding the Application Resources > Connections > REST nodes and selecting DeptEmpRestConn. Then, right click on it and select the Properties menu choice.
In the rest of the tutorial, you will piece of work with the connection name and not the physical Balance URL that it represents.
-
If you lot use the Android emulator for testing, localhost (127.0.0.1) volition not work for testing and you need to utilize 10.0.2.2 as the host address. This is a special alias to your host loopback interface. Set the REST connexion equally shown in the image below and change the localhost (127.0.0.i) reference to 10.0.2.two.
Note: Alternatively to 10.0.ii.2 you can use the real IP accost that is assigned to your figurer (assuming your computer is in a network).
You have now completed the first part of this tutorial. In the next part, you add the classes to implement the client infrastructure.
Expand all | Hide all
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
How Does The Json Web Services Workspace Work,
Source: https://docs.oracle.com/cd/E53569_01/tutorials/tut_jdev_maf_json/tut_jdev_maf_json.html
Posted by: boydreste1954.blogspot.com

MAF
0 Response to "How Does The Json Web Services Workspace Work"
Post a Comment