From 9ce3c17a98857c8c15acef639963017b98a900f2 Mon Sep 17 00:00:00 2001 From: Ryan D. Brooks Date: Mon, 18 Jul 2016 13:09:23 -0700 Subject: refactor: Add OrcsParamConverterProvider Change-Id: I7d272f81901eeddafa6808c89260786ddc851d47 --- .../ext/CxfJaxRsClientConfiguratorTest.java | 2 +- .../internal/ext/CxfJaxRsClientConfigurator.java | 3 +- .../client/internal/ext/IdParamConverter.java | 34 ++++++++++++++++++++++ .../internal/ext/OrcsParamConverterProvider.java | 34 ++++++++++++++++++++++ 4 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/IdParamConverter.java create mode 100644 plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/OrcsParamConverterProvider.java diff --git a/plugins/org.eclipse.osee.jaxrs.client.test/src/org/eclipse/osee/jaxrs/client/internal/ext/CxfJaxRsClientConfiguratorTest.java b/plugins/org.eclipse.osee.jaxrs.client.test/src/org/eclipse/osee/jaxrs/client/internal/ext/CxfJaxRsClientConfiguratorTest.java index d1f4a74f052..16b0d0d35d2 100644 --- a/plugins/org.eclipse.osee.jaxrs.client.test/src/org/eclipse/osee/jaxrs/client/internal/ext/CxfJaxRsClientConfiguratorTest.java +++ b/plugins/org.eclipse.osee.jaxrs.client.test/src/org/eclipse/osee/jaxrs/client/internal/ext/CxfJaxRsClientConfiguratorTest.java @@ -236,7 +236,7 @@ public class CxfJaxRsClientConfiguratorTest { assertEquals(JsonMappingExceptionMapper.class, iterator.next()); assertEquals(OAuthJSONProvider.class, iterator.next().getClass()); assertEquals(OAuthContextProvider.class, iterator.next().getClass()); - + assertEquals(OrcsParamConverterProvider.class, iterator.next().getClass()); assertEquals(OseeAccountClientRequestFilter.class, iterator.next().getClass()); assertEquals(LoggingFeature.class, iterator.next().getClass()); assertEquals(GZIPFeature.class, iterator.next().getClass()); diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/CxfJaxRsClientConfigurator.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/CxfJaxRsClientConfigurator.java index a5be34a3033..db9d0d2f2d3 100644 --- a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/CxfJaxRsClientConfigurator.java +++ b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/CxfJaxRsClientConfigurator.java @@ -94,6 +94,7 @@ public final class CxfJaxRsClientConfigurator implements JaxRsClientConfigurator providers.add(new GenericResponseExceptionMapper()); providers.addAll(JacksonFeature.getProviders()); providers.addAll(OAuth2Util.getOAuthProviders()); + providers.add(new OrcsParamConverterProvider()); providers.add(new OseeAccountClientRequestFilter()); this.providers = providers; @@ -115,7 +116,6 @@ public final class CxfJaxRsClientConfigurator implements JaxRsClientConfigurator bean.setFeatures(getFeatures()); bean.setProperties(getProperties()); bean.setProviders(getOAuthProviders(config)); - bean.setProvider(new OseeAccountClientRequestFilter()); /** * If threadSafe is true then multiple threads can invoke on the same proxy or WebClient instance. @@ -139,7 +139,6 @@ public final class CxfJaxRsClientConfigurator implements JaxRsClientConfigurator register(builder, getFeatures()); register(builder, getProperties()); register(builder, getOAuthProviders(config)); - builder.register(new OseeAccountClientRequestFilter()); } @Override diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/IdParamConverter.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/IdParamConverter.java new file mode 100644 index 00000000000..81e96f4e2f5 --- /dev/null +++ b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/IdParamConverter.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2016 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.jaxrs.client.internal.ext; + +import javax.ws.rs.ext.ParamConverter; +import org.eclipse.osee.framework.jdk.core.type.Id; + +/** + * @author Ryan D. Brooks + */ +public class IdParamConverter implements ParamConverter { + @Override + public String toString(Id value) { + return String.valueOf(value.getId()); + } + + @Override + public Id fromString(String value) { + /* + * return null so that the default parameter conversion will be used. Namely that + * org.apache.cxf.jaxrs.utils.InjectionUtils.handleParameter(String, boolean, Class, Annotation[], + * ParameterType, Message) will call valueOf(String value) on the formal parameter type + */ + return null; + } +} \ No newline at end of file diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/OrcsParamConverterProvider.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/OrcsParamConverterProvider.java new file mode 100644 index 00000000000..1312b0c1404 --- /dev/null +++ b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/OrcsParamConverterProvider.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2016 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.jaxrs.client.internal.ext; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import javax.ws.rs.ext.ParamConverter; +import javax.ws.rs.ext.Provider; +import org.eclipse.osee.framework.jdk.core.type.Id; + +/** + * @author Ryan D. Brooks + */ +@Provider +public class OrcsParamConverterProvider implements javax.ws.rs.ext.ParamConverterProvider { + private final IdParamConverter idConverter = new IdParamConverter(); + + @SuppressWarnings("unchecked") + @Override + public ParamConverter getConverter(Class rawType, Type genericType, Annotation[] annotations) { + if (Id.class.isAssignableFrom(rawType)) { + return (ParamConverter) idConverter; + } + return null; + } +} \ No newline at end of file -- cgit v1.2.3