diff options
Diffstat (limited to 'openstack-client-connectors/jersey2-connector')
5 files changed, 0 insertions, 323 deletions
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 |