Added the possibility for a client to add additional HTTP headers
This commit is contained in:
parent
e7b6f7c889
commit
031372c497
|
@ -55,8 +55,13 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherImpl.class);
|
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherImpl.class);
|
||||||
|
|
||||||
|
private static final String ACCEPT_HTTP_HEADER_KEY = "Accept";
|
||||||
|
private static final String CONTENT_TYPE_HTTP_HEADER_KEY = "Content-Type";
|
||||||
|
|
||||||
protected final String address;
|
protected final String address;
|
||||||
|
|
||||||
|
protected Map<String, String> headers;
|
||||||
|
|
||||||
protected boolean hierarchicalMode;
|
protected boolean hierarchicalMode;
|
||||||
protected boolean includeContextsInHeader;
|
protected boolean includeContextsInHeader;
|
||||||
|
|
||||||
|
@ -123,8 +128,22 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public void addHeader(String name, String value) {
|
||||||
|
headers.put(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected GXHTTPStringRequest getGXHTTPStringRequest() {
|
||||||
|
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
||||||
|
gxHTTPStringRequest.from(this.getClass().getSimpleName());
|
||||||
|
for(String name : headers.keySet()) {
|
||||||
|
gxHTTPStringRequest.header(name, headers.get(name));
|
||||||
|
}
|
||||||
|
return gxHTTPStringRequest;
|
||||||
|
}
|
||||||
|
|
||||||
public ResourceRegistryPublisherImpl(String address) {
|
public ResourceRegistryPublisherImpl(String address) {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
|
this.headers = new HashMap<>();
|
||||||
ContextCache contextCache = ContextCache.getInstance();
|
ContextCache contextCache = ContextCache.getInstance();
|
||||||
contextCache.setContextCacheRenewal(contextCacheRenewal);
|
contextCache.setContextCacheRenewal(contextCacheRenewal);
|
||||||
}
|
}
|
||||||
|
@ -132,9 +151,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
public List<Context> getAllContextFromServer() throws ResourceRegistryException {
|
public List<Context> getAllContextFromServer() throws ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
logger.info("Going to read all {}s", Context.NAME);
|
logger.info("Going to read all {}s", Context.NAME);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
||||||
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
|
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
|
||||||
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
|
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
|
||||||
|
|
||||||
|
@ -166,9 +184,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
protected Context getContextFromServer(String id) throws ContextNotFoundException, ResourceRegistryException {
|
protected Context getContextFromServer(String id) throws ContextNotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
logger.info("Going to get current {} ", Context.NAME);
|
logger.info("Going to get current {} ", Context.NAME);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
||||||
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
|
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
|
||||||
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
|
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
|
||||||
gxHTTPStringRequest.path(id);
|
gxHTTPStringRequest.path(id);
|
||||||
|
@ -256,9 +273,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
public String list(String type, Boolean polymorphic) throws ResourceRegistryException {
|
public String list(String type, Boolean polymorphic) throws ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
logger.info("Going to get all instances of {} ", type);
|
logger.info("Going to get all instances of {} ", type);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
||||||
gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART);
|
gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART);
|
||||||
gxHTTPStringRequest.path(type);
|
gxHTTPStringRequest.path(type);
|
||||||
|
|
||||||
|
@ -285,10 +301,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
|
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
logger.trace("Going to create {} : {}", type, json);
|
logger.trace("Going to create {} : {}", type, json);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
gxHTTPStringRequest.header(CONTENT_TYPE_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||||
gxHTTPStringRequest.header("Content-type", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
||||||
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
||||||
gxHTTPStringRequest.path(type);
|
gxHTTPStringRequest.path(type);
|
||||||
gxHTTPStringRequest.path(uuid.toString());
|
gxHTTPStringRequest.path(uuid.toString());
|
||||||
|
@ -382,9 +397,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
throws AvailableInAnotherContextException, ResourceRegistryException {
|
throws AvailableInAnotherContextException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
logger.info("Going to check if {} with UUID {} exists", type, uuid);
|
logger.info("Going to check if {} with UUID {} exists", type, uuid);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
||||||
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
|
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
|
||||||
gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART);
|
gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART);
|
||||||
gxHTTPStringRequest.path(type);
|
gxHTTPStringRequest.path(type);
|
||||||
|
@ -447,9 +461,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
logger.trace("Going to read {} with UUID {}", type, uuid);
|
logger.trace("Going to read {} with UUID {}", type, uuid);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
||||||
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
||||||
gxHTTPStringRequest.path(type);
|
gxHTTPStringRequest.path(type);
|
||||||
gxHTTPStringRequest.path(uuid.toString());
|
gxHTTPStringRequest.path(uuid.toString());
|
||||||
|
@ -527,10 +540,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
logger.trace("Going to create {} : {}", type, json);
|
logger.trace("Going to create {} : {}", type, json);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
gxHTTPStringRequest.header(CONTENT_TYPE_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||||
gxHTTPStringRequest.header("Content-type", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
||||||
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
||||||
gxHTTPStringRequest.path(type);
|
gxHTTPStringRequest.path(type);
|
||||||
gxHTTPStringRequest.path(uuid.toString());
|
gxHTTPStringRequest.path(uuid.toString());
|
||||||
|
@ -573,9 +585,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
logger.trace("Going to delete {} with UUID {}", type, uuid);
|
logger.trace("Going to delete {} with UUID {}", type, uuid);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
|
||||||
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
||||||
gxHTTPStringRequest.path(type);
|
gxHTTPStringRequest.path(type);
|
||||||
gxHTTPStringRequest.path(uuid.toString());
|
gxHTTPStringRequest.path(uuid.toString());
|
||||||
|
@ -796,8 +807,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
try {
|
try {
|
||||||
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME,
|
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME,
|
||||||
contextUUID);
|
contextUUID);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
|
||||||
gxHTTPStringRequest.path(SharingPath.SHARING_PATH_PART);
|
gxHTTPStringRequest.path(SharingPath.SHARING_PATH_PART);
|
||||||
gxHTTPStringRequest.path(SharingPath.CONTEXTS_PATH_PART);
|
gxHTTPStringRequest.path(SharingPath.CONTEXTS_PATH_PART);
|
||||||
gxHTTPStringRequest.path(contextUUID.toString());
|
gxHTTPStringRequest.path(contextUUID.toString());
|
||||||
|
@ -867,8 +877,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
try {
|
try {
|
||||||
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME,
|
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME,
|
||||||
contextUUID);
|
contextUUID);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
|
||||||
gxHTTPStringRequest.path(SharingPath.SHARING_PATH_PART);
|
gxHTTPStringRequest.path(SharingPath.SHARING_PATH_PART);
|
||||||
gxHTTPStringRequest.path(SharingPath.CONTEXTS_PATH_PART);
|
gxHTTPStringRequest.path(SharingPath.CONTEXTS_PATH_PART);
|
||||||
gxHTTPStringRequest.path(contextUUID.toString());
|
gxHTTPStringRequest.path(contextUUID.toString());
|
||||||
|
@ -936,8 +945,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
throws NotFoundException, ResourceRegistryException {
|
throws NotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
logger.trace("Going to get contexts of {} with UUID {}", type, instanceUUID);
|
logger.trace("Going to get contexts of {} with UUID {}", type, instanceUUID);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName());
|
|
||||||
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
|
||||||
gxHTTPStringRequest.path(type);
|
gxHTTPStringRequest.path(type);
|
||||||
gxHTTPStringRequest.path(instanceUUID.toString());
|
gxHTTPStringRequest.path(instanceUUID.toString());
|
||||||
|
|
Loading…
Reference in New Issue