summaryrefslogtreecommitdiffstats
path: root/openstack-client-connectors
diff options
context:
space:
mode:
Diffstat (limited to 'openstack-client-connectors')
-rw-r--r--openstack-client-connectors/jersey-connector/pom.xml29
-rw-r--r--openstack-client-connectors/jersey-connector/src/main/java/com/woorea/openstack/connector/JerseyConnector.java119
-rw-r--r--openstack-client-connectors/jersey-connector/src/main/java/com/woorea/openstack/connector/JerseyLoggingFilter.java225
-rw-r--r--openstack-client-connectors/jersey-connector/src/main/java/com/woorea/openstack/connector/JerseyResponse.java82
-rw-r--r--openstack-client-connectors/jersey-connector/src/main/resources/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector1
-rw-r--r--openstack-client-connectors/jersey-connector/src/test/java/com/woorea/openstack/connector/JerseyLoggingFilterTest.java267
-rw-r--r--openstack-client-connectors/jersey2-connector/pom.xml35
-rw-r--r--openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/JaxRs20Connector.java81
-rw-r--r--openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/JaxRs20Response.java77
-rw-r--r--openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/OpenStack.java129
-rw-r--r--openstack-client-connectors/jersey2-connector/src/main/resources/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector1
-rw-r--r--openstack-client-connectors/pom.xml29
-rw-r--r--openstack-client-connectors/resteasy-connector/pom.xml36
-rw-r--r--openstack-client-connectors/resteasy-connector/src/main/java/com/woorea/openstack/connector/RESTEasyConnector.java145
-rw-r--r--openstack-client-connectors/resteasy-connector/src/main/java/com/woorea/openstack/connector/RESTEasyInputStream.java53
-rw-r--r--openstack-client-connectors/resteasy-connector/src/main/java/com/woorea/openstack/connector/RESTEasyResponse.java75
-rw-r--r--openstack-client-connectors/resteasy-connector/src/main/resources/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector1
17 files changed, 0 insertions, 1385 deletions
diff --git a/openstack-client-connectors/jersey-connector/pom.xml b/openstack-client-connectors/jersey-connector/pom.xml
deleted file mode 100644
index e942e8d..0000000
--- a/openstack-client-connectors/jersey-connector/pom.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.so.libs.openstack-java-sdk</groupId>
- <artifactId>client-connectors</artifactId>
- <version>1.2.1-SNAPSHOT</version>
- </parent>
- <groupId>org.onap.so.libs.openstack-java-sdk.client-connectors</groupId>
- <artifactId>jersey-connector</artifactId>
- <name>OpenStack Jersey Connector</name>
- <description>OpenStack Jersey Connector</description>
- <dependencies>
- <dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-client</artifactId>
- <version>1.17.1</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/openstack-client-connectors/jersey-connector/src/main/java/com/woorea/openstack/connector/JerseyConnector.java b/openstack-client-connectors/jersey-connector/src/main/java/com/woorea/openstack/connector/JerseyConnector.java
deleted file mode 100644
index 770b4d8..0000000
--- a/openstack-client-connectors/jersey-connector/src/main/java/com/woorea/openstack/connector/JerseyConnector.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package com.woorea.openstack.connector;
-
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Logger;
-
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.ContextResolver;
-import javax.ws.rs.ext.Provider;
-
-import com.fasterxml.jackson.annotation.JsonRootName;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.client.impl.ClientRequestImpl;
-import com.sun.jersey.core.header.OutBoundHeaders;
-import com.woorea.openstack.base.client.OpenStackClientConnector;
-import com.woorea.openstack.base.client.OpenStackRequest;
-import com.woorea.openstack.base.client.OpenStackResponse;
-import com.woorea.openstack.base.client.OpenStackResponseException;
-
-public class JerseyConnector implements OpenStackClientConnector {
-
- protected Client client = null;
- protected boolean logPassword;
- private JerseyLoggingFilter logger = new JerseyLoggingFilter(Logger.getLogger("os"));
-
- public JerseyConnector() {
- ClientConfig clientConfig = new DefaultClientConfig();
- clientConfig.getClasses().add(JacksonJaxbJsonProvider.class);
- clientConfig.getClasses().add(OpenStackObjectMapper.class);
- client = Client.create(clientConfig);
- }
-
- @Override
- public <T> OpenStackResponse request(OpenStackRequest<T> request) {
- WebResource target = client.resource(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(), String.valueOf(o));
- }
- }
- target.addFilter(logger);
- MultivaluedMap<String, Object> headers = new OutBoundHeaders();
- for(Map.Entry<String, List<Object>> h : request.headers().entrySet()) {
- for(Object v : h.getValue()) {
- headers.add(h.getKey(), v);
- }
- }
- if(request.entity() != null && request.entity().getContentType() != null) {
- headers.add("Content-Type", request.entity().getContentType());
- } else {
- headers.add("Content-Type", "application/json");
- }
- try {
- ClientResponse response;
- if (request.entity() != null && request.entity().getEntity() != null) {
- response = target.getHeadHandler().handle(new ClientRequestImpl(target.getURI(), request.method().name(), request.entity().getEntity(), headers));
- } else {
- response = target.getHeadHandler().handle(new ClientRequestImpl(target.getURI(), request.method().name(), null, headers));
- }
- return new JerseyResponse(response);
- } catch (UniformInterfaceException e) {
- throw new OpenStackResponseException(e.getResponse().getClientResponseStatus().getReasonPhrase(), e.getResponse().getStatus());
- }
- }
-
- @Provider
- public static class OpenStackObjectMapper implements ContextResolver<ObjectMapper> {
- static ObjectMapper DEFAULT_MAPPER;
- static ObjectMapper WRAPPED_MAPPER;
- static {
- DEFAULT_MAPPER = new ObjectMapper();
- DEFAULT_MAPPER.setSerializationInclusion(Include.NON_NULL);
- DEFAULT_MAPPER.enable(SerializationFeature.INDENT_OUTPUT);
- DEFAULT_MAPPER.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
- DEFAULT_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
- DEFAULT_MAPPER.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
-
- WRAPPED_MAPPER = new ObjectMapper();
- WRAPPED_MAPPER.setSerializationInclusion(Include.NON_NULL);
- WRAPPED_MAPPER.enable(SerializationFeature.INDENT_OUTPUT);
- WRAPPED_MAPPER.enable(SerializationFeature.WRAP_ROOT_VALUE);
- WRAPPED_MAPPER.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
- WRAPPED_MAPPER.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
- WRAPPED_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
- WRAPPED_MAPPER.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
- }
-
- @Override
- public ObjectMapper getContext(Class<?> type) {
- return type.getAnnotation(JsonRootName.class) == null ? DEFAULT_MAPPER : WRAPPED_MAPPER;
- }
- }
-}
diff --git a/openstack-client-connectors/jersey-connector/src/main/java/com/woorea/openstack/connector/JerseyLoggingFilter.java b/openstack-client-connectors/jersey-connector/src/main/java/com/woorea/openstack/connector/JerseyLoggingFilter.java
deleted file mode 100644
index ffdeb83..0000000
--- a/openstack-client-connectors/jersey-connector/src/main/java/com/woorea/openstack/connector/JerseyLoggingFilter.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package com.woorea.openstack.connector;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.logging.Logger;
-
-import com.sun.jersey.api.client.AbstractClientRequestAdapter;
-import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientRequest;
-import com.sun.jersey.api.client.ClientRequestAdapter;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.filter.ClientFilter;
-import com.sun.jersey.core.util.ReaderWriter;
-
-/**
- * A Jersey client filter that writes the request and response to a specified logger.
- */
-public class JerseyLoggingFilter extends ClientFilter {
-
- private final AtomicLong counter = new AtomicLong(0);
- private final Logger logger;
-
- /**
- * Constructor
- * @param logger the logger to which the request and response are written.
- */
- public JerseyLoggingFilter(Logger logger) {
- this.logger = logger;
- }
-
- @Override
- public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
- long id = counter.incrementAndGet();
- logRequest(id, request);
- ClientResponse response = getNext().handle(request);
- logResponse(id, response);
- return response;
- }
-
- /**
- * Logs a request.
- * @param id the request id (counter)
- * @param request the request
- */
- private void logRequest(long id, ClientRequest request) {
- StringBuilder builder = new StringBuilder();
-
- builder.append(String.valueOf(id));
- builder.append(" * Client out-bound request\n");
-
- builder.append(String.valueOf(id));
- builder.append(" > ");
- builder.append(request.getMethod());
- builder.append(" ");
- builder.append(request.getURI().toASCIIString());
- builder.append("\n");
-
- // Request headers
-
- for (Map.Entry<String, List<Object>> entry : request.getHeaders().entrySet()) {
- String header = entry.getKey();
- List<Object> values = entry.getValue();
-
- if (values.size() == 1) {
- builder.append(String.valueOf(id));
- builder.append(" > ");
- builder.append(header);
- builder.append(": ");
- builder.append(ClientRequest.getHeaderValue(values.get(0)));
- builder.append("\n");
- } else {
- StringBuilder buf = new StringBuilder();
- boolean first = true;
-
- for(Object value : values) {
- if (first) {
- first = false;
- } else {
- buf.append(",");
- }
-
- buf.append(ClientRequest.getHeaderValue(value));
- }
-
- builder.append(String.valueOf(id));
- builder.append(" > ");
- builder.append(header);
- builder.append(": ");
- builder.append(buf.toString());
- builder.append("\n");
- }
- }
-
- // Request body
-
- if (request.getEntity() != null) {
- request.setAdapter(new JerseyLoggingAdapter(request.getAdapter(), builder));
- } else {
- logger.info(builder.toString());
- }
- }
-
- /**
- * Logs a response.
- * @param id the request id (counter)
- * @param response the response
- */
- private void logResponse(long id, ClientResponse response) {
- StringBuilder builder = new StringBuilder();
-
- builder.append(String.valueOf(id));
- builder.append(" * Client in-bound response\n");
-
- builder.append(String.valueOf(id));
- builder.append(" < ");
- builder.append(String.valueOf(response.getStatus()));
- builder.append("\n");
-
- // Response headers
-
- for (Map.Entry<String, List<String>> entry : response.getHeaders().entrySet()) {
- String header = entry.getKey();
- for (String value : entry.getValue()) {
- builder.append(String.valueOf(id));
- builder.append(" < ");
- builder.append(header);
- builder.append(": ");
- builder.append(value).append("\n");
- }
- }
-
- // Response body
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- InputStream in = response.getEntityInputStream();
- try {
- ReaderWriter.writeTo(in, out);
-
- byte[] requestEntity = out.toByteArray();
- appendToBuffer(builder, requestEntity);
- response.setEntityInputStream(new ByteArrayInputStream(requestEntity));
- } catch (IOException ex) {
- throw new ClientHandlerException(ex);
- }
-
- logger.info(builder.toString());
- }
-
- /**
- * Appends bytes to the builder. If the bytes contain the password pattern,
- * the password is obliterated.
- * @param builder the builder
- * @param bytes the bytes to append
- */
- private void appendToBuffer(StringBuilder builder, byte[] bytes) {
- if (bytes.length != 0) {
- String s = new String(bytes);
- builder.append(s.replaceAll("\"password\".*:.*\"(.*)\"", "\"password\" : \"******\""));
- builder.append("\n");
- }
- }
-
- private class JerseyLoggingAdapter extends AbstractClientRequestAdapter {
- private final StringBuilder builder;
-
- JerseyLoggingAdapter(ClientRequestAdapter adapter, StringBuilder builder) {
- super(adapter);
- this.builder = builder;
- }
-
- @Override
- public OutputStream adapt(ClientRequest request, OutputStream out) throws IOException {
- return new JerseyLoggingOutputStream(getAdapter().adapt(request, out), builder);
- }
- }
-
- private class JerseyLoggingOutputStream extends OutputStream {
- private final OutputStream stream;
- private final StringBuilder builder;
- private final ByteArrayOutputStream logStream = new ByteArrayOutputStream();
-
- JerseyLoggingOutputStream(OutputStream stream, StringBuilder builder) {
- this.stream = stream;
- this.builder = builder;
- }
-
- @Override
- public void write(int value) throws IOException {
- logStream.write(value);
- stream.write(value);
- }
-
- @Override
- public void close() throws IOException {
- appendToBuffer(builder, logStream.toByteArray());
- logger.info(builder.toString());
- stream.close();
- }
- }
-} \ No newline at end of file
diff --git a/openstack-client-connectors/jersey-connector/src/main/java/com/woorea/openstack/connector/JerseyResponse.java b/openstack-client-connectors/jersey-connector/src/main/java/com/woorea/openstack/connector/JerseyResponse.java
deleted file mode 100644
index 5b01660..0000000
--- a/openstack-client-connectors/jersey-connector/src/main/java/com/woorea/openstack/connector/JerseyResponse.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package com.woorea.openstack.connector;
-
-/*
- * Modifications copyright (c) 2017 AT&T Intellectual Property
- */
-
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import com.sun.jersey.api.client.ClientResponse;
-import com.woorea.openstack.base.client.OpenStackResponse;
-import com.woorea.openstack.base.client.OpenStackResponseException;
-
-public class JerseyResponse implements OpenStackResponse {
-
- private ClientResponse response;
-
- public JerseyResponse(ClientResponse response) {
- this.response = response;
- }
-
- @Override
- public <T> T getEntity(Class<T> returnType) {
- if(response.getStatus() >= 400) {
- throw new OpenStackResponseException(response.getClientResponseStatus().getReasonPhrase(),
- response.getStatus(), this);
- }
- if(response.hasEntity() && returnType != null && Void.class != returnType) {
- return response.getEntity(returnType);
- } else {
- return null;
- }
- }
-
- @Override
- public <T> T getErrorEntity(Class<T> returnType) {
- if(response.getStatus() >= 400 && response.hasEntity()) {
- return response.getEntity(returnType);
- }
- return null;
- }
-
- @Override
- public InputStream getInputStream() {
- if(response.hasEntity()) {
- return response.getEntityInputStream();
- } else {
- return null;
- }
- }
-
- @Override
- public String header(String name) {
- return response.getHeaders().getFirst(name);
- }
-
- @Override
- public Map<String, String> headers() {
- Map<String, String> headers = new HashMap<>();
- for(String k : response.getHeaders().keySet()) {
- headers.put(k, response.getHeaders().getFirst(k));
- }
- return headers;
- }
-}
diff --git a/openstack-client-connectors/jersey-connector/src/main/resources/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector b/openstack-client-connectors/jersey-connector/src/main/resources/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector
deleted file mode 100644
index 5b9a158..0000000
--- a/openstack-client-connectors/jersey-connector/src/main/resources/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector
+++ /dev/null
@@ -1 +0,0 @@
-com.woorea.openstack.connector.JerseyConnector \ No newline at end of file
diff --git a/openstack-client-connectors/jersey-connector/src/test/java/com/woorea/openstack/connector/JerseyLoggingFilterTest.java b/openstack-client-connectors/jersey-connector/src/test/java/com/woorea/openstack/connector/JerseyLoggingFilterTest.java
deleted file mode 100644
index 3ebad7c..0000000
--- a/openstack-client-connectors/jersey-connector/src/test/java/com/woorea/openstack/connector/JerseyLoggingFilterTest.java
+++ /dev/null
@@ -1,267 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package com.woorea.openstack.connector;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doCallRealMethod;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.reflect.Method;
-import java.net.URI;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-import java.util.logging.Logger;
-import java.util.logging.SimpleFormatter;
-
-import javax.ws.rs.core.MultivaluedMap;
-
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-import com.sun.jersey.api.client.ClientHandler;
-import com.sun.jersey.api.client.ClientRequest;
-import com.sun.jersey.api.client.ClientRequestAdapter;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.filter.ClientFilter;
-
-public class JerseyLoggingFilterTest {
-
- private static Logger logger;
- private static LogFormatter logFormatter;
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- logger = Logger.getLogger(JerseyLoggingFilterTest.class.getSimpleName());
- logger.setLevel(Level.ALL);
- logger.setUseParentHandlers(false);
-
- ConsoleHandler handler = new ConsoleHandler();
- logFormatter = new LogFormatter();
- handler.setFormatter(logFormatter);
- handler.setLevel(Level.ALL);
- logger.addHandler(handler);
- }
-
- @Before
- public void setUpTest() {
- logFormatter.clearLog();
- }
-
- /**
- * Tests a scenario with no request content (GET).
- * @throws Exception for unexpected errors
- */
- @Test
- public void testGET() throws Exception {
- String responseContent = "<response>Hello, I am Eliza.</response>";
- execute("GET", "http://www.onap.org/eliza", null, responseContent);
- }
-
- /**
- * Tests a scenario with request content (POST).
- * @throws Exception for unexpected errors
- */
- @Test
- public void testPOST() throws Exception {
- String requestContent = "<request>I feel sad.</request>";
- String responseContent = "<response>Do you often feel sad?</response>";
- execute("POST", "http://www.onap.org/eliza", requestContent, responseContent);
- }
-
- /**
- * Runs a single test.
- * @param httpMethod any HTTP method (POST, GET, ...)
- * @param url any URL
- * @param requestContent mock request content, possibly null
- * @param responseContent mock response content, never null
- * @throws Exception for unexpected errors
- */
- private void execute(String httpMethod, String url, String requestContent, String responseContent)
- throws Exception {
- JerseyLoggingFilter loggingFilter = new JerseyLoggingFilter(logger);
-
- // Mock multi-valued and single valued request headers
-
- HashMap<String, List<Object>> requestHeaderMap = new HashMap<>();
- requestHeaderMap.put("Accept", Arrays.asList(new Object[]{"application/xml","application/json"}));
-
- if (requestContent != null) {
- requestHeaderMap.put("Content-Type", Arrays.asList(new Object[]{"application/xml"}));
- requestHeaderMap.put("Content-Length", Arrays.asList(new Object[]{String.valueOf(requestContent.length())}));
- }
-
- @SuppressWarnings("unchecked")
- MultivaluedMap<String, Object> requestHeaders = mock(MultivaluedMap.class);
- when(requestHeaders.entrySet()).thenReturn(requestHeaderMap.entrySet());
-
- // Mock the request object
-
- ClientRequest request = mock(TestClientRequest.class);
- when(request.getURI()).thenReturn(new URI(url));
- when(request.getMethod()).thenReturn(httpMethod);
- when(request.getHeaders()).thenReturn(requestHeaders);
-
- if (requestContent != null) {
- when(request.getEntity()).thenReturn(requestContent.getBytes("UTF-8"));
- }
-
- doCallRealMethod().when(request).setAdapter(any(ClientRequestAdapter.class));
- when(request.getAdapter()).thenCallRealMethod();
- request.setAdapter(new DefaultClientRequestAdapter());
-
- // Mock multi-valued and single valued response headers
-
- HashMap<String, List<String>> responseHeaderMap = new HashMap<>();
- responseHeaderMap.put("Cache-Control", Arrays.asList(new String[]{"no-cache","no-store"}));
- responseHeaderMap.put("Content-Type", Arrays.asList(new String[]{"application/xml"}));
- responseHeaderMap.put("Content-Length", Arrays.asList(new String[]{String.valueOf(responseContent.length())}));
- @SuppressWarnings("unchecked")
- MultivaluedMap<String, String> responseHeaders = mock(MultivaluedMap.class);
- when(responseHeaders.entrySet()).thenReturn(responseHeaderMap.entrySet());
-
- // Mock the response object
-
- ClientResponse response = mock(ClientResponse.class);
- when(response.getStatus()).thenReturn(200);
- when(response.getHeaders()).thenReturn(responseHeaders);
- when(response.getEntityInputStream()).thenReturn(
- new ByteArrayInputStream(responseContent.getBytes("UTF-8")));
-
- // Mock a handler that returns the response object and set
- // it to be the next filter after the logging filter.
-
- ClientFilter handler = mock(ClientFilter.class);
- when(handler.handle(request)).then(produceResponse(response));
- Method setNext = ClientFilter.class.getDeclaredMethod("setNext", new Class<?>[]{ClientHandler.class});
- setNext.setAccessible(true);
- setNext.invoke(loggingFilter, new Object[]{handler});
-
- // Run the request into the logging filter
-
- loggingFilter.handle(request);
-
- // Validate resulting the log content
-
- String log = logFormatter.getLog();
-
- assertContains(log, "* Client out-bound request");
- assertContains(log, "> " + httpMethod + " " + url);
-
- for (String header : requestHeaderMap.keySet()) {
- assertContains(log, "> " + header + ": ");
- }
-
- if (requestContent != null) {
- assertContains(log, requestContent);
- }
-
- assertContains(log, "* Client in-bound response");
- assertContains(log, "< 200");
-
- for (String header : responseHeaderMap.keySet()) {
- assertContains(log, "< " + header + ": ");
- }
-
- assertContains(log, responseContent);
- }
-
- private void assertContains(String log, String expect) {
- assertTrue("Log does not contain '" + expect + "'", log.contains(expect));
- }
-
- private class DefaultClientRequestAdapter implements ClientRequestAdapter {
- @Override
- public OutputStream adapt(ClientRequest request, OutputStream out) throws IOException {
- return out;
- }
- }
-
- private abstract class TestClientRequest extends ClientRequest {
- private ClientRequestAdapter adapter;
-
- @Override
- public ClientRequestAdapter getAdapter() {
- return adapter;
- }
-
- @Override
- public void setAdapter(ClientRequestAdapter adapter) {
- this.adapter = adapter;
- }
- }
-
- private Answer<ClientResponse> produceResponse(final ClientResponse response) {
- return new Answer<ClientResponse>() {
- public ClientResponse answer(InvocationOnMock invocation) throws IOException {
- ClientRequest request = (ClientRequest) invocation.getArguments()[0];
- byte[] entity = (byte[]) request.getEntity();
-
- if (entity != null) {
- ClientRequestAdapter adapter = request.getAdapter();
-
- OutputStream nullOutputStream = new OutputStream() {
- @Override
- public void write(int b) {
- // Discard
- }
- };
-
- OutputStream outputStream = adapter.adapt(request, nullOutputStream);
- outputStream.write(entity);
- outputStream.close();
- }
-
- return response;
- }
- };
- }
-
- private static class LogFormatter extends SimpleFormatter {
- StringBuilder buffer = new StringBuilder();
-
- public synchronized String getLog() {
- return buffer.toString();
- }
-
- public synchronized void clearLog() {
- buffer.setLength(0);
- }
-
- @Override
- public synchronized String format(LogRecord record) {
- String logData = super.format(record);
- buffer.append(logData);
- return logData;
- }
- }
-} \ No newline at end of file
diff --git a/openstack-client-connectors/jersey2-connector/pom.xml b/openstack-client-connectors/jersey2-connector/pom.xml
deleted file mode 100644
index 396867d..0000000
--- a/openstack-client-connectors/jersey2-connector/pom.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.so.libs.openstack-java-sdk</groupId>
- <artifactId>client-connectors</artifactId>
- <version>1.2.1-SNAPSHOT</version>
- </parent>
- <groupId>org.onap.so.libs.openstack-java-sdk.client-connectors</groupId>
- <artifactId>jersey2-connector</artifactId>
- <name>OpenStack Jersey2 Connector</name>
- <description>OpenStack Jersey2 Connector</description>
- <url>http://maven.apache.org</url>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.glassfish.jersey.core</groupId>
- <artifactId>jersey-client</artifactId>
- <version>2.6</version>
- </dependency>
- <dependency>
- <groupId>org.glassfish.jersey.media</groupId>
- <artifactId>jersey-media-json-jackson</artifactId>
- <version>2.6</version>
- </dependency>
- <dependency>
- <groupId>org.onap.so.libs.openstack-java-sdk</groupId>
- <artifactId>openstack-client</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-
-</project>
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
deleted file mode 100644
index b1b528f..0000000
--- a/openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/JaxRs20Connector.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package com.woorea.openstack.connector;
-
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Logger;
-
-import javax.ws.rs.ClientErrorException;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
-
-import org.glassfish.jersey.filter.LoggingFilter;
-
-import com.woorea.openstack.base.client.HttpMethod;
-import com.woorea.openstack.base.client.OpenStackClientConnector;
-import com.woorea.openstack.base.client.OpenStackRequest;
-import com.woorea.openstack.base.client.OpenStackResponse;
-import com.woorea.openstack.base.client.OpenStackResponseException;
-
-public class JaxRs20Connector implements OpenStackClientConnector {
-
- 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());
-
- 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();
-
- 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());
-
- 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
deleted file mode 100644
index 2b1820e..0000000
--- a/openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/JaxRs20Response.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package com.woorea.openstack.connector;
-
-/*
- * Modifications copyright (c) 2017 AT&T Intellectual Property
- */
-
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.ws.rs.core.Response;
-
-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;
- }
-
- @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 InputStream getInputStream() {
- return (InputStream) response.getEntity();
- }
-
- @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;
- }
-
-}
diff --git a/openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/OpenStack.java b/openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/OpenStack.java
deleted file mode 100644
index eeedfd0..0000000
--- a/openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/OpenStack.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package com.woorea.openstack.connector;
-
-import java.io.IOException;
-
-import javax.net.ssl.SSLContext;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.ClientRequestContext;
-import javax.ws.rs.client.ClientRequestFilter;
-import javax.ws.rs.ext.ContextResolver;
-
-import org.glassfish.jersey.SslConfigurator;
-import org.glassfish.jersey.jackson.JacksonFeature;
-
-import com.fasterxml.jackson.annotation.JsonRootName;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-
-public class OpenStack {
-
- public static Client CLIENT;
-
- public static ObjectMapper DEFAULT_MAPPER;
-
- public static ObjectMapper WRAPPED_MAPPER;
-
- static {
- initialize();
- }
-
- private static void initialize() {
-
- /*
- //class MyX509TrustManager implements X509TrustManager
- TrustManager mytm[] = null;
- KeyManager mykm[] = null;
-
- try {
- mytm = new TrustManager[]{new MyX509TrustManager("./truststore_client", "asdfgh".toCharArray())};
- mykm = new KeyManager[]{new MyX509KeyManager("./keystore_client", "asdfgh".toCharArray())};
- } catch (Exception ex) {
-
- }
-
- SSLContext context = null;
- context = SSLContext.getInstance("SSL");
- context.init(mykm, mytm, null);
-
- */
-
- try {
-
- SSLContext context;
- context = SSLContext.getInstance("SSL");
- context.init(null, null, null);
-
- SslConfigurator sslConfig = SslConfigurator.newInstance();
- /*
- .trustStoreFile("./truststore_client")
- .trustStorePassword("asdfgh")
-
- .keyStoreFile("./keystore_client")
- .keyPassword("asdfgh");
- */
- //old: CLIENT.property(ClientProperties.SSL_CONFIG, new SslConfig(context));
-
- CLIENT = ClientBuilder.newBuilder().sslContext(sslConfig.createSSLContext()).build();
-
- DEFAULT_MAPPER = new ObjectMapper();
-
- DEFAULT_MAPPER.setSerializationInclusion(Include.NON_NULL);
- DEFAULT_MAPPER.enable(SerializationFeature.INDENT_OUTPUT);
- DEFAULT_MAPPER.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
- DEFAULT_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
- DEFAULT_MAPPER.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
-
- WRAPPED_MAPPER = new ObjectMapper();
-
- WRAPPED_MAPPER.setSerializationInclusion(Include.NON_NULL);
- WRAPPED_MAPPER.enable(SerializationFeature.INDENT_OUTPUT);
- WRAPPED_MAPPER.enable(SerializationFeature.WRAP_ROOT_VALUE);
- WRAPPED_MAPPER.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
- WRAPPED_MAPPER.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
- WRAPPED_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
- WRAPPED_MAPPER.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
-
- CLIENT.register(new JacksonFeature()).register(new ContextResolver<ObjectMapper>() {
-
- @Override
- public ObjectMapper getContext(Class<?> type) {
- return type.getAnnotation(JsonRootName.class) == null ? DEFAULT_MAPPER : WRAPPED_MAPPER;
- }
-
- });
-
- CLIENT.register(new ClientRequestFilter() {
-
- @Override
- public void filter(ClientRequestContext requestContext) throws IOException {
- requestContext.getHeaders().remove("Content-Language");
- requestContext.getHeaders().remove("Content-Encoding");
- }
- });
-
- } catch(Exception e) {
- throw new RuntimeException(e.getMessage(), e);
- }
-
- }
-
-}
diff --git a/openstack-client-connectors/jersey2-connector/src/main/resources/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector b/openstack-client-connectors/jersey2-connector/src/main/resources/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector
deleted file mode 100644
index fc24457..0000000
--- a/openstack-client-connectors/jersey2-connector/src/main/resources/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector
+++ /dev/null
@@ -1 +0,0 @@
-com.woorea.openstack.connector.JaxRs20Connector \ No newline at end of file
diff --git a/openstack-client-connectors/pom.xml b/openstack-client-connectors/pom.xml
index 3654d39..51ff6e4 100644
--- a/openstack-client-connectors/pom.xml
+++ b/openstack-client-connectors/pom.xml
@@ -12,33 +12,6 @@
<packaging>pom</packaging>
<profiles>
<profile>
- <id>jersey</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- <modules>
- <module>jersey-connector</module>
- </modules>
- </profile>
- <profile>
- <id>jersey2</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- <modules>
- <module>jersey2-connector</module>
- </modules>
- </profile>
- <profile>
- <id>resteasy</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- <modules>
- <module>resteasy-connector</module>
- </modules>
- </profile>
- <profile>
<id>http</id>
<activation>
<activeByDefault>true</activeByDefault>
@@ -47,7 +20,6 @@
<module>http-connector</module>
</modules>
</profile>
-
</profiles>
<dependencies>
<dependency>
@@ -56,5 +28,4 @@
<version>${project.version}</version>
</dependency>
</dependencies>
-
</project>
diff --git a/openstack-client-connectors/resteasy-connector/pom.xml b/openstack-client-connectors/resteasy-connector/pom.xml
deleted file mode 100644
index 8bfe105..0000000
--- a/openstack-client-connectors/resteasy-connector/pom.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.so.libs.openstack-java-sdk</groupId>
- <artifactId>client-connectors</artifactId>
- <version>1.2.1-SNAPSHOT</version>
- </parent>
- <groupId>org.onap.so.libs.openstack-java-sdk.client-connectors</groupId>
- <artifactId>resteasy-connector</artifactId>
- <name>OpenStack RESTEasy Connector</name>
- <description>OpenStack RESTEasy Connector</description>
- <dependencies>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jaxrs</artifactId>
- <!-- replaced with 3.5.0.Final <version>2.3.2.Final</version> -->
- <version>3.5.1.Final</version><!-- 3.5.0 changed to 3.5.1 for the CLM policy threat issue resolution -->
- </dependency>
- <!-- replaced with httpclient and httpcore
- <dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.1</version>
- </dependency>
- -->
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpcore</artifactId>
- </dependency>
- </dependencies>
-
-</project>
diff --git a/openstack-client-connectors/resteasy-connector/src/main/java/com/woorea/openstack/connector/RESTEasyConnector.java b/openstack-client-connectors/resteasy-connector/src/main/java/com/woorea/openstack/connector/RESTEasyConnector.java
deleted file mode 100644
index b804e69..0000000
--- a/openstack-client-connectors/resteasy-connector/src/main/java/com/woorea/openstack/connector/RESTEasyConnector.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package com.woorea.openstack.connector;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.ext.ContextResolver;
-
-// bwj: changed the HttpStatus package
-//import org.apache.commons.httpclient.HttpStatus;
-import org.apache.http.HttpStatus;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.plugins.providers.InputStreamProvider;
-import org.jboss.resteasy.spi.ResteasyProviderFactory;
-
-import com.fasterxml.jackson.annotation.JsonRootName;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
-import com.woorea.openstack.base.client.OpenStackClientConnector;
-import com.woorea.openstack.base.client.OpenStackRequest;
-import com.woorea.openstack.base.client.OpenStackResponse;
-import com.woorea.openstack.base.client.OpenStackResponseException;
-
-public class RESTEasyConnector implements OpenStackClientConnector {
-
- public static ObjectMapper DEFAULT_MAPPER;
-
- public static ObjectMapper WRAPPED_MAPPER;
-
- static class OpenStackProviderFactory extends ResteasyProviderFactory {
-
- private JacksonJsonProvider jsonProvider;
- private InputStreamProvider streamProvider;
-
- public OpenStackProviderFactory() {
- super();
-
- addContextResolver(new ContextResolver<ObjectMapper>() {
- @Override
- public ObjectMapper getContext(Class<?> type) {
- return type.getAnnotation(JsonRootName.class) == null ? DEFAULT_MAPPER : WRAPPED_MAPPER;
- }
- });
-
- jsonProvider = new JacksonJsonProvider();
- addMessageBodyReader(jsonProvider);
- addMessageBodyWriter(jsonProvider);
-
- streamProvider = new InputStreamProvider();
- addMessageBodyReader(streamProvider);
- addMessageBodyWriter(streamProvider);
- }
-
- }
-
- private static OpenStackProviderFactory providerFactory;
-
- static {
- DEFAULT_MAPPER = new ObjectMapper();
-
- DEFAULT_MAPPER.setSerializationInclusion(Include.NON_NULL);
- DEFAULT_MAPPER.enable(SerializationFeature.INDENT_OUTPUT);
- DEFAULT_MAPPER.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
- DEFAULT_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
- DEFAULT_MAPPER.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
-
- WRAPPED_MAPPER = new ObjectMapper();
-
- WRAPPED_MAPPER.setSerializationInclusion(Include.NON_NULL);
- WRAPPED_MAPPER.enable(SerializationFeature.INDENT_OUTPUT);
- WRAPPED_MAPPER.enable(SerializationFeature.WRAP_ROOT_VALUE);
- WRAPPED_MAPPER.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
- WRAPPED_MAPPER.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
- WRAPPED_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
- WRAPPED_MAPPER.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
-
- providerFactory = new OpenStackProviderFactory();
- }
-
- @Override
- public <T> OpenStackResponse request(OpenStackRequest<T> request) {
- ClientRequest client = new ClientRequest(UriBuilder.fromUri(request.endpoint() + "/" + request.path()),
- ClientRequest.getDefaultExecutor(), providerFactory);
-
- for(Map.Entry<String, List<Object> > entry : request.queryParams().entrySet()) {
- for (Object o : entry.getValue()) {
- client = client.queryParameter(entry.getKey(), String.valueOf(o));
- }
- }
-
- for (Entry<String, List<Object>> h : request.headers().entrySet()) {
- StringBuilder sb = new StringBuilder();
- for (Object v : h.getValue()) {
- sb.append(String.valueOf(v));
- }
- client.header(h.getKey(), sb);
- }
-
- if (request.entity() != null) {
- client.body(request.entity().getContentType(), request.entity().getEntity());
- }
-
- ClientResponse<T> response;
-
- try {
- response = client.httpMethod(request.method().name(), request.returnType());
- } catch (Exception e) {
- throw new RuntimeException("Unexpected client exception", e);
- }
-
- if (response.getStatus() == HttpStatus.SC_OK
- || response.getStatus() == HttpStatus.SC_CREATED
- || response.getStatus() == HttpStatus.SC_NO_CONTENT
- || response.getStatus() == HttpStatus.SC_ACCEPTED) {
- return new RESTEasyResponse(client, response);
- }
-
- response.releaseConnection();
-
- throw new OpenStackResponseException(response.getResponseStatus()
- .getReasonPhrase(), response.getStatus());
- }
-
-}
diff --git a/openstack-client-connectors/resteasy-connector/src/main/java/com/woorea/openstack/connector/RESTEasyInputStream.java b/openstack-client-connectors/resteasy-connector/src/main/java/com/woorea/openstack/connector/RESTEasyInputStream.java
deleted file mode 100644
index 0e1e9e9..0000000
--- a/openstack-client-connectors/resteasy-connector/src/main/java/com/woorea/openstack/connector/RESTEasyInputStream.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package com.woorea.openstack.connector;
-
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.SocketException;
-
-import org.jboss.resteasy.client.ClientExecutor;
-
-
-public class RESTEasyInputStream extends FilterInputStream {
-
- protected ClientExecutor clientExecutor;
-
- public RESTEasyInputStream(InputStream inputStream, ClientExecutor clientExecutor) {
- super(inputStream);
- this.clientExecutor = clientExecutor;
- }
-
- @Override
- public void close() throws IOException {
- try {
- clientExecutor.close();
- } catch (Exception e) {
- // Silently skip errors in the socket close errors
- }
-
- try {
- super.close();
- } catch (SocketException e) {
- // We expect this exception because the socket is closed
- } catch (IllegalStateException e) {
- // We expect this exception because the socket is closed (httpclient 4.2)
- }
- }
-
-}
diff --git a/openstack-client-connectors/resteasy-connector/src/main/java/com/woorea/openstack/connector/RESTEasyResponse.java b/openstack-client-connectors/resteasy-connector/src/main/java/com/woorea/openstack/connector/RESTEasyResponse.java
deleted file mode 100644
index ced748e..0000000
--- a/openstack-client-connectors/resteasy-connector/src/main/java/com/woorea/openstack/connector/RESTEasyResponse.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package com.woorea.openstack.connector;
-
-/*
- * Modifications copyright (c) 2017 AT&T Intellectual Property
- */
-
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.ClientResponse;
-import com.woorea.openstack.base.client.OpenStackResponse;
-
-import javax.ws.rs.core.MultivaluedMap;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-public class RESTEasyResponse implements OpenStackResponse {
-
- private ClientRequest client;
-
- private ClientResponse response;
-
- public RESTEasyResponse(ClientRequest client, ClientResponse response) {
- this.client = client;
- this.response = response;
- }
-
- @Override
- public <T> T getEntity(Class<T> returnType) {
- return (T) response.getEntity(returnType);
- }
-
- @Override
- public <T> T getErrorEntity(Class<T> returnType) {
- return (T) response.getEntity(returnType);
- }
-
- @Override
- public InputStream getInputStream() {
- return new RESTEasyInputStream((InputStream) response.getEntity(InputStream.class), client.getExecutor());
- }
-
- @Override
- public String header(String name) {
- return response.getHeaders().getFirst(name).toString();
- }
-
- @Override
- public Map<String, String> headers() {
- Map<String, String> headers = new HashMap<>();
- MultivaluedMap<String, Object> responseHeaders = response.getHeaders();
-
- for (String key : responseHeaders.keySet()) {
- headers.put(key, responseHeaders.getFirst(key).toString());
- }
-
- return headers;
- }
-
-}
diff --git a/openstack-client-connectors/resteasy-connector/src/main/resources/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector b/openstack-client-connectors/resteasy-connector/src/main/resources/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector
deleted file mode 100644
index dbb991d..0000000
--- a/openstack-client-connectors/resteasy-connector/src/main/resources/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector
+++ /dev/null
@@ -1 +0,0 @@
-com.woorea.openstack.connector.RESTEasyConnector \ No newline at end of file