GxRest/GxJRS/Requests

From Gcube Wiki
Revision as of 04:30, 24 April 2018 by Manuele.simi (Talk | contribs) (GXWebTargetAdapterRequest)

Jump to: navigation, search

Introduction

Types of Requests

GXHTTPRequest

GXWebTargetAdapterRequest

import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
 
//send a post request with content
 
String context ="json serialization (not shown";
Map<String,String> queryParams = new WeakHashMap<>();
queryParams.put("rrURL", DEFAULT_RR_URL);
String DEFAULT_RR_URL = "url of resource registry to contact";
 
 
GXInboundResponse response = request.path("gxrest")
		.queryParams(queryParams).withEntity(Entity.entity(context, MediaType.APPLICATION_JSON)).post();
if (!response.hasCREATEDCode()) {
	if (response.hasException()) {
		try {
			throw response.getException();
		} catch (ClassNotFoundException e) {
			//that's OK, we can tolerate this
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}
} else {
	logger.info("Resource successfully created!");
	logger.info("Returned message: " + response.getStreamedContentAsString());
}