Skip to content

Commit

Permalink
Need to dynamic import all to serialize JSON objects; Use null check …
Browse files Browse the repository at this point in the history
…instead of getDeploymentConfiguration() to avoid exceptions when reloading bundle.
  • Loading branch information
mrvisser committed Jun 2, 2012
1 parent 7c64414 commit e1cddec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<configuration>
<instructions>
<Bundle-Category>sakai-nakamura</Bundle-Category>
<DynamicImport-Package>*</DynamicImport-Package>
<Export-Package>
javax.ws.rs;version="1.1.1",
javax.ws.rs.core;version="1.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Object> applications = new LinkedList<Object>();
protected Collection<Object> applications = Collections.synchronizedList(new LinkedList<Object>());

@Override
protected DeploymentConfiguration getDeploymentConfiguration() {
Expand Down Expand Up @@ -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) {
Expand All @@ -166,7 +170,6 @@ private static MessageBodyWriter<Object> createJsonProvider() {
private DeploymentConfiguration internalCreateDeploymentConfiguration() {
try {
DeploymentConfiguration result = super.getDeploymentConfiguration();

// add the jackson provider that has jaxb compatibility
result.getProvidersRegistry().addProvider(PROVIDER_JSON, 100);

Expand Down

0 comments on commit e1cddec

Please sign in to comment.