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


Java ResourceConfig.forApplication方法代碼示例

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


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

示例1: initJersey

import org.glassfish.jersey.server.ResourceConfig; //導入方法依賴的package包/類
/** Initialize the Jersey subsystem */
private synchronized void initJersey() throws NamespaceException, ServletException {
    if (componentContext == null) {
        //we have not yet been activated
        return;
    }
    //end of STANBOL-1073 work around
    if (componentContext == null) {
        log.debug(" ... can not init Jersey Endpoint - Component not yet activated!");
        //throw new IllegalStateException("Null ComponentContext, not activated?");
        return;
    }

    shutdownJersey();

    log.info("(Re)initializing the Stanbol Jersey subsystem");

    // register all the JAX-RS resources into a a JAX-RS application and bind it to a configurable URL
    // prefix
    DefaultApplication app = new DefaultApplication();
    String staticUrlRoot = (String) componentContext.getProperties().get(
        STATIC_RESOURCES_URL_ROOT_PROPERTY);
    String applicationAlias = (String) componentContext.getProperties().get(ALIAS_PROPERTY);

    // incrementally contribute fragment resources
    List<LinkResource> linkResources = new ArrayList<LinkResource>();
    List<ScriptResource> scriptResources = new ArrayList<ScriptResource>();
    for (WebFragment fragment : webFragments) {
        log.debug("Registering web fragment '{}' into jaxrs application", fragment.getName());
        linkResources.addAll(fragment.getLinkResources());
        scriptResources.addAll(fragment.getScriptResources());
        navigationLinks.removeAll(fragment.getNavigationLinks());
        navigationLinks.addAll(fragment.getNavigationLinks());
        app.contributeClasses(fragment.getJaxrsResourceClasses());
        app.contributeSingletons(fragment.getJaxrsResourceSingletons());
    }
    app.contributeSingletons(components);
    Collections.sort(linkResources);
    Collections.sort(scriptResources);
    Collections.sort(navigationLinks);

    // bind the aggregate JAX-RS application to a dedicated servlet
    ServletContainer container = new ServletContainer(
            ResourceConfig.forApplication(app));
    Bundle appBundle = componentContext.getBundleContext().getBundle();
    httpService.registerServlet(applicationAlias, container, getInitParams(), null);
    registeredAliases.add(applicationAlias);

    // forward the main Stanbol OSGi runtime context so that JAX-RS resources can lookup arbitrary
    // services
    servletContext = container.getServletContext();
    servletContext.setAttribute(BundleContext.class.getName(), componentContext.getBundleContext());
    layoutConfiguration.setRootUrl(applicationAlias);
    //servletContext.setAttribute(BaseStanbolResource.ROOT_URL, applicationAlias);
    layoutConfiguration.setStaticResourcesRootUrl(staticUrlRoot);
    //servletContext.setAttribute(BaseStanbolResource.STATIC_RESOURCES_ROOT_URL, staticUrlRoot);
    layoutConfiguration.setLinkResources(linkResources);
    //servletContext.setAttribute(BaseStanbolResource.LINK_RESOURCES, linkResources);
    layoutConfiguration.setScriptResources(scriptResources);
    //servletContext.setAttribute(BaseStanbolResource.SCRIPT_RESOURCES, scriptResources);
    layoutConfiguration.setNavigationsLinks(navigationLinks);
    //servletContext.setAttribute(BaseStanbolResource.NAVIGATION_LINKS, navigationLinks);
    servletContext.setAttribute(CORS_ORIGIN, corsOrigins);
    servletContext.setAttribute(CORS_ACCESS_CONTROL_EXPOSE_HEADERS, exposedHeaders);

    log.info("JerseyEndpoint servlet registered at {}", applicationAlias);
}
 
開發者ID:teamdigitale,項目名稱:ontonethub,代碼行數:68,代碼來源:JerseyEndpoint.java


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