summaryrefslogtreecommitdiffstats
path: root/openstack-client-connectors/jersey2-connector
diff options
context:
space:
mode:
Diffstat (limited to 'openstack-client-connectors/jersey2-connector')
-rw-r--r--openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/JaxRs20Connector.java68
-rw-r--r--openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/JaxRs20Response.java76
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;
+ }
}