當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletContextHandler.setAttribute方法代碼示例

本文整理匯總了Java中org.eclipse.jetty.servlet.ServletContextHandler.setAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletContextHandler.setAttribute方法的具體用法?Java ServletContextHandler.setAttribute怎麽用?Java ServletContextHandler.setAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jetty.servlet.ServletContextHandler的用法示例。


在下文中一共展示了ServletContextHandler.setAttribute方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
public void start(int listenPort, String dbname) throws Exception {
    if (Objects.nonNull(server) && server.isRunning()) {
        LOG.info("ineternal webui already running at port [" + listenPort + "].");
        throw new Exception("already running at port[" + listenPort + "]");
    }
    // remove old connectors
    Connector[] oldConnectors = server.getConnectors();
    if (Objects.nonNull(oldConnectors)) {
        for (Connector oldc : oldConnectors) {
            server.removeConnector(oldc);
        }
    }
    // add new connector
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(listenPort);
    server.setConnectors(new Connector[] { connector });
    // set dbname
    ServletContextHandler contextHandler = (ServletContextHandler) server.getHandler();
    contextHandler.setAttribute("dbname", dbname);
    server.start();
    LOG.info("internal webui server started with listening port [" + listenPort + "].");
}
 
開發者ID:SecureSkyTechnology,項目名稱:burpextender-proxyhistory-webui,代碼行數:23,代碼來源:WebUIApp.java

示例2: addServlet

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
public void addServlet(String path, ServletHolder servletHolder, boolean requiresAuthentication) {
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath(path);
    context.addServlet(servletHolder, MATCH_ALL);
    context.setAttribute(WebService.ATTRIBUTE_PULSAR_NAME, pulsar);

    if (requiresAuthentication && pulsar.getConfiguration().isAuthenticationEnabled()) {
        FilterHolder filter = new FilterHolder(new AuthenticationFilter(pulsar));
        context.addFilter(filter, MATCH_ALL, EnumSet.allOf(DispatcherType.class));
    }

    FilterHolder responseFilter = new FilterHolder(new ResponseHandlerFilter(pulsar));
    context.addFilter(responseFilter, MATCH_ALL, EnumSet.allOf(DispatcherType.class));

    handlers.add(context);
}
 
開發者ID:apache,項目名稱:incubator-pulsar,代碼行數:17,代碼來源:WebService.java

示例3: initTracing

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
protected void initTracing(ServletContextHandler context) {
    client.register(new Builder(mockTracer).build());

    ServerTracingDynamicFeature serverTracingFeature =
        new ServerTracingDynamicFeature.Builder(mockTracer)
            .withOperationNameProvider(HTTPMethodOperationName.newBuilder())
            .withDecorators(Collections.singletonList(ServerSpanDecorator.STANDARD_TAGS))
            .withSkipPattern("/health")
        .build();
    // TODO clarify dispatcher types
    context.addFilter(new FilterHolder(new SpanFinishingFilter(mockTracer)), "/*",
        EnumSet.of(
            DispatcherType.REQUEST,
            DispatcherType.FORWARD,
            // TODO CXF does not call AsyncListener#onComplete() without this (it calls only onStartAsync)
            DispatcherType.ASYNC,
            DispatcherType.ERROR,
            DispatcherType.INCLUDE));

    context.setAttribute(CLIENT_ATTRIBUTE, client);
    context.setAttribute(TRACER_ATTRIBUTE, mockTracer);
    context.setAttribute(SERVER_TRACING_FEATURE, serverTracingFeature);
}
 
開發者ID:opentracing-contrib,項目名稱:java-jaxrs,代碼行數:24,代碼來源:AbstractJettyTest.java

示例4: initContext

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
private ServletContextHandler initContext(final String contextPath, final Set<Class<?>> classes) {
    final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath(contextPath);
    context.setAttribute(ATTR_CLASSES, classes);
    context.setAttribute(ATTR_DI, dependencyInjection);
    return context;
}
 
開發者ID:dajudge,項目名稱:testee.fi,代碼行數:8,代碼來源:RestServerImpl.java

示例5: startServer

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
@Override

    @Before
    public void startServer()
        throws Exception
    {
        super.startServer();

        // repo handler

        this.repoServer = new Server( 0 );

        ServletHolder shRepo = new ServletHolder( RepoServlet.class );
        ServletContextHandler contextRepo = new ServletContextHandler();

        contextRepo.setContextPath( "/" );
        contextRepo.addServlet( shRepo, "/*" );

        repoServer.setHandler( contextRepo );
        repoServer.start();
        this.repoServerPort = repoServer.getConnectors()[0].getLocalPort();

        //redirect handler

        this.redirectServer = new Server( 0 );
        ServletHolder shRedirect = new ServletHolder( RedirectServlet.class );
        ServletContextHandler contextRedirect = new ServletContextHandler();
        contextRedirect.setAttribute( "redirectToPort", Integer.toString( this.repoServerPort ) );

        contextRedirect.setContextPath( "/" );
        contextRedirect.addServlet( shRedirect, "/*" );

        redirectServer.setHandler( contextRedirect );
        redirectServer.start();
        this.redirectPort = redirectServer.getConnectors()[0].getLocalPort();
        log.info( "redirect server port {}", redirectPort );

    }
 
開發者ID:ruikom,項目名稱:apache-archiva,代碼行數:39,代碼來源:DownloadArtifactsTest.java

示例6: enableMultipartFilter

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
private void enableMultipartFilter(HttpEndpoint endpoint, Server server, String connectorKey) throws Exception {
    ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
    CamelContext camelContext = this.getCamelContext();
    FilterHolder filterHolder = new FilterHolder();
    filterHolder.setInitParameter("deleteFiles", "true");
    if (ObjectHelper.isNotEmpty(camelContext.getProperty(TMP_DIR))) {
        File file = new File(camelContext.getProperty(TMP_DIR));
        if (!file.isDirectory()) {
            throw new RuntimeCamelException(
                    "The temp file directory of camel-jetty is not exists, please recheck it with directory name :"
                            + camelContext.getProperties().get(TMP_DIR));
        }
        context.setAttribute("javax.servlet.context.tempdir", file);
    }
    // if a filter ref was provided, use it.
    Filter filter = ((JettyHttpEndpoint) endpoint).getMultipartFilter();
    if (filter == null) {
        // if no filter ref was provided, use the default filter
        filter = new MultiPartFilter();
    }
    filterHolder.setFilter(new CamelFilterWrapper(filter));
    String pathSpec = endpoint.getPath();
    if (pathSpec == null || "".equals(pathSpec)) {
        pathSpec = "/";
    }
    if (endpoint.isMatchOnUriPrefix()) {
        pathSpec = pathSpec.endsWith("/") ? pathSpec + "*" : pathSpec + "/*";
    }
    addFilter(context, filterHolder, pathSpec);
    if (LOG.isDebugEnabled()) LOG.debug("using multipart filter implementation " + filter.getClass().getName() + " for path " + pathSpec);
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:32,代碼來源:JettyHttpComponent.java

示例7: addRestResources

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
public void addRestResources(String basePath, String javaPackages, WebSocketService service) {
    JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
    provider.setMapper(ObjectMapperFactory.create());
    ResourceConfig config = new ResourceConfig();
    config.packages("jersey.config.server.provider.packages", javaPackages);
    config.register(provider);
    ServletHolder servletHolder = new ServletHolder(new ServletContainer(config));
    servletHolder.setAsyncSupported(true);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath(basePath);
    context.addServlet(servletHolder, "/*");
    context.setAttribute(ATTRIBUTE_PROXY_SERVICE_NAME, service);
    handlers.add(context);
}
 
開發者ID:apache,項目名稱:incubator-pulsar,代碼行數:15,代碼來源:ProxyServer.java

示例8: initTracing

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
@Override
protected void initTracing(ServletContextHandler context) {
    client.register(new Builder(mockTracer).build());

    ServerTracingDynamicFeature serverTracingBuilder =
        new ServerTracingDynamicFeature.Builder(mockTracer)
            .withOperationNameProvider(WildcardOperationName.newBuilder())
        .build();
    context.addFilter(new FilterHolder(new SpanFinishingFilter(mockTracer)),
        "/*", EnumSet.of(DispatcherType.REQUEST));

    context.setAttribute(TRACER_ATTRIBUTE, mockTracer);
    context.setAttribute(CLIENT_ATTRIBUTE, client);
    context.setAttribute(SERVER_TRACING_FEATURE, serverTracingBuilder);
}
 
開發者ID:opentracing-contrib,項目名稱:java-jaxrs,代碼行數:16,代碼來源:AbstractWildcardOperationNameTest.java

示例9: initTracing

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
@Override
protected void initTracing(ServletContextHandler context) {
    client.register(new Builder(mockTracer).build());

    Tracer serverTracer = NoopTracerFactory.create();
    ServerTracingDynamicFeature serverTracingBuilder =
            new ServerTracingDynamicFeature.Builder(serverTracer)
                    .build();

    context.setAttribute(TRACER_ATTRIBUTE, serverTracer);
    context.setAttribute(CLIENT_ATTRIBUTE, ClientBuilder.newClient());
    context.setAttribute(SERVER_TRACING_FEATURE, serverTracingBuilder);
}
 
開發者ID:opentracing-contrib,項目名稱:java-jaxrs,代碼行數:14,代碼來源:AbstractClientTest.java

示例10: initTracing

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
@Override
protected void initTracing(ServletContextHandler context) {
  client.register(new Builder(mockTracer).build());

  ServerTracingDynamicFeature serverTracingBuilder =
      new ServerTracingDynamicFeature.Builder(mockTracer)
          .withOperationNameProvider(ClassNameOperationName.newBuilder())
          .build();
  context.addFilter(new FilterHolder(new SpanFinishingFilter(mockTracer)),
      "/*", EnumSet.of(DispatcherType.REQUEST));

  context.setAttribute(TRACER_ATTRIBUTE, mockTracer);
  context.setAttribute(CLIENT_ATTRIBUTE, client);
  context.setAttribute(SERVER_TRACING_FEATURE, serverTracingBuilder);
}
 
開發者ID:opentracing-contrib,項目名稱:java-jaxrs,代碼行數:16,代碼來源:AbstractClassOperationNameTest.java

示例11: initTracing

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
@Override
protected void initTracing(ServletContextHandler context) {
    client.register(new Builder(mockTracer).build());

    ServerTracingDynamicFeature serverTracingBuilder =
            new ServerTracingDynamicFeature.Builder(mockTracer)
                    .build();
    context.addFilter(new FilterHolder(new SpanFinishingFilter(mockTracer)),
        "/*", EnumSet.of(DispatcherType.REQUEST));

    context.setAttribute(TRACER_ATTRIBUTE, mockTracer);
    context.setAttribute(CLIENT_ATTRIBUTE, client);
    context.setAttribute(SERVER_TRACING_FEATURE, serverTracingBuilder);
}
 
開發者ID:opentracing-contrib,項目名稱:java-jaxrs,代碼行數:15,代碼來源:AbstractServerDefaultConfigurationTest.java

示例12: enableMultipartFilter

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
private void enableMultipartFilter(HttpCommonEndpoint endpoint, Server server, String connectorKey) throws Exception {
    ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
    CamelContext camelContext = this.getCamelContext();
    FilterHolder filterHolder = new FilterHolder();
    filterHolder.setInitParameter("deleteFiles", "true");
    if (ObjectHelper.isNotEmpty(camelContext.getProperty(TMP_DIR))) {
        File file = new File(camelContext.getProperty(TMP_DIR));
        if (!file.isDirectory()) {
            throw new RuntimeCamelException(
                    "The temp file directory of camel-jetty is not exists, please recheck it with directory name :"
                            + camelContext.getProperties().get(TMP_DIR));
        }
        context.setAttribute("javax.servlet.context.tempdir", file);
    }
    // if a filter ref was provided, use it.
    Filter filter = ((JettyHttpEndpoint) endpoint).getMultipartFilter();
    if (filter == null) {
        // if no filter ref was provided, use the default filter
        filter = new MultiPartFilter();
    }
    filterHolder.setFilter(new CamelFilterWrapper(filter));
    String pathSpec = endpoint.getPath();
    if (pathSpec == null || "".equals(pathSpec)) {
        pathSpec = "/";
    }
    if (endpoint.isMatchOnUriPrefix()) {
        pathSpec = pathSpec.endsWith("/") ? pathSpec + "*" : pathSpec + "/*";
    }
    addFilter(context, filterHolder, pathSpec);
    LOG.debug("using multipart filter implementation " + filter.getClass().getName() + " for path " + pathSpec);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:32,代碼來源:JettyHttpComponent.java

示例13: initServer

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
private void initServer() {
  String host = System.getProperty("ios-driver.host");
  if (host == null) {
    host = "0.0.0.0";
  }
  server = new Server(new InetSocketAddress(host, options.getPort()));

  ServletContextHandler wd = new ServletContextHandler(server, "/wd/hub", true, false);
  wd.addServlet(
      new ServletHolder(new HttpServlet() {
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
          response.setContentType("application/json;charset=UTF-8");
          response.setCharacterEncoding("UTF-8");
          response.setStatus(200);
          response.getWriter().print("{}");
          response.getWriter().close();
          p("Received /shutdown command. Shutting down.");
          new Thread() {
            @Override
            public void run() {
              try {
                IOSServer.this.stop();
              } catch (Exception e) {
                log.warning("Exception shutting down: " + e);
                Runtime.getRuntime().exit(1);
              }
            }
          }.start();
        }
      }),
      "/shutdown");
  wd.addServlet(IOSServlet.class, "/*");

  wd.getServletContext().getContextHandler().setMaxFormContentSize(500000);
  wd.setAttribute(DRIVER, driver);
  wd.setAttribute(SERVER, this);

  ServletContextHandler extra = new ServletContextHandler(server, "/", true, false);
  extra.setAttribute(DRIVER, driver);

  HandlerList handlers = new HandlerList();
  handlers.setHandlers(new Handler[] {wd, extra});
  server.setHandler(handlers);
}
 
開發者ID:google,項目名稱:devtools-driver,代碼行數:47,代碼來源:IOSServer.java

示例14: main

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
/**
 * Server starter to initialize the server.
 * @param args
 */
public static void main(String[] args) {
    Server server = new Server(PORT);
    ServletContextHandler servhandler = new ServletContextHandler(ServletContextHandler.SESSIONS);

    VelocityEngine velocity = new VelocityEngine();
    velocity.init();

    servhandler.setResourceBase(DIR);
    servhandler.setContextPath("/");
    servhandler.setAttribute("templateEngine", velocity);

    servhandler.addServlet(IndexServlet.class, "/index");
    servhandler.addServlet(HotelServlet.class, "/hotel");
    servhandler.addServlet(CategoryServlet.class, "/category");
    servhandler.addServlet(CityServlet.class, "/city");
    servhandler.addServlet(PageServlet.class, "/page");
    servhandler.addServlet(HotelDetailServlet.class, "/hotelDetail");
    servhandler.addServlet(ReviewServlet.class, "/review");
    servhandler.addServlet(LikeServlet.class, "/like");
    servhandler.addServlet(ReviewModalServlet.class, "/reviewmodal");
    servhandler.addServlet(ShowLikeServlet.class, "/showlike");
    servhandler.addServlet(AttractionServlet.class, "/attraction");
    servhandler.addServlet(MyPageServlet.class, "/mypage");
    servhandler.addServlet(ClearServlet.class, "/clear");
    server.setHandler(servhandler);

    ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
    holderPwd.setInitParameter("dirAllowed","false");
    servhandler.addServlet(holderPwd,"/");

    System.out.println("Starting server on port " + PORT + "...");

    try {
        server.start();
        server.join();

        System.out.println("Exiting...");
    }
    catch (Exception ex) {
        System.out.println("Interrupted while running server. " + ex);
        System.exit(-1);
    }
}
 
開發者ID:brianisadog,項目名稱:hotelApp,代碼行數:48,代碼來源:JettyServer.java


注:本文中的org.eclipse.jetty.servlet.ServletContextHandler.setAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。