From e1cddec3e1cd048728c0c354d5a26566ad1caccd Mon Sep 17 00:00:00 2001 From: Branden Visser Date: Sat, 2 Jun 2012 16:40:01 -0400 Subject: [PATCH] Need to dynamic import all to serialize JSON objects; Use null check instead of getDeploymentConfiguration() to avoid exceptions when reloading bundle. --- pom.xml | 1 + .../nakamura/wink/NakamuraWinkServlet.java | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 3a0598a..8cc81c2 100644 --- a/pom.xml +++ b/pom.xml @@ -40,6 +40,7 @@ sakai-nakamura + * javax.ws.rs;version="1.1.1", javax.ws.rs.core;version="1.1.1", diff --git a/src/main/java/org/sakaiproject/nakamura/wink/NakamuraWinkServlet.java b/src/main/java/org/sakaiproject/nakamura/wink/NakamuraWinkServlet.java index 3d958a7..e1c6bc8 100644 --- a/src/main/java/org/sakaiproject/nakamura/wink/NakamuraWinkServlet.java +++ b/src/main/java/org/sakaiproject/nakamura/wink/NakamuraWinkServlet.java @@ -35,8 +35,9 @@ import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; import java.io.IOException; +import java.util.Collection; +import java.util.Collections; import java.util.LinkedList; -import java.util.List; import javax.servlet.Servlet; import javax.servlet.ServletException; @@ -94,7 +95,7 @@ public class NakamuraWinkServlet extends RestServlet { @Reference(cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC, referenceInterface=Object.class, target="(javax.ws.rs=true)", bind="bindApplication", unbind="unbindApplication") - protected List applications = new LinkedList(); + protected Collection applications = Collections.synchronizedList(new LinkedList()); @Override protected DeploymentConfiguration getDeploymentConfiguration() { @@ -132,17 +133,20 @@ protected void service(HttpServletRequest httpServletRequest, protected void bindApplication(Object obj) { applications.add(obj); - getDeploymentConfiguration().addApplication(createApplication(obj), false); + if (deploymentConfiguration != null) { + deploymentConfiguration.addApplication(createApplication(obj), false); + } } protected void unbindApplication(Object obj) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException { applications.remove(obj); - // swap in a new requestProcessor with a rebuilt configuration - deploymentConfiguration = internalCreateDeploymentConfiguration(); - RequestProcessor requestProcessor = createRequestProcessor(); - storeRequestProcessorOnServletContext(requestProcessor); + if (deploymentConfiguration != null) { + deploymentConfiguration = internalCreateDeploymentConfiguration(); + RequestProcessor requestProcessor = createRequestProcessor(); + storeRequestProcessorOnServletContext(requestProcessor); + } } protected Application createApplication(Object obj) { @@ -166,7 +170,6 @@ private static MessageBodyWriter createJsonProvider() { private DeploymentConfiguration internalCreateDeploymentConfiguration() { try { DeploymentConfiguration result = super.getDeploymentConfiguration(); - // add the jackson provider that has jaxb compatibility result.getProvidersRegistry().addProvider(PROVIDER_JSON, 100);