com.sun.jersey.spi.container.WebApplication Java Examples

The following examples show how to use com.sun.jersey.spi.container.WebApplication. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JerseyContainerProvider.java    From recipes-rss with Apache License 2.0 5 votes vote down vote up
public NettyHandlerContainer createContainer(Class<NettyHandlerContainer> clazz, ResourceConfig config,WebApplication webApp)
           throws ContainerException {
	if (clazz != NettyHandlerContainer.class) {
		return null;
	}
	return new NettyHandlerContainer(webApp, config);
}
 
Example #2
Source File: NettyContainerProvider.java    From karyon with Apache License 2.0 5 votes vote down vote up
@Override
public NettyContainer createContainer(Class<NettyContainer> type, ResourceConfig resourceConfig,
                                      WebApplication application) throws ContainerException {
    Preconditions.checkNotNull(type);
    Preconditions.checkNotNull(application);
    if (!type.equals(NettyContainer.class)) {
        logger.error(
                "Netty container provider can only create container of type {}. Invoked to create container of type {}",
                NettyContainer.class.getName(), type.getName());
    }
    return new NettyContainer(application);
}
 
Example #3
Source File: JerseyModuleProvidesTest.java    From dagger-servlet with Apache License 2.0 5 votes vote down vote up
@Inject
public ProvidesResource(DaggerContainer daggerContainer, WebApplication webApplication, Providers providers,
                        FeaturesAndProperties featuresAndProperties, MessageBodyWorkers messageBodyWorkers,
                        ExceptionMapperContext exceptionMapperContext, ResourceContext resourceContext) {
    assertNotNull(daggerContainer);
    assertNotNull(webApplication);
    assertNotNull(providers);
    assertNotNull(featuresAndProperties);
    assertNotNull(messageBodyWorkers);
    assertNotNull(exceptionMapperContext);
    assertNotNull(resourceContext);
}
 
Example #4
Source File: JerseyRequestModule.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
@Singleton
@Provides
public HttpHeaders provideHttpHeaders(WebApplication webApplication) {
    return webApplication.getThreadLocalHttpContext().getRequest();
}
 
Example #5
Source File: NettyHandlerContainer.java    From recipes-rss with Apache License 2.0 4 votes vote down vote up
NettyHandlerContainer(WebApplication application, ResourceConfig resourceConfig) {
	this.application = application;
	this.baseUri = (String) resourceConfig.getProperty(PROPERTY_BASE_URI);
}
 
Example #6
Source File: NettyContainer.java    From karyon with Apache License 2.0 4 votes vote down vote up
WebApplication getApplication() {
    return application;
}
 
Example #7
Source File: NettyContainer.java    From karyon with Apache License 2.0 4 votes vote down vote up
public NettyContainer(WebApplication application) {
    this.application = application;
    nettyToJerseyBridge = new NettyToJerseyBridge(application);
}
 
Example #8
Source File: NettyToJerseyBridge.java    From karyon with Apache License 2.0 4 votes vote down vote up
NettyToJerseyBridge(WebApplication application) {
    this.application = application;
}
 
Example #9
Source File: DaggerContainer.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
public WebApplication getWebApplication() {
    return webApplication;
}
 
Example #10
Source File: DaggerContainer.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
@Override
protected void initiate(ResourceConfig config, WebApplication webApplication) {
    this.webApplication = webApplication;
    webApplication.initiate(config, new DaggerComponentProviderFactory(config, objectGraph, modules));
}
 
Example #11
Source File: JerseyRequestModule.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
@Singleton
@Provides
public HttpResponseContext provideResponseContext(WebApplication webApplication) {
    return webApplication.getThreadLocalHttpContext().getResponse();
}
 
Example #12
Source File: JerseyRequestModule.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
@Singleton
@Provides
public SecurityContext provideSecurityContext(WebApplication webApplication) {
    return webApplication.getThreadLocalHttpContext().getRequest();
}
 
Example #13
Source File: JerseyRequestModule.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
@Singleton
@Provides
public Request provideRequest(WebApplication webApplication) {
    return webApplication.getThreadLocalHttpContext().getRequest();
}
 
Example #14
Source File: DcCoreContainerFilterTest.java    From io with Apache License 2.0 4 votes vote down vote up
/**
 * リクエストフィルタとしてメソッド/ヘッダオーバライドを実施していることを確認.
 * X-FORWARDED-PROTO、X-FORWARDED-HOSTヘッダでリクエストUri, Base UriのPROTO, HOST部が書き換わることを確認。
 * @throws URISyntaxException URISyntaxException
 */
@Test
public void testFilterContainerRequest() throws URISyntaxException {
    // 被テストオブジェクトを準備
    DcCoreContainerFilter containerFilter = new DcCoreContainerFilter();
    // ContainerRequiestを準備
    WebApplication wa = mock(WebApplication.class);
    InBoundHeaders headers = new InBoundHeaders();
    // メソッドオーバーライド
    headers.add(DcCoreUtils.HttpHeaders.X_HTTP_METHOD_OVERRIDE, HttpMethod.OPTIONS);
    // ヘッダオーバーライド
    String authzValue = "Bearer tokenstring";
    String acceptValue = "text/html";
    String contentTypeValue = "application/xml";
    headers.add(DcCoreUtils.HttpHeaders.X_OVERRIDE, HttpHeaders.AUTHORIZATION + ": " + authzValue);
    headers.add(HttpHeaders.ACCEPT, contentTypeValue);
    headers.add(DcCoreUtils.HttpHeaders.X_OVERRIDE, HttpHeaders.ACCEPT + ": " + acceptValue);
    headers.add(HttpHeaders.CONTENT_TYPE, contentTypeValue);

    // X-FORWARDED-* 系のヘッダ設定
    String scheme = "https";
    String host = "example.org";
    headers.add(DcCoreUtils.HttpHeaders.X_FORWARDED_PROTO, scheme);
    headers.add(DcCoreUtils.HttpHeaders.X_FORWARDED_HOST, host);

    ContainerRequest request = new ContainerRequest(wa, HttpMethod.POST,
            new URI("http://dc1.example.com/hoge"),
            new URI("http://dc1.example.com/hoge/hoho"),
            headers, null);

    // HttpServletRequestのmockを準備
    HttpServletRequest mockServletRequest = mock(HttpServletRequest.class);
    when(mockServletRequest.getRequestURL()).thenReturn(new StringBuffer("http://dc1.example.com"));

    ServletContext mockServletContext = mock(ServletContext.class);
    when(mockServletContext.getContextPath()).thenReturn("");
    when(mockServletRequest.getServletContext()).thenReturn(mockServletContext);
    containerFilter.setHttpServletRequest(mockServletRequest);

    // 被テスト処理の実行
    ContainerRequest filteredRequest = containerFilter.filter(request);

    // 結果の検証。
    Assert.assertEquals(HttpMethod.OPTIONS, filteredRequest.getMethod());
    Assert.assertEquals(authzValue, filteredRequest.getHeaderValue(HttpHeaders.AUTHORIZATION));
    Assert.assertEquals(acceptValue, filteredRequest.getHeaderValue(HttpHeaders.ACCEPT));

    Assert.assertEquals(contentTypeValue, filteredRequest.getHeaderValue(HttpHeaders.CONTENT_TYPE));
    Assert.assertEquals(scheme, filteredRequest.getRequestUri().getScheme());
    Assert.assertEquals(host, filteredRequest.getRequestUri().getHost());
}
 
Example #15
Source File: JerseyRequestModule.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
@Singleton
@Provides
public HttpRequestContext provideHttpRequestContext(WebApplication webApplication) {
    return webApplication.getThreadLocalHttpContext().getRequest();
}
 
Example #16
Source File: JerseyRequestModule.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
@Singleton
@Provides
public ExtendedUriInfo provideExtendedUriInfo(WebApplication webApplication) {
    return webApplication.getThreadLocalHttpContext().getUriInfo();
}
 
Example #17
Source File: JerseyRequestModule.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
@Singleton
@Provides
public UriInfo provideUriInfo(WebApplication webApplication) {
    return webApplication.getThreadLocalHttpContext().getUriInfo();
}
 
Example #18
Source File: JerseyRequestModule.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
@Singleton
@Provides
public HttpContext provideHttpContext(WebApplication webApplication) {
    return webApplication.getThreadLocalHttpContext();
}
 
Example #19
Source File: JerseyModule.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
@Provides
public ResourceContext provideResourceContext(WebApplication webApplication) {
    return webApplication.getResourceContext();
}
 
Example #20
Source File: JerseyModule.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
@Provides
public ExceptionMapperContext provideExceptionMapperContext(WebApplication webApplication) {
    return webApplication.getExceptionMapperContext();
}
 
Example #21
Source File: JerseyModule.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
@Provides
public MessageBodyWorkers provideMessageBodyWorkers(WebApplication webApplication) {
    return webApplication.getMessageBodyWorkers();
}
 
Example #22
Source File: JerseyModule.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
@Provides
public FeaturesAndProperties provideFeaturesAndProperties(WebApplication webApplication) {
    return webApplication.getFeaturesAndProperties();
}
 
Example #23
Source File: JerseyModule.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
@Provides
public Providers provideProviders(WebApplication webApplication) {
    return webApplication.getProviders();
}
 
Example #24
Source File: JerseyModule.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
@Provides
public WebApplication webApplication(DaggerContainer daggerContainer) {
    return daggerContainer.getWebApplication();
}
 
Example #25
Source File: OptionsMethodTest.java    From io with Apache License 2.0 4 votes vote down vote up
/**
 * 認証なしのOPTIONSメソッドがリクエストされた場合にpersoniumで受け付けている全メソッドが返却されること.
 * @throws URISyntaxException URISyntaxException
 */
@Test
public void 認証なしのOPTIONSメソッドがリクエストされた場合にpersoniumで受け付けている全メソッドが返却されること() throws URISyntaxException {
    // 被テストオブジェクトを準備
    DcCoreContainerFilter containerFilter = new DcCoreContainerFilter();
    // ContainerRequiestを準備
    WebApplication wa = mock(WebApplication.class);
    InBoundHeaders headers = new InBoundHeaders();
    // X-FORWARDED-* 系のヘッダ設定
    String scheme = "https";
    String host = "example.org";
    headers.add(DcCoreUtils.HttpHeaders.X_FORWARDED_PROTO, scheme);
    headers.add(DcCoreUtils.HttpHeaders.X_FORWARDED_HOST, host);
    ContainerRequest request = new ContainerRequest(wa, HttpMethod.OPTIONS,
            new URI("http://dc1.example.com/hoge"),
            new URI("http://dc1.example.com/hoge/hoho"),
            headers, null);
    // HttpServletRequestのmockを準備
    HttpServletRequest mockServletRequest = mock(HttpServletRequest.class);
    when(mockServletRequest.getRequestURL()).thenReturn(new StringBuffer("http://dc1.example.com"));
    ServletContext mockServletContext = mock(ServletContext.class);
    when(mockServletContext.getContextPath()).thenReturn("");
    when(mockServletRequest.getServletContext()).thenReturn(mockServletContext);
    containerFilter.setHttpServletRequest(mockServletRequest);
    try {
        containerFilter.filter(request);
    } catch (WebApplicationException e) {
        Response response = e.getResponse();
        assertEquals(response.getStatus(), HttpStatus.SC_OK);
        MultivaluedMap<String, Object> meta = response.getMetadata();
        List<Object> values = meta.get("Access-Control-Allow-Methods");
        assertEquals(values.size(), 1);
        String value = (String) values.get(0);
        String[] methods = value.split(",");
        Map<String, String> masterMethods = new HashMap<String, String>();
        masterMethods.put(HttpMethod.OPTIONS, "");
        masterMethods.put(HttpMethod.GET, "");
        masterMethods.put(HttpMethod.POST, "");
        masterMethods.put(HttpMethod.PUT, "");
        masterMethods.put(HttpMethod.DELETE, "");
        masterMethods.put(HttpMethod.HEAD, "");
        masterMethods.put(com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.MERGE, "");
        masterMethods.put(com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.MKCOL, "");
        masterMethods.put(com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.MOVE, "");
        masterMethods.put(com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.PROPFIND, "");
        masterMethods.put(com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.PROPPATCH, "");
        masterMethods.put(com.fujitsu.dc.common.utils.DcCoreUtils.HttpMethod.ACL, "");
        for (String method : methods) {
            if (method.trim() == "") {
                continue;
            }
            String m = masterMethods.remove(method.trim());
            if (m == null) {
                fail("Method " + method + " is not defined.");
            }
        }
        if (!masterMethods.isEmpty()) {
            fail("UnExcpected Error.");
        }
    }
}