Java Code Examples for javax.servlet.Servlet

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project 3Dto2DApplet, under directory /src/java/nl/dannyarends/www/http/.

Source file: Webserver.java

  22 
vote

public Servlet unloadServlet(Servlet servlet){
  PathTreeDictionary registry=(PathTreeDictionary)currentRegistry.get();
  if (registry == null)   registry=defaultRegistry;
  Servlet result=null;
synchronized (registry) {
    result=(Servlet)registry.remove(servlet)[0];
  }
  return result;
}
 

Example 2

From project cipango, under directory /cipango-server/src/main/java/org/cipango/server/servlet/.

Source file: SipServletHolder.java

  22 
vote

public void handle(SipMessage message) throws ServletException, IOException {
  if (_class == null)   throw new UnavailableException("Servlet not initialized");
  Servlet servlet=_servlet;
synchronized (this) {
    if (_unavailable != 0 || !_initOnStartup)     servlet=getServlet();
    if (servlet == null)     throw new UnavailableException("Could not instantiate " + _class);
  }
  try {
    if (message.isRequest())     servlet.service((SipServletRequest)message,null);
 else     servlet.service(null,(SipServletResponse)message);
  }
  finally {
  }
}
 

Example 3

From project jetty-project, under directory /jetty-jmx-ws/src/test/java/org/mortbay/jetty/jmx/ws/service/impl/.

Source file: JMXServiceTest.java

  22 
vote

private ServletHandler createServlets(ServletHandler servletHandler){
  Servlet servlet=new DefaultServlet();
  ServletHolder servletHolder=new ServletHolder(servlet);
  servletHandler.addServletWithMapping(servletHolder,"/");
  servletHandler.addServletWithMapping(servletHolder,"/anotherPath/");
  return servletHandler;
}
 

Example 4

From project jsf-test, under directory /jetty/src/main/java/org/jboss/test/faces/jetty/.

Source file: JettyServer.java

  22 
vote

@Override public void addServlet(ServletHolder servletHolder){
  Map<String,String> initParameters=servletHolder.getInitParameters();
  String mapping=servletHolder.getMapping();
  String name=servletHolder.getName();
  Servlet servlet=servletHolder.getServlet();
  org.mortbay.jetty.servlet.ServletHolder jettyServletHolder=new org.mortbay.jetty.servlet.ServletHolder(servlet);
  jettyServletHolder.setName(name);
  jettyServletHolder.setInitParameters(initParameters);
  webAppContext.addServlet(jettyServletHolder,mapping);
}
 

Example 5

From project lime-mvc, under directory /test/org/zdevra/guice/mvc/.

Source file: AbstractTest.java

  22 
vote

public WebResponse executeSimpleUrl(String url) throws ServletException, IOException {
  ServletUnitClient sc=sr.newClient();
  WebRequest request=new GetMethodWebRequest(url);
  InvocationContext ic=sc.newInvocation(request);
  Servlet ss=ic.getServlet();
  ss.service(ic.getRequest(),ic.getResponse());
  WebResponse response=ic.getServletResponse();
  return response;
}
 

Example 6

From project org.ops4j.pax.web, under directory /pax-web-extender-war/src/main/java/org/ops4j/pax/web/extender/war/internal/.

Source file: UnregisterWebAppVisitorWC.java

  22 
vote

/** 
 * Unregisters servlet from web container.
 * @throws NullArgumentException if servlet is null
 * @see WebAppVisitor#visit(WebAppServlet)
 */
public void visit(final WebAppServlet webAppServlet){
  NullArgumentException.validateNotNull(webAppServlet,"Web app servlet");
  final Servlet servlet=webAppServlet.getServlet();
  if (servlet != null) {
    try {
      m_webContainer.unregisterServlet(servlet);
    }
 catch (    Exception ignore) {
      LOG.error("Unregistration exception. Skipping.",ignore);
    }
  }
}
 

Example 7

From project org.ops4j.pax.wicket, under directory /service/src/main/java/org/ops4j/pax/wicket/internal/.

Source file: PaxWicketAppFactoryTracker.java

  22 
vote

private void addApplication(ServiceReference reference,PaxWicketApplicationFactory internalFactory){
  if (!internalFactory.isValidFactory()) {
    LOGGER.warn("Trying to register ApplicationFactory without application name or mount point is not possible");
    return;
  }
  LOGGER.debug("Service Added [{}], Factory hash [{}]",reference,identityHashCode(internalFactory));
  Servlet servlet=ServletProxy.newServletProxy(internalFactory);
  addServlet(internalFactory.getMountPoint(),servlet,internalFactory.getContextParams(),reference);
synchronized (factories) {
    factories.put(reference,internalFactory);
  }
}
 

Example 8

From project qi4j-libraries, under directory /http/src/main/java/org/qi4j/library/http/.

Source file: JettyMixin.java

  22 
vote

private void addServlets(Context root,Iterable<ServiceReference<Servlet>> servlets){
  for (  ServiceReference<Servlet> servlet : servlets) {
    ServletInfo servletInfo=servlet.metaInfo(ServletInfo.class);
    String servletPath=servletInfo.getPath();
    Servlet servletInstance=servlet.get();
    ServletHolder holder=new ServletHolder(servletInstance);
    holder.setInitParameters(servletInfo.initParams());
    root.addServlet(holder,servletPath);
  }
}
 

Example 9

From project tiles, under directory /tiles-servlet/src/test/java/org/apache/tiles/web/util/.

Source file: ServletContextAdapterTest.java

  22 
vote

/** 
 * Test method for  {@link org.apache.tiles.web.util.ServletContextAdapter#getServlet(java.lang.String)}.
 * @throws ServletException If something goes wrong.
 */
@SuppressWarnings("deprecation") @Test public void testGetServlet() throws ServletException {
  Servlet is=createMock(Servlet.class);
  expect(servletContext.getServlet("whatever")).andReturn(is);
  replay(servletContext,config,is);
  ServletContextAdapter adapter=new ServletContextAdapter(config);
  assertEquals(is,adapter.getServlet("whatever"));
  verify(is);
}
 

Example 10

From project usergrid-stack, under directory /standalone/src/main/java/org/usergrid/standalone/.

Source file: Server.java

  22 
vote

private void mapServlet(String cls,String mapping){
  try {
    Servlet servlet=(Servlet)ClassLoaderUtil.load(cls);
    if (servlet != null) {
      ServletHandler handler=new ServletHandler(servlet);
      handler.setServletPath(mapping);
      httpServer.getServerConfiguration().addHttpHandler(handler,mapping);
    }
  }
 catch (  Exception e) {
    logger.error("Unable to add JSP page: " + mapping);
  }
  logger.info("jsp: " + JspFactory.getDefaultFactory());
}
 

Example 11

From project karaf, under directory /http/core/src/main/java/org/apache/karaf/http/core/internal/.

Source file: ServletServiceImpl.java

  21 
vote

@Override public List<ServletInfo> getServlets(){
  List<ServletInfo> servletInfos=new ArrayList<ServletInfo>();
  Collection<ServletEvent> events=servletEventHandler.getServletEvents();
  for (  ServletEvent event : events) {
    Servlet servlet=event.getServlet();
    String servletClassName=" ";
    if (servlet != null) {
      servletClassName=servlet.getClass().getName();
      servletClassName=servletClassName.substring(servletClassName.lastIndexOf(".") + 1,servletClassName.length());
    }
    String servletName=event.getServletName() != null ? event.getServletName() : " ";
    if (servletName.contains(".")) {
      servletName=servletName.substring(servletName.lastIndexOf(".") + 1,servletName.length());
    }
    String alias=event.getAlias() != null ? event.getAlias() : " ";
    String[] urls=(String[])(event.getUrlParameter() != null ? event.getUrlParameter() : new String[]{""});
    ServletInfo info=new ServletInfo();
    info.setBundle(event.getBundle());
    info.setName(servletName);
    info.setClassName(servletClassName);
    info.setState(event.getType());
    info.setAlias(alias);
    info.setUrls(urls);
    servletInfos.add(info);
  }
  return servletInfos;
}
 

Example 12

From project undertow, under directory /servlet/src/main/java/io/undertow/servlet/core/.

Source file: ManagedServlet.java

  21 
vote

@Override public InstanceHandle<? extends Servlet> getServlet() throws ServletException {
  final InstanceHandle<? extends Servlet> instanceHandle;
  final Servlet instance;
  try {
    instanceHandle=factory.createInstance();
  }
 catch (  Exception e) {
    throw UndertowServletMessages.MESSAGES.couldNotInstantiateComponent(servletInfo.getName(),e);
  }
  instance=instanceHandle.getInstance();
  instance.init(new ServletConfigImpl(servletInfo,servletContext));
  return new InstanceHandle<Servlet>(){
    @Override public Servlet getInstance(){
      return instance;
    }
    @Override public void release(){
      instance.destroy();
      instanceHandle.release();
    }
  }
;
}
 

Example 13

From project virgo.snaps, under directory /org.eclipse.virgo.snaps.core/src/main/java/org/eclipse/virgo/snaps/core/internal/webapp/container/.

Source file: ServletManager.java

  21 
vote

private void processServlets(WebXml webXml) throws SnapException {
  for (  ServletDefinition servletDefinition : webXml.getServletDefinitions()) {
    try {
      Class<?> servletClass=ManagerUtils.loadComponentClass(servletDefinition.getServletClassName(),this.classLoader);
      Servlet servlet=(Servlet)servletClass.newInstance();
      this.servlets.put(servletDefinition.getServletName(),new ServletHolder(servletDefinition,servlet));
    }
 catch (    ClassNotFoundException e) {
      logger.error(String.format("The servlet class '%s' could not be loaded by '%s'",servletDefinition.getServletClassName(),this.classLoader),e);
      throw new SnapException("The servlet class '" + servletDefinition.getServletClassName() + "' could not be loaded by "+ this.classLoader,e);
    }
catch (    InstantiationException e) {
      logger.error(String.format("The servlet class '%s' could not be instantiated",servletDefinition.getServletClassName()),e);
      throw new SnapException("The servlet class '" + servletDefinition.getServletClassName() + "' could not be instantiated",e);
    }
catch (    IllegalAccessException e) {
      logger.error(String.format("The servlet class '%s' could not be instantiated due to access restrictions",servletDefinition.getServletClassName()),e);
      throw new SnapException("The servlet class '" + servletDefinition.getServletClassName() + "' could not be instantiated due to access restrictions",e);
    }
  }
}
 

Example 14

From project agile, under directory /agile-framework/src/main/java/org/headsupdev/agile/framework/.

Source file: HeadsUpActivator.java

  19 
vote

/** 
 * Called whenever the OSGi framework starts our bundle
 */
public void start(BundleContext bc) throws Exception {
  String defaultTimeZoneId=System.getProperty("agile.runtime.timezone");
  if (defaultTimeZoneId != null) {
    Manager.getLogger(getClass().getName()).info("Detected system timezone " + defaultTimeZoneId);
    TimeZone defaultTimeZone=TimeZone.getTimeZone(defaultTimeZoneId);
    Manager.getStorageInstance().getGlobalConfiguration().setDefaultTimeZone(defaultTimeZone);
  }
  Manager.getLogger(getClass().getName()).info("Default timezone set to " + Manager.getStorageInstance().getGlobalConfiguration().getDefaultTimeZone().getID());
  Dictionary props=new Hashtable();
  props.put("alias","/");
  props.put("servlet-name","Wicket Servlet");
  bc.registerService(Servlet.class.getName(),new HeadsUpServlet(),props);
  props=new Hashtable();
  String[] urls={"/*"};
  props.put("filter-name","Wicket Filter");
  props.put("urlPatterns",urls);
  bc.registerService(Filter.class.getName(),new HeadsUpFilter(),props);
  props=new Hashtable();
  props.put("alias","/repository/*");
  bc.registerService(Servlet.class.getName(),new RepositoryServlet(),props);
  props=new Hashtable();
  props.put("alias","/favicon.ico");
  bc.registerService(Servlet.class.getName(),new FaviconServlet(),props);
  HomeApplication homeApp=new HomeApplication();
  homeApp.setContext(bc);
  props=new Properties();
  bc.registerService(Application.class.getName(),homeApp,props);
  DefaultErrorPageMapping error=new DefaultErrorPageMapping();
  error.setError("404");
  error.setLocation("/filenotfound");
  bc.registerService(ErrorPageMapping.class.getName(),error,null);
  System.out.println("Started version " + Manager.getStorageInstance().getGlobalConfiguration().getBuildVersion() + " at "+ Manager.getStorageInstance().getGlobalConfiguration().getBaseUrl());
  webTracker=new WebTracker(bc);
  webTracker.open();
  appTracker=new AppTracker(bc);
  appTracker.open();
}
 

Example 15

From project airlift, under directory /http-server/src/main/java/io/airlift/http/server/.

Source file: HttpServer.java

  19 
vote

private static ServletContextHandler createServletContext(Servlet theServlet,Map<String,String> parameters,Set<Filter> filters,TraceTokenManager tokenManager,LoginService loginService,String... connectorNames){
  ServletContextHandler context=new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
  context.addFilter(new FilterHolder(new TimingFilter()),"/*",null);
  if (tokenManager != null) {
    context.addFilter(new FilterHolder(new TraceTokenFilter(tokenManager)),"/*",null);
  }
  context.addFilter(GzipFilter.class,"/*",null);
  context.addFilter(GZipRequestFilter.class,"/*",null);
  if (loginService != null) {
    SecurityHandler securityHandler=createSecurityHandler(loginService);
    context.setSecurityHandler(securityHandler);
  }
  for (  Filter filter : filters) {
    context.addFilter(new FilterHolder(filter),"/*",null);
  }
  ServletHolder servletHolder=new ServletHolder(theServlet);
  servletHolder.setInitParameters(ImmutableMap.copyOf(parameters));
  context.addServlet(servletHolder,"/*");
  context.setConnectorNames(connectorNames);
  return context;
}
 

Example 16

From project components-ness-httpserver_1, under directory /src/main/java/com/nesscomputing/httpserver/.

Source file: SoloJetty8HttpServer.java

  19 
vote

@Inject SoloJetty8HttpServer(final SoloHttpServerConfig soloHttpServerConfig,final HttpServerConfig httpServerConfig,@Named(CATCHALL_NAME) final Servlet catchallServlet){
  super(httpServerConfig,catchallServlet);
  final ImmutableMap.Builder<String,HttpConnector> builder=ImmutableMap.builder();
  final URI[] serviceUris=soloHttpServerConfig.getServiceUris();
  Preconditions.checkState(ArrayUtils.isNotEmpty(serviceUris),"at least one valid URI must be given!");
  int count=0;
  for (  URI serviceUri : serviceUris) {
    final String scheme=serviceUri.getScheme();
    final boolean secure="https".equals(scheme);
    int port=serviceUri.getPort();
    if (port == 0) {
      port=secure ? 443 : 80;
    }
    builder.put(count == 0 ? "service" : String.format("service-%d",count),new HttpConnector(secure,scheme,serviceUri.getHost(),port));
    count++;
  }
  connectors=builder.build();
}
 

Example 17

From project core_4, under directory /impl/src/main/java/org/richfaces/webapp/.

Source file: GenericServletContainerInitializer.java

  19 
vote

/** 
 * <p> Returns the servlet registration for given  {@link Servlet} class, which has at least one mapping registered.</p> <p> Returns null otherwise. </p>
 * @param servletClass {@link Servlet} implementation class
 * @param context to search for registration
 * @return the servlet registration for given {@link Servlet} class, which has at least one mapping registered, nullotherwise.
 */
protected ServletRegistration getServletRegistration(Class<? extends Servlet> servletClass,ServletContext context){
  Collection<? extends ServletRegistration> servletRegistrations=context.getServletRegistrations().values();
  for (  ServletRegistration servletRegistration : servletRegistrations) {
    if (servletClass.getName().equals(servletRegistration.getClassName())) {
      if (servletRegistration.getMappings() != null && !servletRegistration.getMappings().isEmpty()) {
        return servletRegistration;
      }
    }
  }
  return null;
}
 

Example 18

From project IOCipherServer, under directory /src/Acme/Serve/.

Source file: Serve.java

  19 
vote

/** 
 * Adds a servlet to run
 * @param urlPat servlet invoker URL pattern
 * @param className servlet class name
 * @param initParams servlet init parameters
 */
public void addServlet(String urlPat,String className,Hashtable initParams){
  SecurityManager security=System.getSecurityManager();
  if (security != null) {
    int i=className.lastIndexOf('.');
    if (i > 0) {
      security.checkPackageAccess(className.substring(0,i));
      security.checkPackageDefinition(className.substring(0,i));
    }
  }
  try {
    addServlet(urlPat,(Servlet)Class.forName(className).newInstance(),initParams,null);
  }
 catch (  ClassNotFoundException e) {
    log("TJWS: Class not found: " + className);
    ClassLoader cl=getClass().getClassLoader();
    log("TJWS: Class loader: " + cl);
    if (cl instanceof java.net.URLClassLoader)     log("TJWS: CP: " + java.util.Arrays.asList(((java.net.URLClassLoader)cl).getURLs()));
  }
catch (  ClassCastException e) {
    log("TJWS: Servlet class doesn't implement javax.servlet.Servlet: " + e.getMessage());
  }
catch (  InstantiationException e) {
    log("TJWS: Can't instantiate servlet: " + e.getMessage());
  }
catch (  IllegalAccessException e) {
    log("TJWS: Illegal class access: " + e.getMessage());
  }
catch (  Exception e) {
    log("TJWS: Unexpected problem of servlet creation: " + e,e);
  }
}
 

Example 19

From project ios-driver, under directory /server/src/main/java/org/uiautomation/ios/server/.

Source file: IOSServer.java

  19 
vote

private void init(IOSServerConfiguration options) throws IOSAutomationSetupException {
  this.options=options;
  this.port=options.getPort();
  server=new Server(new InetSocketAddress("0.0.0.0",options.getPort()));
  ServletContextHandler wd=new ServletContextHandler(server,"/wd/hub",true,false);
  wd.addServlet(UIAScriptProxyRegister.class,"/uiascriptproxy/register/*");
  wd.addServlet(UIAScriptServlet.class,"/uiascriptproxy/*");
  wd.addServlet(IOSServlet.class,"/*");
  wd.addServlet(ResourceServlet.class,"/resources/*");
  ServletContextHandler extra=new ServletContextHandler(server,"/",true,false);
  try {
    String ide="org.uiautomation.ios.ide.IDEServlet";
    Class<?> c=Class.forName(ide);
    Class<Servlet> r=(Class<Servlet>)c;
    extra.addServlet(r,"/ide/*");
  }
 catch (  Exception e) {
    System.err.println("couldn't find ide servlet");
  }
  HandlerList handlers=new HandlerList();
  handlers.setHandlers(new Handler[]{wd,extra});
  server.setHandler(handlers);
  IOSDriver driver=new IOSDriver(port);
  for (  String app : this.options.getSupportedApps()) {
    driver.addSupportedApplication(new IOSApplication(app));
  }
  wd.setAttribute(DRIVER,driver);
  Runtime.getRuntime().addShutdownHook(new Thread(){
    public void run(){
      try {
        server.stop();
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
    }
  }
);
}
 

Example 20

From project jagger, under directory /chassis/coordinator.http/src/main/java/com/griddynamics/jagger/coordinator/http/server/jetty/.

Source file: ServletConfiguration.java

  19 
vote

public static ServletConfiguration create(Servlet servlet,String path){
  ServletConfiguration configuration=new ServletConfiguration();
  configuration.setServlet(servlet);
  configuration.setPath(path);
  return configuration;
}
 

Example 21

From project jbosgi, under directory /testsuite/example/src/test/java/org/jboss/test/osgi/example/ear/.

Source file: EnterpriseArchiveTestCase.java

  19 
vote

@Deployment(name=WAR_STRUCTURE_EAR,testable=false) public static Archive<?> getWarStructureEar(){
  final WebArchive war=ShrinkWrap.create(WebArchive.class,WAR_STRUCTURE_BUNDLE);
  war.addClasses(SimpleServlet.class);
  war.setManifest(new Asset(){
    @Override public InputStream openStream(){
      OSGiManifestBuilder builder=OSGiManifestBuilder.newInstance();
      builder.addBundleSymbolicName(war.getName());
      builder.addBundleManifestVersion(2);
      builder.addImportPackages(PostConstruct.class,WebServlet.class);
      builder.addImportPackages(Servlet.class,HttpServlet.class);
      builder.addImportPackages(Echo.class);
      builder.addBundleClasspath("WEB-INF/classes");
      return builder.openStream();
    }
  }
);
  final JavaArchive jar=ShrinkWrap.create(JavaArchive.class,ECHO_BUNDLE);
  jar.addClasses(Echo.class);
  jar.setManifest(new Asset(){
    @Override public InputStream openStream(){
      OSGiManifestBuilder builder=OSGiManifestBuilder.newInstance();
      builder.addBundleSymbolicName(jar.getName());
      builder.addBundleManifestVersion(2);
      builder.addExportPackages(Echo.class);
      return builder.openStream();
    }
  }
);
  EnterpriseArchive ear=ShrinkWrap.create(EnterpriseArchive.class,WAR_STRUCTURE_EAR);
  ear.add(jar,"/",ZipExporter.class);
  ear.addAsModule(war);
  return ear;
}
 

Example 22

From project JsTestDriver, under directory /JsTestDriver/src/com/google/jstestdriver/requesthandlers/.

Source file: RequestHandlersModule.java

  19 
vote

@Override protected void configure(){
  configureHandlers();
  bindScope(RequestScoped.class,requestScope);
  bind(RequestScope.class).toInstance(requestScope);
  bind(new Key<List<RequestMatcher>>(){
  }
).toInstance(matchers.build());
  bind(Servlet.class).to(RequestHandlerServlet.class).in(Singleton.class);
  bind(ProxyServletConfig.Factory.class).toProvider(FactoryProvider.newFactory(ProxyServletConfig.Factory.class,ProxyServletConfig.class));
  bind(ProxyRequestHandler.Factory.class).toProvider(FactoryProvider.newFactory(ProxyRequestHandler.Factory.class,ProxyRequestHandler.class));
  bind(ProxyConfiguration.class).in(Singleton.class);
}
 

Example 23

From project nettosphere, under directory /server/src/main/java/org/atmosphere/nettosphere/.

Source file: Config.java

  19 
vote

/** 
 * Add an Jersey/JAX RS that will be mapped to the specified path
 * @param path a mapping path
 * @param c    an Jersey/JAX RS
 * @return this
 */
public Builder resource(String path,Class<?> c){
  try {
    if (AtmosphereHandler.class.isAssignableFrom(c)) {
      handlers.put(path,AtmosphereHandler.class.cast(c.newInstance()));
    }
 else     if (Servlet.class.isAssignableFrom(c)) {
      handlers.put(path,new ReflectorServletProcessor(Servlet.class.cast(c.newInstance())));
    }
 else {
      staticResourcePath=path;
      initParam("com.sun.jersey.config.property.packages",c.getPackage().getName());
    }
  }
 catch (  Exception ex) {
    logger.error("Invalid resource {}",c);
  }
  return this;
}
 

Example 24

From project ontology-broker, under directory /src/org/sc/probro/.

Source file: BrokerStart.java

  19 
vote

public void addServlet(String servletName,Servlet servlet,String firstMapping,String... mappings){
  ServletHolder holder=new ServletHolder(servlet);
  holder.setName(servletName);
  context.addServlet(holder,firstMapping);
  if (mappings.length > 0) {
    ServletMapping servletMapping=new ServletMapping();
    servletMapping.setServletName(servletName);
    servletMapping.setPathSpecs(mappings);
    context.getServletHandler().addServletMapping(servletMapping);
  }
}
 

Example 25

From project openwebbeans, under directory /webbeans-tomcat6/src/main/java/org/apache/webbeans/web/tomcat/.

Source file: TomcatWebPlugin.java

  19 
vote

/** 
 * {@inheritDoc}
 */
@Override public boolean supportsJavaEeComponentInjections(Class<?> clazz){
  if (Servlet.class.isAssignableFrom(clazz) || Filter.class.isAssignableFrom(clazz) || ServletContextListener.class.isAssignableFrom(clazz)|| ServletContextAttributeListener.class.isAssignableFrom(clazz)|| HttpSessionActivationListener.class.isAssignableFrom(clazz)|| HttpSessionAttributeListener.class.isAssignableFrom(clazz)|| HttpSessionBindingListener.class.isAssignableFrom(clazz)|| HttpSessionListener.class.isAssignableFrom(clazz)|| ServletRequestListener.class.isAssignableFrom(clazz)|| ServletRequestAttributeListener.class.isAssignableFrom(clazz)|| clazz.isAnnotationPresent(WebService.class)) {
    return true;
  }
  return false;
}
 

Example 26

From project org.ops4j.pax.vaadin, under directory /pax-vaadin-service/src/main/java/org/ops4j/pax/vaadin/internal/.

Source file: Activator.java

  19 
vote

private void createAndRegisterVaadinResourceServlet(){
  Bundle vaadin=null;
  for (  Bundle bundle : bundleContext.getBundles()) {
    if ("com.vaadin".equals(bundle.getSymbolicName())) {
      vaadin=bundle;
      break;
    }
  }
  Dictionary<String,String> props;
  props=new Hashtable<String,String>();
  props.put("alias",VaadinResourceServlet._VAADIN);
  HttpServlet vaadinResourceServlet=new VaadinResourceServlet(vaadin);
  resourceService=bundleContext.registerService(Servlet.class.getName(),vaadinResourceServlet,props);
  bundleContext.registerService(VaadinResourceService.class.getName(),vaadinResourceServlet,null);
}
 

Example 27

From project Pitbull, under directory /pitbull-servlet/src/main/java/org/jboss/pitbull/servlet/.

Source file: DeploymentServletRegistration.java

  19 
vote

public void initialize(InstanceManager im,ClassLoader loader) throws Exception {
  this.im=im;
  this.config=new ServletConfig(){
    @Override public String getServletName(){
      return DeploymentServletRegistration.this.name;
    }
    @Override public ServletContext getServletContext(){
      return DeploymentServletRegistration.this.servletContext;
    }
    @Override public String getInitParameter(    String name){
      return DeploymentServletRegistration.this.getInitParameter(name);
    }
    @Override public Enumeration<String> getInitParameterNames(){
      final Iterator<String> it=DeploymentServletRegistration.this.initParameters.keySet().iterator();
      return new Enumeration<String>(){
        @Override public boolean hasMoreElements(){
          return it.hasNext();
        }
        @Override public String nextElement(){
          return it.next();
        }
      }
;
    }
  }
;
  if (servlet == null && servletClass == null) {
    servletClass=(Class<? extends Servlet>)loader.loadClass(className);
  }
  if (servlet != null) {
    servletClass=servlet.getClass();
  }
  if (SingleThreadModel.class.isAssignableFrom(servletClass)) {
    perRequest=true;
  }
  if (loadLevel >= 0 && !perRequest) {
    initializeServlet();
  }
}
 

Example 28

From project platform_3, under directory /http-server/src/main/java/com/proofpoint/http/server/.

Source file: HttpServer.java

  19 
vote

private static ServletContextHandler createServletContext(Servlet theServlet,Map<String,String> parameters,Set<Filter> filters,TraceTokenManager tokenManager,LoginService loginService,String... connectorNames){
  ServletContextHandler context=new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
  context.addFilter(new FilterHolder(new TimingFilter()),"/*",null);
  if (tokenManager != null) {
    context.addFilter(new FilterHolder(new TraceTokenFilter(tokenManager)),"/*",null);
  }
  context.addFilter(GzipFilter.class,"/*",null);
  context.addFilter(GZipRequestFilter.class,"/*",null);
  if (loginService != null) {
    SecurityHandler securityHandler=createSecurityHandler(loginService);
    context.setSecurityHandler(securityHandler);
  }
  for (  Filter filter : filters) {
    context.addFilter(new FilterHolder(filter),"/*",null);
  }
  ServletHolder servletHolder=new ServletHolder(theServlet);
  servletHolder.setInitParameters(ImmutableMap.copyOf(parameters));
  context.addServlet(servletHolder,"/*");
  context.setConnectorNames(connectorNames);
  return context;
}
 

Example 29

From project sparsemapcontent, under directory /extensions/http/src/main/java/uk/co/tfd/sm/http/content/.

Source file: StaticContentServiceFactory.java

  19 
vote

@Activate public void activate(ComponentContext componentContext) throws NamespaceException, IOException, ServletException {
  BundleContext bundleContext=componentContext.getBundleContext();
  @SuppressWarnings("unchecked") Dictionary<String,Object> properties=componentContext.getProperties();
  String[] mappings=(String[])toStringArray(properties.get(MAPPINGS),DEFAULT_MAPPINGS);
  Map<String,String> mt=Maps.newHashMap();
  loadMimeTypes(mt,"mime.types");
  loadMimeTypes(mt,"core_mime.types");
  mimeTypes=ImmutableMap.copyOf(mt);
  servlets.clear();
  if (mappings != null && mappings.length > 0) {
    for (    String location : mappings) {
      String[] mapping=StringUtils.split(location,"=",3);
      String alias=mapping[0].trim();
      String path=mapping[1].trim();
      StaticContentServlet contentServlet=new StaticContentServlet(alias,path,mimeTypes);
      Dictionary<String,String> props=new Hashtable<String,String>();
      props.put("alias",alias);
      servlets.put(contentServlet,bundleContext.registerService(Servlet.class.getName(),contentServlet,props));
      LOGGER.debug("Registering {} as {} {} ",new Object[]{contentServlet,alias,path});
    }
  }
}
 

Example 30

From project springfaces-v1, under directory /org.springframework.faces.mvc/src/main/java/org/springframework/faces/mvc/servlet/.

Source file: FacesHandlerAdapter.java

  19 
vote

/** 
 * Factory method used to construct the servlet class.
 * @return The faces servlet instance
 */
protected Servlet newFacesServlet(){
  try {
    return (Servlet)facesServletClass.newInstance();
  }
 catch (  Exception e) {
    throw new IllegalArgumentException("Unable to instanciate face servlet from the specified class " + facesServletClass.getName(),e);
  }
}
 

Example 31

From project winstone, under directory /src/java/winstone/.

Source file: ServletConfiguration.java

  19 
vote

protected void setUnavailable(Servlet unavailableServlet){
  this.unavailable=true;
  if (unavailableServlet != null) {
    Logger.log(Logger.DEBUG,Launcher.RESOURCES,"ServletConfiguration.destroy",this.servletName);
    ClassLoader cl=Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(this.webAppConfig.getLoader());
    try {
      unavailableServlet.destroy();
    }
  finally {
      Thread.currentThread().setContextClassLoader(cl);
      this.instance=null;
    }
  }
  this.webAppConfig.removeServletConfigurationAndMappings(this);
}