summaryrefslogtreecommitdiffstats
path: root/openstack-client-connectors/jersey2-connector/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'openstack-client-connectors/jersey2-connector/src/main')
-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
4 files changed, 0 insertions, 288 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
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