Clients
C Client Library
Introduction
The C module generates the source code for the ANSI-C-compatible data structures and (de)serialization functions that can be used in conjunction with libxml2 to (de)serialize the REST resources as they are represented as XML data.
The generated C source code depends on the XML Reader API and the XML Writer API as well as the <time.h>
, <string.h>
, and <stdlib.h>
C standard libraries.
REST XML Example
#include <rsb.c>
//...
xmlTextReaderPtr reader = ...;
//set up the reader to the url.
rsb_rest_data_resultsType *response_element = ...;
response_element = xml_read_rsb_rest_data_resultsType(reader);
//handle the response as needed...
//free the rsb_rest_data_resultsType
free_rsb_rest_data_resultsType(response_element);
Files:
- rsb.c
- enunciate-common.c: common code needed for all projects
.NET Client Library
Introduction
The .NET client-side library may be used to access the SOAP API for this application via the .NET runtime.
.NET Service Example
//instantiate a new service...
MtomJobProcessor service = new MtomJobProcessor();
//make the remote call...
result = service.Process(job);
//handle the result as needed...
The .NET client-side library defines the classes that can be (de)serialized to/from XML. This is useful for accessing the REST endpoints that are published by this application.
REST Example
//read a resource from a REST url
Uri uri = new Uri(...);
XmlSerializer s = new XmlSerializer( typeof( Results ) );
//Create the request object WebRequest req =
WebRequest.Create(uri);
WebResponse resp = req.GetResponse();
Stream stream = resp.GetResponseStream();
TextReader r = new StreamReader( stream );
Results order = (Results) s.Deserialize( r );
//handle the result as needed...
Files:
- rsb-dotnet.zip: bundle of C# code
Java Client Library
Introduction
The Java client-side library is used to access the Web service API for this application.
The Java client-side uses JAX-WS to access the SOAP API for this application.
JAX-WS Example
// instantiate a new service with an impl
// (or through dependency injection, or whatever)...
MtomJobProcessor service = new MtomJobProcessor();
//make the remote call to read the result...
result = service.process(job);
//handle the result as needed...
The JAX-WS client-side library is used to provide the set of Java objects that can be serialized to/from XML using JAXB. This is useful for accessing the REST endpoints that are published by this application.
REST Example (Raw JAXB)
java.net.URL url = new java.net.URL(baseURL + "/results/{applicationName}");
JAXBContext context = JAXBContext.newInstance( Results.class );
java.net.URLConnection connection = url.openConnection();
connection.connect();
Unmarshaller unmarshaller = context.createUnmarshaller();
Results result = (Results) unmarshaller.unmarshal( connection.getInputStream() );
//handle the result as needed...
REST Example (Jersey client)
com.sun.jersey.api.client.Client client = com.sun.jersey.api.client.Client.create();
Results result = client.resource(baseUrl + "/results/{applicationName}") .get(Results.class);
//handle the result as needed...
Files:
- rsb-client.jar: the binaries for the Java client library
- rsb-client-sources.jar: the sources for the Java client library
Java JSON Client Library
Introduction
The Java client-side library is used to provide the set of Java objects that can be serialized to/from JSON using Jackson. This is useful for accessing the JSON REST endpoints that are published by this application.
REST Example (Raw Jackson)
java.net.URL url = new java.net.URL(baseURL + "/results/{applicationName}");
ObjectMapper mapper = new ObjectMapper();
java.net.URLConnection connection = url.openConnection();
connection.connect();
Results result = (Results) mapper.readValue( connection.getInputStream(), Results.class );
//handle the result as needed...
Files:
- rsb-json-client.jar: the binaries for the Java JSON client library.
- rsb-json-client-sources.jar: the sources for the Java JSON client library.
Objective C Client Library
Introduction
The Objective C module generates the source code for the Objective C classes and (de)serialization functions that can be used in conjunction with libxml2 to (de)serialize the REST resources as they are represented as XML data.
The generated Objective C source code depends on the XML Reader API and the XML Writer API as well as the base OpenStep foundation classes.
REST XML Example
#import <rsb.h>
//...
RSBREST_DATAResults *responseElement;
NSData *responseData;
//data holding the XML from the response.
NSURL *baseURL = ...;
//the base url including the host and subpath.
NSURL *url = [NSURL URLWithString: @"/results/{applicationName}" relativeToURL: baseURL];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
NSURLResponse *response = nil;
NSError *error = NULL;
[request setHTTPMethod: @"GET"];
//this example uses a synchronous request,
//but you'll probably want to use an asynchronous call
// responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
// RSBREST_DATAResults *responseElement = [RSBREST_DATAResults readFromXML: responseData];
// [responseElement retain];
//handle the response as needed...
Files:
- rsb.h
- rsb.m
- enunciate-common.h: common header needed for all projects.
- enunciate-common.m: common implementation needed for all projects.
PHP Client Library
Introduction
The PHP client-side library defines the PHP classes that can be (de)serialized to/from JSON. This is useful for accessing the REST endpoints that are published by this application, but only those that produce a JSON representation of their resources (content type “application/json”).
This library requires the json_encode function which was included in PHP versions 5.2.0+.
Files
Ruby Client Library
Introduction
The Ruby client-side library defines the Ruby classes that can be (de)serialized to/from JSON. This is useful for accessing the REST endpoints that are published by this application, but only those that produce a JSON representation of their resources (content type “application/json”).
This library leverages the Ruby JSON Implementation, which is required in order to use this library.
JSON REST Example
require 'net/https'
require 'uri'
//...
//read a resource from a REST url
url = URI.parse("...")
request = Net::HTTP::Get.new(url.request_uri)
http = Net::HTTP.new(url.host, url.port)
//set up additional http stuff...
res = http.start do |ht| ht.request(request) end
result = Results.from_json(JSON.parse(res.body))
//handle the result as needed...
Files: