Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.jaxrs')
-rw-r--r--plugins/org.eclipse.osee.jaxrs/META-INF/MANIFEST.MF5
-rw-r--r--plugins/org.eclipse.osee.jaxrs/src/org/eclipse/osee/jaxrs/JacksonFeature.java114
-rw-r--r--plugins/org.eclipse.osee.jaxrs/src/org/eclipse/osee/jaxrs/JaxRsConstants.java24
-rw-r--r--plugins/org.eclipse.osee.jaxrs/src/org/eclipse/osee/jaxrs/OseeWebApplicationException.java4
4 files changed, 144 insertions, 3 deletions
diff --git a/plugins/org.eclipse.osee.jaxrs/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.jaxrs/META-INF/MANIFEST.MF
index 5bd233abb2..8db4cb3800 100644
--- a/plugins/org.eclipse.osee.jaxrs/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.jaxrs/META-INF/MANIFEST.MF
@@ -11,4 +11,7 @@ Import-Package: javax.ws.rs,
javax.ws.rs.ext,
org.eclipse.osee.framework.jdk.core.util
Export-Package: org.eclipse.osee.jaxrs
-
+Require-Bundle: org.codehaus.jackson.core;bundle-version="1.9.13",
+ org.codehaus.jackson.jaxrs;bundle-version="1.9.13",
+ org.codehaus.jackson.mapper;bundle-version="1.9.13",
+ org.codehaus.jackson.xc;bundle-version="1.9.13"
diff --git a/plugins/org.eclipse.osee.jaxrs/src/org/eclipse/osee/jaxrs/JacksonFeature.java b/plugins/org.eclipse.osee.jaxrs/src/org/eclipse/osee/jaxrs/JacksonFeature.java
new file mode 100644
index 0000000000..a0b75c8e44
--- /dev/null
+++ b/plugins/org.eclipse.osee.jaxrs/src/org/eclipse/osee/jaxrs/JacksonFeature.java
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import javax.ws.rs.RuntimeType;
+import javax.ws.rs.core.Configuration;
+import javax.ws.rs.core.Feature;
+import javax.ws.rs.core.FeatureContext;
+import javax.ws.rs.ext.Provider;
+import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
+import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
+import org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper;
+import org.codehaus.jackson.jaxrs.JsonParseExceptionMapper;
+import org.codehaus.jackson.map.DeserializationConfig;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@Provider
+public class JacksonFeature implements Feature {
+
+ private final static String JSON_FEATURE = JacksonFeature.class.getName();
+
+ public static final String JAXRS_CONFIG_PREFIX = "jaxrs";
+ public static final String JAXRS_CONFIG_PREFIX_AND_DOT = JAXRS_CONFIG_PREFIX + ".";
+ public static final String JSON_FEATURE_KEY = JAXRS_CONFIG_PREFIX_AND_DOT + "jsonFeature";
+
+ @Override
+ public boolean configure(FeatureContext context) {
+ boolean configured = false;
+ Configuration config = context.getConfiguration();
+
+ String propertyKey = getPropertyNameForRuntime(JSON_FEATURE_KEY, config.getRuntimeType());
+
+ String jsonFeature = getJsonFeature(config, propertyKey, JSON_FEATURE);
+ if (JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
+ context.property(propertyKey, JSON_FEATURE);
+
+ if (!config.isRegistered(JacksonJaxbJsonProvider.class)) {
+ for (Object object : getProviders()) {
+ context.register(object);
+ }
+ }
+ configured = true;
+ }
+ return configured;
+ }
+
+ private String getJsonFeature(Configuration config, String propertyKey, String defaultValue) {
+ String toReturn = defaultValue;
+ Map<String, Object> props = config.getProperties();
+ Object value = props != null ? props.get(propertyKey) : null;
+ if (value != null) {
+ toReturn = String.valueOf(value);
+ }
+ return toReturn;
+ }
+
+ public static String getPropertyNameForRuntime(String key, RuntimeType runtimeType) {
+ if (runtimeType != null && key.startsWith(JAXRS_CONFIG_PREFIX)) {
+ RuntimeType[] types = RuntimeType.values();
+ for (RuntimeType type : types) {
+ if (key.startsWith(JAXRS_CONFIG_PREFIX_AND_DOT + type.name().toLowerCase())) {
+ return key;
+ }
+ }
+ return key.replace(JAXRS_CONFIG_PREFIX, JAXRS_CONFIG_PREFIX_AND_DOT + runtimeType.name().toLowerCase());
+ }
+ return key;
+ }
+
+ public static List<? extends Object> getProviders() {
+ List<Object> providers = new ArrayList<Object>();
+ providers.add(JacksonFeature.newJacksonJsonProvider());
+ providers.add(JsonParseExceptionMapper.class);
+ providers.add(JsonMappingExceptionMapper.class);
+ return providers;
+ }
+
+ private static JacksonJsonProvider newJacksonJsonProvider() {
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
+ objectMapper.configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS, true);
+ objectMapper.configure(SerializationConfig.Feature.AUTO_DETECT_GETTERS, true);
+ objectMapper.configure(SerializationConfig.Feature.AUTO_DETECT_IS_GETTERS, true);
+ objectMapper.configure(SerializationConfig.Feature.USE_ANNOTATIONS, true);
+ objectMapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
+ objectMapper.configure(SerializationConfig.Feature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS, true);
+
+ objectMapper.configure(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
+ objectMapper.configure(DeserializationConfig.Feature.AUTO_DETECT_FIELDS, true);
+ objectMapper.configure(DeserializationConfig.Feature.AUTO_DETECT_SETTERS, true);
+ objectMapper.configure(DeserializationConfig.Feature.AUTO_DETECT_CREATORS, true);
+ objectMapper.configure(DeserializationConfig.Feature.USE_ANNOTATIONS, true);
+ objectMapper.configure(DeserializationConfig.Feature.USE_JAVA_ARRAY_FOR_JSON_ARRAY, true);
+ objectMapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
+ objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ return new JacksonJaxbJsonProvider(objectMapper, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS);
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.jaxrs/src/org/eclipse/osee/jaxrs/JaxRsConstants.java b/plugins/org.eclipse.osee.jaxrs/src/org/eclipse/osee/jaxrs/JaxRsConstants.java
new file mode 100644
index 0000000000..2c8a841f42
--- /dev/null
+++ b/plugins/org.eclipse.osee.jaxrs/src/org/eclipse/osee/jaxrs/JaxRsConstants.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class JaxRsConstants {
+
+ private JaxRsConstants() {
+ // Constants
+ }
+
+ public static final String OSEE_ERROR_REPONSE_HEADER = "osee-jaxrs-error-response";
+
+}
diff --git a/plugins/org.eclipse.osee.jaxrs/src/org/eclipse/osee/jaxrs/OseeWebApplicationException.java b/plugins/org.eclipse.osee.jaxrs/src/org/eclipse/osee/jaxrs/OseeWebApplicationException.java
index a9a120b05f..eb8687973f 100644
--- a/plugins/org.eclipse.osee.jaxrs/src/org/eclipse/osee/jaxrs/OseeWebApplicationException.java
+++ b/plugins/org.eclipse.osee.jaxrs/src/org/eclipse/osee/jaxrs/OseeWebApplicationException.java
@@ -11,7 +11,6 @@
package org.eclipse.osee.jaxrs;
import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.Response.StatusType;
@@ -58,7 +57,8 @@ public class OseeWebApplicationException extends WebApplicationException {
@Override
public Response getResponse() {
- return Response.status(getErrorStatus()).type(MediaType.APPLICATION_JSON_TYPE).entity(getErrorResponse()).build();
+ return Response.status(getErrorStatus()).entity(getErrorResponse()).header(
+ JaxRsConstants.OSEE_ERROR_REPONSE_HEADER, Boolean.TRUE).build();
}
public StatusType getErrorStatus() {

Back to the top