Posts tagged restful

No JDBC based data retrieval in Java applications – RESTstyle, JSON formatted HTTP based interaction from Java to Database

This article demonstrates how Java application can query data from relational databases (well, in this case more specifically the Oracle RDBMS) without the use of plain old JDBC but instead through a simple HTTP interaction with a RESTful service that returns the data in JSON format.

In this way, issues with JDBC drivers, database connections, data sources and firewall and other network complications are avoided and the Java application does not contain a single bit of SQL.

Image

This article will demonstrate how easy it is to set up the RESTful API from the database – using Oracle’s dbms_epg package – and how this API can be accessed from Java using JAX-RS (Jersey) and the json-lib utility library.

This topic is one of many to be discussed in Friday’s (4th February) Masterclass on Leveraging the Oracle Database in Java Application (some seats are available – go to http://www.amis.nl/trainingen/oracle-database-in-java-applications for registration and details).

Read the rest of this entry »

SOA Suite 11g – Using Spring Component to mimic Http Binding and integrate RESTful services

In an earlier post, I showed for the Oracle SOA Suite 11g how we can use the Mediator's Java Callout functionality to integrate RESTful services into our SOA Composite applications, even though we currently have no Http Binding Service nor WSIF support (SOAP Java Binding) at our disposal in the SOA Suite – link to article.  In SOA Suite 11g PS1 – released in November 2009 – is the preview (not yet officially supported and only available for PoC and early trials – of Spring components. This feature provides another way of integrating Java classes into our SOA Composite applications.

This article demonstrates how we can use the Spring component to bind our SOA Composite Application to the RESTful Translation service provided by Google.

Read the rest of this entry »

The Oracle SOA Suite 11g HttpBinding or another way to call RESTful services from SOA Composite Applications

I wanted to take a quick look at REST(ful) WebServices and see how those can be integrated into the SCA based SOA Composite Applications that we create with the Oracle SOA Suite. Currently, it does not have the HTTP binding that the 10.1.3 release of the SOA Suite used to have. So what are the alternatives?

In this article, I want to demonstrate a way of calling RESTful (simple http request based) services into a SOA Composite application. I show one way of doing so using the Google Translation Service, a RESTful service described at http://code.google.com/apis/ajaxlanguage/documentation/ and to be accessed at http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hello%20world&langpair=en%7Cit. This service takes a string to translate and an indication of a source and a destination language. Though maybe not formally resource oriented enough to be called REST-style (or RESTful) service by some, it is a service that does not require SOAP or WS* but simply a HTTP Get request. So at least quite restful.

In this article I will use the work I did and described in the previous article: Leveraging RESTful Services from Java application using Jersey (Introduction). Using project Jersey's support for clients of RESTful services and the JSON-SIMPLE library to interpret the response I get from the GoogleTranslation service, I will hook up with the RESTful Service. Then I will leverage the Mediator Java Callout mechanism to integrate this REST-service-client into a SOA Composite application. The Mediator I create will be the fully SOA Suite integrated front-end of this RESTful Service.

Read the rest of this entry »

Leveraging RESTful Services from Java applications using Jersey (Introduction)

While researching for the Oracle SOA Suite 11g Handbook, I wanted to take a quick look at REST(ful) WebServices and see how those can be integrated into the SCA based SOA Composite Applications that we create with the Oracle SOA Suite. Currently, it does not have the HTTP binding that the 10.1.3 release of the SOA Suite used to have. So what are the alternatives? But first, how does one call a simple HTTP only (no SOAP/WS*) service from a piece of Java code? With as little programming and as much framework lifting as possible.

One of the frameworks available for RESTful operations is Jersey – a framework that should be more REST aware than plain HTTP communication oriented libraries like Apache HTTP Client, as well as offer some support for typical formats used in RESTful interactions, such as JSON, XML, RSS, CSV. So let’s create the simples Java application consuming a RESTful service – the Google Translation service – using the Jersey library.

Read the rest of this entry »

RESTful service based on ADF Business Components, publishing enterprise database contents the REST way

After three introductory and exploratory articles on RestLet, RESTful Services and the creation of the latter using the former in JDeveloper 11g as well as hooking it up with ADF, it is now time to create a more serious RESTful service. A service that exposes resources from an enterprise business service. One backed by a enterprise database. One that RESTfully provides access to the Human Resource data. In other words: we will publish RESTful services for DEPT and EMP in the SCOTT schema.

It really is simple. The steps are:

  • create default ADF BC business objects for the DEPT and EMP tables; this implicitly publishes a Data Control that exposes the data collections
  •  create a new JSF page; drag the EMP table to this page and drop it as master-detail (table-table); this implicitly creates a PageDefinition that fuels the BindingContainer we need for our services
  • create and configure a servlet filter that will take care of initializing the BindingContainer on every request
  • create Resource classes for Depts, Dept, Emps and Emp; these classes get the appropriate data binding from the BindingContainer, set the current row for Dept (all resources except Depts) and Emp (only for the Emp resource) and write the XML representation of the desired data
  • attach routes for all resources using appropriate URLs (/depts, /depts/{deptno}, , /depts/{deptno}/emps,  /depts/{deptno}/emps/{empno}
  • deploy the Web Application and access the RESTfule services from a browser or other Http-client

Let’s take it one step at a time:

Read the rest of this entry »

Publishing resources exposed by ADF Data Control in RESTful services using RestLet and JDeveloper 11g

The previous two articles on RESTful services using RestLet and developing in JDeveloper 11g – First Steps with RestLet 1.1RC2 in JDeveloper 11g – restful services 101 and Extending the RestLet application with support for POST/PUT to create and update Resources – used a static data set as source for the Resources. For real world services that will not be your typical scenario. Usually a business service hiding a persistence layer sitting on top of a database or wrapping a web service (RESTful or otherwise) is the more logical publisher of resources.

In this article, we will see how we can leverage ADF Model – Data Control & Data Bindings – to hook up such a business service. ADF Model publishes a Data Control for each Business Service it exposes. Through the Data Control applications can get access to data collections and operations acting on that data. For the application consuming the Data Control there should be no difference whether the underlying business service is an ADF BC application module connecting to a relational database, an EJB doing something similar, a web service published in the SOA of the organization or a RESTful service out there on the internet. That is at least the theory.

In this article, I will create a very simple Data Control, really nothing more than a mock object: a Placeholder Data Control. I will create a Thing data type and expose through the Placeholder Data Control a collection of Thing objects. The benefit of this approach is that we can take look at how ADF model can be used for providing the foundation for our RESTful services without the need for implementing a real business service. In a subsequent article we should find that the code we now write for the placeholder data control will work for ‘real’  data controls as well. .... Read the rest of this entry »

Extending the RestLet application with support for POST/PUT to create and update Resources

In a previous post – First Steps with RestLet 1.1RC2 in JDeveloper 11g – restful services 101 – I introduced RestLet and how to use it for creating very simple RestFul services in JDeveloper 11g. This contribution takes things a little further: the things and thing service discussed in the prior article only support read only operations: GET requests. In this article, we will add the ability to create and update things.

Since creation is done based on simple HTTP request of type POST, all we need for a Thing Create Client is a static HTML page with form that posts to the /things url of our RestFul service. The post request should contain the properties of the new thing we want to have created. It is up to the RestFul service to handle the post request. More specifically: the ThingsResource class will take on the Post request sent to the /things service and try to create a new thing based on it..... Read the rest of this entry »

First Steps with RestLet 1.1RC2 in JDeveloper 11g – restful services 101

WebServices are hot. Some more so than others. SOAP based WebServices are frequently seen as not very lean and agile. Robust – perhaps. Widely supported – no doubt about it. Key element of almost any SOA infrastructure – sure. Easy, lightweight to deploy or to program a client against – no, not really. Inituitive? Bookmarkable? Addressable? – none of those. Restful web-services are the easy to use, lightweight, navigation oriented complement to the more heavy weight WS* SOAP based web services. REST is the natural extension of HTTP – leveraging a lot of its potential in a very direct way. REST services focus on Resources – that are searched & retrieved, created, updated and deleted. Resources can refer to each other – through hyperlinks that equal new REST service calls. The representation of Resources – the format of the response received or sent by a client has to be agreed upon; it usually is XHTML, XML or plain text.

Under JSR-311, a formal specification for REST is being developed, with project Jersey – nearing its completion – the reference implementation. An even more mature Java project for RESTful services is RestLet – a fairly easy to use library that allows for easy publication of Restful services. Its main job is interpreting the URIs in requests sent to the server/service and routing them to the appropriate resource handler and more particularly the right method depending on the nature – GET, POST/PUT, DELETE – of the HTTP request.

In this article I will demonstrate a very first introduction to the use of RestLet with JDeveloper 11g..... Read the rest of this entry »