gCube eXtensions to REST
This repository has been archived on 2025-11-11. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Luca Frosini 6870e50925 Add developer information for Luca Frosini in pom.xml 2025-11-07 14:40:03 +01:00
gxHTTP Add developer information for Luca Frosini in pom.xml 2025-11-07 14:40:03 +01:00
gxJRS javax version 2025-11-06 16:26:41 +01:00
.gitignore Ignored MacOs File 2023-06-21 11:40:00 +02:00
CHANGELOG.md Removed jakarta.ws.rs-api dependency from gx-rest component 2025-03-05 14:43:46 +01:00
FUNDING.md Aligned legal and documentation files with templates 2025-06-06 16:27:33 +02:00
Jenkinsfile javax version 2025-11-06 16:26:41 +01:00
Jenkinsfile-javax Updated Jenkinsfile and Jenkinsjob.xml 2025-11-06 16:27:18 +01:00
Jenkinsjob-javax.xml Updated Jenkinsfile and Jenkinsjob.xml 2025-11-06 16:27:18 +01:00
Jenkinsjob.xml javax version 2025-11-06 16:26:41 +01:00
LICENSE.md Aligned legal and documentation files with templates 2025-06-06 16:27:33 +02:00
README.md Update README.md: clarify license terms and correct gCubeFramework link 2025-07-03 15:28:00 +02:00
build.log javax version 2025-11-06 16:26:41 +01:00
pom.javax.xml Update parent version to 1.3.0-SNAPSHOT in pom.javax.xml 2025-11-06 17:39:42 +01:00
pom.xml Updated pom.xml to comply with others Java 17 components 2025-11-07 12:10:30 +01:00
tree_jakarta.txt javax version 2025-11-06 16:26:41 +01:00
tree_javax.txt javax version 2025-11-06 16:26:41 +01: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 (if any).

Documentation

See gxRest on Wiki.

Built With

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

License

This project is licensed under the terms specified in the LICENSE.md file.

About the gCube Framework

This software is part of the gCubeFramework: an open-source software toolkit used for building and operating Hybrid Data Infrastructures enabling the dynamic deployment of Virtual Research Environments by favouring the realisation of reuse oriented policies.

The projects leading to this software have received funding from a series of European Union programmes see FUNDING.md