Go to file
Manuele Simi a019b08860 Adjust code in the readme. 2019-04-07 22:55:07 -04:00
.settings Aligning pom artifactId to svn location 2019-03-22 11:21:36 +00:00
gxHTTP Update scm paths in the poms. 2019-03-28 01:14:26 +00:00
gxJRS Add JAX-RS MessageBodyWriter/Reader responsible for converting SerializableErrorEntity to/from a stream. 2019-03-31 03:39:06 +00:00
idea/.idea Add REAME.md 2019-04-06 15:56:02 -04:00
.classpath Aligning pom artifactId to svn location 2019-03-22 11:21:36 +00:00
.gitignore Add gitignore. 2019-04-06 15:43:32 -04:00
.project Aligning pom artifactId to eclipse project name 2019-03-22 11:32:37 +00:00
README.md Adjust code in the readme. 2019-04-07 22:55:07 -04:00
pom.xml Update scm paths in the poms. 2019-03-28 01:14:26 +00:00

README.md

gxRest

The gCube eXtensions to the Rest Protocol (gxRest) is a set of Java libraries designed to provide convenient round-trip interaction between a Restful web application (also known as "service") and its clients.

gxRest has the flexibility for different degrees of exploitation:

  • it can be entirely adopted both at client and service side with full benefit of its conventions;
  • it can be used to send REST requests based only on plain HTTP;
  • it can be used only to return HTTP code/messagess from the service;
  • it can be used only to throw Exceptions from the service to the client.

Examples of use

Sending a request:

GXHTTPRequest request = GXHTTPRequest.newRequest("http://host:port/service/").from("GXRequestTest");
 
//prepare some parameters
String context ="...";
Map<String,String> queryParams = new WeakHashMap<>();
queryParams.put("param name", "param value");
GXInboundResponse response = request.path("context")
	  .queryParams(queryParams).withBody(context).post();

Returning a success response:

 @POST
  public Response create(...) {
 
    //Resource successfully created 
    
    URI location = ... //URI of the new resource
    return GXOutboundSuccessResponse.newCREATEResponse(location)
              .withMessage("Resource successfully created.")
	      .ofType(MediaType.APPLICATION_JSON)
              .build();
  }

Throwing an exception:

@POST
  public Response create(...) {
 
    //Oh no, something failed here
    GXOutboundErrorResponse.throwException(new MyCustomException("Resource already exists."));
    
  }   

Parsing a response

// invoke the remote method and get a response.
GXInboundResponse response = ...;
if (response.hasException()) 
    throw response.getException();
//assuming a created (200) code was expected 
if (response.hasCREATEDCode()) {
		System.out.println("Resource successfully created!");
}
//access content as string
String value = response.getStreamedContentAsString();
//unmasharll content as json
Context returnedContext = response.tryConvertStreamedContentFromJson(Context.class);

Modules

Deployment

Notes about how to deploy this component on an infrastructure or link to wiki doc.

Documentation

See gxRest on Wiki.

Built With

  • JAX-RS - Java™ API for RESTful Web Services
  • Jersey - JAX-RS runtime
  • Maven - Dependency Management

License

TBP