Added the possibility for a client to add additional HTTP headers
This commit is contained in:
parent
b1541f1671
commit
c84c4e4c78
|
@ -30,11 +30,29 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistrySchemaClientImpl.class);
|
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistrySchemaClientImpl.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;
|
||||||
|
|
||||||
|
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 ResourceRegistrySchemaClientImpl(String address) {
|
public ResourceRegistrySchemaClientImpl(String address) {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
|
this.headers = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -58,10 +76,9 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
||||||
logger.trace("Going to create: {}", typeDefinitition);
|
logger.trace("Going to create: {}", typeDefinitition);
|
||||||
Type typeDefinitionObj = TypeMapper.deserializeTypeDefinition(typeDefinitition);
|
Type typeDefinitionObj = TypeMapper.deserializeTypeDefinition(typeDefinitition);
|
||||||
|
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
gxHTTPStringRequest.from(ResourceRegistrySchemaClient.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(TypePath.TYPES_PATH_PART);
|
gxHTTPStringRequest.path(TypePath.TYPES_PATH_PART);
|
||||||
gxHTTPStringRequest.path(typeDefinitionObj.getName());
|
gxHTTPStringRequest.path(typeDefinitionObj.getName());
|
||||||
|
|
||||||
|
@ -94,9 +111,8 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
||||||
public boolean exist(String typeName) throws ResourceRegistryException {
|
public boolean exist(String typeName) throws ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
logger.info("Going to get {} schema", typeName);
|
logger.info("Going to get {} schema", typeName);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
gxHTTPStringRequest.from(ResourceRegistrySchemaClient.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(TypePath.TYPES_PATH_PART);
|
gxHTTPStringRequest.path(TypePath.TYPES_PATH_PART);
|
||||||
gxHTTPStringRequest.path(typeName);
|
gxHTTPStringRequest.path(typeName);
|
||||||
|
|
||||||
|
@ -136,9 +152,8 @@ public class ResourceRegistrySchemaClientImpl implements ResourceRegistrySchemaC
|
||||||
public String read(String typeName, Boolean polymorphic) throws ContextNotFoundException, ResourceRegistryException {
|
public String read(String typeName, Boolean polymorphic) throws ContextNotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
logger.info("Going to get {} schema", typeName);
|
logger.info("Going to get {} schema", typeName);
|
||||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
|
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||||
gxHTTPStringRequest.from(ResourceRegistrySchemaClient.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(TypePath.TYPES_PATH_PART);
|
gxHTTPStringRequest.path(TypePath.TYPES_PATH_PART);
|
||||||
gxHTTPStringRequest.path(typeName);
|
gxHTTPStringRequest.path(typeName);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue