diff options
author | 2018-07-25 19:32:59 +0800 | |
---|---|---|
committer | 2018-07-25 19:32:59 +0800 | |
commit | 9d07a8f00e984dd8d90356201e333cf3c808c7a3 (patch) | |
tree | 5f5ce4b06b90d5dc74826d4d36f9d16330e97a05 /openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector | |
parent | 8a57851000af82011c19d8e55787cdae3623c65b (diff) |
basic code refactoring client connector
Issue-ID: SO-729
Change-Id: If7331155e44582fcfeb1f7473ee42b1d8d55238a
Signed-off-by: seshukm <seshu.kumar.m@huawei.com>
Diffstat (limited to 'openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector')
2 files changed, 72 insertions, 72 deletions
diff --git a/openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/JaxRs20Connector.java b/openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/JaxRs20Connector.java index d18a64f..b1b528f 100644 --- a/openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/JaxRs20Connector.java +++ b/openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/JaxRs20Connector.java @@ -37,45 +37,45 @@ import com.woorea.openstack.base.client.OpenStackResponseException; public class JaxRs20Connector implements OpenStackClientConnector { - protected Client client = OpenStack.CLIENT; + protected Client client = OpenStack.CLIENT; private LoggingFilter logger = new LoggingFilter(Logger.getLogger("os"), 10000); - @Override - public <T> OpenStackResponse request(OpenStackRequest<T> request) { - WebTarget target = client.target(request.endpoint()).path(request.path()); + @Override + public <T> OpenStackResponse request(OpenStackRequest<T> request) { + WebTarget target = client.target(request.endpoint()).path(request.path()); - for(Map.Entry<String, List<Object> > entry : request.queryParams().entrySet()) { - for (Object o : entry.getValue()) { - target = target.queryParam(entry.getKey(), o); - } - } + for(Map.Entry<String, List<Object> > entry : request.queryParams().entrySet()) { + for (Object o : entry.getValue()) { + target = target.queryParam(entry.getKey(), o); + } + } target.register(logger); - Invocation.Builder invocation = target.request(); + Invocation.Builder invocation = target.request(); - for(Map.Entry<String, List<Object>> h : request.headers().entrySet()) { - StringBuilder sb = new StringBuilder(); - for(Object v : h.getValue()) { - sb.append(String.valueOf(v)); - } - invocation.header(h.getKey(), sb); - } + for(Map.Entry<String, List<Object>> h : request.headers().entrySet()) { + StringBuilder sb = new StringBuilder(); + for(Object v : h.getValue()) { + sb.append(String.valueOf(v)); + } + invocation.header(h.getKey(), sb); + } - Entity<?> entity = (request.entity() == null) ? null : - Entity.entity(request.entity().getEntity(), request.entity().getContentType()); + Entity<?> entity = (request.entity() == null) ? null : + Entity.entity(request.entity().getEntity(), request.entity().getContentType()); - try { - if (entity != null) { - return new JaxRs20Response(invocation.method(request.method().name(), entity)); - } else { - if(HttpMethod.PUT == request.method()) { - return new JaxRs20Response(invocation.method(request.method().name(), Entity.entity("", MediaType.APPLICATION_JSON))); - } else { - return new JaxRs20Response(invocation.method(request.method().name())); - } - } - } catch (ClientErrorException e) { - throw new OpenStackResponseException(e.getResponse() - .getStatusInfo().toString(), e.getResponse().getStatus()); - } - } + try { + if (entity != null) { + return new JaxRs20Response(invocation.method(request.method().name(), entity)); + } else { + if(HttpMethod.PUT == request.method()) { + return new JaxRs20Response(invocation.method(request.method().name(), Entity.entity("", MediaType.APPLICATION_JSON))); + } else { + return new JaxRs20Response(invocation.method(request.method().name())); + } + } + } catch (ClientErrorException e) { + throw new OpenStackResponseException(e.getResponse() + .getStatusInfo().toString(), e.getResponse().getStatus()); + } + } } diff --git a/openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/JaxRs20Response.java b/openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/JaxRs20Response.java index b51c833..2b1820e 100644 --- a/openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/JaxRs20Response.java +++ b/openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/JaxRs20Response.java @@ -30,48 +30,48 @@ import com.woorea.openstack.base.client.OpenStackResponse; import com.woorea.openstack.base.client.OpenStackResponseException; public class JaxRs20Response implements OpenStackResponse { - - private Response response; - - public JaxRs20Response(Response response) { - this.response = response; - } + + private Response response; + + public JaxRs20Response(Response response) { + this.response = response; + } - @Override - public <T> T getEntity(Class<T> returnType) { - if(response.getStatus() >= 400) { - throw new OpenStackResponseException(response.getStatusInfo().getReasonPhrase(), - response.getStatusInfo().getStatusCode(), this); - } - return response.readEntity(returnType); - } + @Override + public <T> T getEntity(Class<T> returnType) { + if(response.getStatus() >= 400) { + throw new OpenStackResponseException(response.getStatusInfo().getReasonPhrase(), + response.getStatusInfo().getStatusCode(), this); + } + return response.readEntity(returnType); + } - @Override - public <T> T getErrorEntity(Class<T> returnType) { - if(response.getStatus() >= 400 && response.hasEntity()) { - return response.readEntity(returnType); - } - return null; - } - + @Override + public <T> T getErrorEntity(Class<T> returnType) { + if(response.getStatus() >= 400 && response.hasEntity()) { + return response.readEntity(returnType); + } + return null; + } + - @Override - public InputStream getInputStream() { - return (InputStream) response.getEntity(); - } + @Override + public InputStream getInputStream() { + return (InputStream) response.getEntity(); + } - @Override - public String header(String name) { - return response.getHeaderString(name); - } + @Override + public String header(String name) { + return response.getHeaderString(name); + } - @Override - public Map<String, String> headers() { - Map<String, String> headers = new HashMap<>(); - for(String k : response.getHeaders().keySet()) { - headers.put(k, response.getHeaderString(k)); - } - return headers; - } + @Override + public Map<String, String> headers() { + Map<String, String> headers = new HashMap<>(); + for(String k : response.getHeaders().keySet()) { + headers.put(k, response.getHeaderString(k)); + } + return headers; + } } |