Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2012 EclipseSource and others. 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: Holger Staudacher - initial API and implementation Dragos Dascalita - disbaled autodiscovery /
 
 package com.eclipsesource.jaxrs.publisher.internal;
 
 import java.util.List;
 
 import  javax.servlet.ServletException;
 
 import  org.glassfish.jersey.server.ResourceConfig;
 import  org.glassfish.jersey.server.ServerProperties;
 import  org.glassfish.jersey.servlet.ServletContainer;
 import  org.osgi.service.http.HttpService;
 import  org.osgi.service.http.NamespaceException;
 
 
 public class JerseyContext {
 
   private final RootApplication application;
   private ServletContainer servletContainer;
   private final HttpService httpService;
   private final String rootPath;
   private boolean isApplicationRegistered;
 
   public JerseyContext( HttpService httpServiceString rootPath ) {
     this. = httpService;
     this. = rootPath == null ? "/services" : rootPath;
     this. = new RootApplication();
     this. = new ServletContainer( ResourceConfig.forApplication(  ) );
   }
 
   private void disableAutoDiscovery() {
     // don't look for implementations described by META-INF/services/*
     this..addProperty(ServerProperties.METAINF_SERVICES_LOOKUP_DISABLE, false );
     // disable auto discovery on server, as it's handled via OSGI
     this..addProperty(ServerProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true );
   }
 
   public void addResourceObject resource ) {
     getRootApplication().addResourceresource );
     if ) {
       ClassLoader original = getContextClassloader();
       try {
         Thread.currentThread().setContextClassLoaderRequest.class.getClassLoader() );
         getServletContainer().reload( ResourceConfig.forApplication(  ) );
       } finally {
         resetContextClassloaderoriginal );
       }
     }
   }
 
     if( ! ) {
        = true;
       registerApplication();
     }
   }
 
   private void registerApplication() {
     ClassLoader loader = getContextClassloader();
     try {
       registerServlet();
     } catch( ServletException shouldNotHappen ) {
       throw new IllegalStateExceptionshouldNotHappen );
     } catch( NamespaceException shouldNotHappen ) {
       throw new IllegalStateExceptionshouldNotHappen );
     } finally {
       resetContextClassloaderloader );
     }
   }
 
     return Thread.currentThread().getContextClassLoader();
   }
 
   private void setContextClassloader() {
   }
 
   private void registerServlet() throws ServletException, NamespaceException {
     ClassLoader original = getContextClassloader();
     try {
       .registerServlet( 
                                    getServletContainer(), 
                                   null
                                   null );
    } finally {
      resetContextClassloaderoriginal );
    }
  }
  private void resetContextClassloaderClassLoader loader ) {
    Thread.currentThread().setContextClassLoaderloader );
  }
  
  public void removeResourceObject resource ) {
    getRootApplication().removeResourceresource );
    if ) {
      getServletContainer().reload( ResourceConfig.forApplication(  ) );
    }
  }
    if( !getRootApplication().hasResources() ) {
      .unregister(  );
       = new ServletContainer( ResourceConfig.forApplication(  ) );
       = false;
    }
  }
  public List<Objecteliminate() {
    getServletContainer().destroy();
    try {
      .unregister(  );
    } catchIllegalArgumentException iae ) {
      // do nothing
    }
    return new ArrayList<Object>( getRootApplication().getSingletons() );
  }
  // For testing purpose
  ServletContainer getServletContainer() {
    return ;
  }
  
  // For testing purpose
    return ;
  }
New to GrepCode? Check out our FAQ X