Author: ogrisel
Date: Mon Mar 28 19:44:08 2011
New Revision: 1086358
URL: http://svn.apache.org/viewvc?rev=1086358&view=rev
Log:
STANBOL-120: fixing issues with registration of the enhancer WebFragment
Removed:
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/writers/
incubator/stanbol/branches/http-endpoint-refactoring/enhancer/jersey/src/main/resources/org/apache/stanbol/enhancer/jersey/templates/org/apache/stanbol/enhancer/jersey/resource/EnhancerRootResource/
Modified:
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/JerseyEndpoint.java
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/resources/META-INF/templates/org/apache/stanbol/commons/web/resource/StanbolRootResource/index.ftl
Modified:
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/JerseyEndpoint.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/JerseyEndpoint.java?rev=1086358&r1=1086357&r2=1086358&view=diff
==============================================================================
---
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/JerseyEndpoint.java
(original)
+++
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/java/org/apache/stanbol/commons/web/JerseyEndpoint.java
Mon Mar 28 19:44:08 2011
@@ -54,10 +54,14 @@ public class JerseyEndpoint {
@Reference
HttpService httpService;
+ protected ComponentContext componentContext;
+
protected ServletContext servletContext;
protected final List<WebFragment> webFragments = new
ArrayList<WebFragment>();
+ protected ArrayList<String> registeredAlias;
+
public Dictionary<String,String> getInitParams() {
Dictionary<String,String> initParams = new Hashtable<String,String>();
// make jersey automatically turn resources into Viewable models and
@@ -68,6 +72,8 @@ public class JerseyEndpoint {
@Activate
protected void activate(ComponentContext ctx) throws IOException,
ServletException, NamespaceException {
+ this.componentContext = ctx;
+ this.registeredAlias = new ArrayList<String>();
// register all the JAX-RS resources into a a JAX-RS application and
bind it to a configurable URL
// prefix
@@ -82,24 +88,28 @@ public class JerseyEndpoint {
// register the root of static resources
httpService.registerResources(staticUrlRoot, staticClasspath, null);
+ registeredAlias.add(staticUrlRoot);
// incrementally contribute fragment resources
for (WebFragment fragment : webFragments) {
+ log.info("Registering web fragment '{}' into jaxrs application",
fragment.getName());
app.contributeClasses(fragment.getJaxrsResourceClasses());
app.contributeSingletons(fragment.getJaxrsResourceSingletons());
app.contributeTemplateLoader(fragment.getTemplateLoader());
- httpService.registerResources(staticUrlRoot + '/' +
fragment.getName(),
- fragment.getStaticResourceClassPath(), null);
+ String resourceAlias = staticUrlRoot + '/' + fragment.getName();
+ httpService.registerResources(resourceAlias,
fragment.getStaticResourceClassPath(), null);
+ registeredAlias.add(resourceAlias);
}
- log.info("Registering servlets with HTTP service " +
httpService.toString());
+
ServletContainer container = new ServletContainer(app);
String alias = (String) ctx.getProperties().get(ALIAS_PROPERTY);
-
+
// TODO: check whether this class-loading hack is still necessary or
not
ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try {
httpService.registerServlet(alias, container, getInitParams(),
null);
+ registeredAlias.add(alias);
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
@@ -109,14 +119,14 @@ public class JerseyEndpoint {
servletContext = container.getServletContext();
servletContext.setAttribute(BundleContext.class.getName(),
ctx.getBundleContext());
servletContext.setAttribute(STATIC_RESOURCES_URL_ROOT_PROPERTY,
staticUrlRoot);
- log.info("Jersey servlet registered at {}", alias);
+ log.info("JerseyEndpoint servlet registered at {}", alias);
}
@Deactivate
protected void deactivate(ComponentContext ctx) {
- log.info("Deactivating jersey bundle");
- String alias = (String) ctx.getProperties().get(ALIAS_PROPERTY);
- httpService.unregister(alias);
+ for (String alias : registeredAlias) {
+ httpService.unregister(alias);
+ }
servletContext = null;
}
@@ -128,13 +138,25 @@ public class JerseyEndpoint {
this.httpService = null;
}
- protected void bindWebFragment(WebFragment webFragment) {
+ protected void bindWebFragment(WebFragment webFragment) throws IOException,
+ ServletException,
+ NamespaceException {
// TODO: support some ordering for jax-rs resource and template
overrides?
webFragments.add(webFragment);
+ if (componentContext != null) {
+ deactivate(componentContext);
+ activate(componentContext);
+ }
}
- protected void unbindWebFragment(WebFragment webFragment) {
+ protected void unbindWebFragment(WebFragment webFragment) throws
IOException,
+ ServletException,
+
NamespaceException {
webFragments.remove(webFragment);
+ if (componentContext != null) {
+ deactivate(componentContext);
+ activate(componentContext);
+ }
}
}
Modified:
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/resources/META-INF/templates/org/apache/stanbol/commons/web/resource/StanbolRootResource/index.ftl
URL:
http://svn.apache.org/viewvc/incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/resources/META-INF/templates/org/apache/stanbol/commons/web/resource/StanbolRootResource/index.ftl?rev=1086358&r1=1086357&r2=1086358&view=diff
==============================================================================
---
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/resources/META-INF/templates/org/apache/stanbol/commons/web/resource/StanbolRootResource/index.ftl
(original)
+++
incubator/stanbol/branches/http-endpoint-refactoring/commons/web/src/main/resources/META-INF/templates/org/apache/stanbol/commons/web/resource/StanbolRootResource/index.ftl
Mon Mar 28 19:44:08 2011
@@ -1,5 +1,4 @@
<#import "/imports/common.ftl" as common>
-<#import "/imports/sparql.ftl" as sparql>
<#escape x as x?html>
<@common.page title="Welcome to Apache Stanbol!" hasrestapi=false>