Package org.apache.wink.server.internal

Examples of org.apache.wink.server.internal.DeploymentConfiguration


  private WinkRequestProcessor winkProvider;



  private boolean accepts(HttpServletRequest request) {
    DeploymentConfiguration deploymentConfiguration = winkProvider.getRequestProcessor().getConfiguration();
    ResourceRegistry resourceRegistry = deploymentConfiguration.getResourceRegistry();
    //FIXME: fix this to comply with externalization requirements
    //log.info("Checking acceptance of {}.", request.getRequestURI());
    return resourceRegistry.getMatchingRootResources(request.getRequestURI()).size() > 0;
  }
View Full Code Here


                oneOf(requestMock).getHeaders("Accept");
                will(returnValue(values.elements()));
            }
        });
        ServerMessageContext context =
            new ServerMessageContext(requestMock, responseMock, new DeploymentConfiguration());
        HttpHeadersImpl headers = new HttpHeadersImpl(context);
        List<MediaType> mediaTypes = headers.getAcceptableMediaTypes();
        assertEquals(1, mediaTypes.size());
        assertEquals(MediaType.TEXT_XML_TYPE, headers.getAcceptableMediaTypes().get(0));
        mockery.assertIsSatisfied();
View Full Code Here

                oneOf(requestMock).getHeaders(HttpHeaders.COOKIE);
                will(returnValue(values.elements()));
            }
        });
        ServerMessageContext context =
            new ServerMessageContext(requestMock, responseMock, new DeploymentConfiguration());
        HttpHeadersImpl headers = new HttpHeadersImpl(context);
        Map<String, Cookie> cookies = headers.getCookies();
        assertEquals(new Cookie("MyName", "MyValue", "/somewhere", null), cookies.get("MyName"));
        assertEquals(1, cookies.size());
        mockery.assertIsSatisfied();
View Full Code Here

                oneOf(requestMock).getHeaders(HttpHeaders.COOKIE);
                will(returnValue(values.elements()));
            }
        });
        ServerMessageContext context =
            new ServerMessageContext(requestMock, responseMock, new DeploymentConfiguration());
        HttpHeadersImpl headers = new HttpHeadersImpl(context);
        Map<String, Cookie> cookies = headers.getCookies();
        assertNull(cookies.get("MyName"));
        assertEquals(0, cookies.size());
        mockery.assertIsSatisfied();
View Full Code Here

                oneOf(requestMock).getHeaders(HttpHeaders.COOKIE);
                will(returnValue(values.elements()));
            }
        });
        ServerMessageContext context =
            new ServerMessageContext(requestMock, responseMock, new DeploymentConfiguration());
        HttpHeadersImpl headers = new HttpHeadersImpl(context);
        Map<String, Cookie> cookies = headers.getCookies();
        assertEquals(new Cookie("MyName", "MyValue", "/somewhere", null), cookies.get("MyName"));
        assertEquals(new Cookie("MyOtherName", "MyOtherValue", "/else", "mydomain.com"), cookies
            .get("MyOtherName"));
View Full Code Here

    @Test
    public void testServerMessageContext() {
        Mockery mockery = new Mockery();
        final HttpServletRequest request = mockery.mock(HttpServletRequest.class);
        final HttpServletResponse response = mockery.mock(HttpServletResponse.class);
        DeploymentConfiguration config = new DeploymentConfiguration();
        mockery.checking(new Expectations() {
            {
                allowing(request).getMethod(); will(returnValue(HttpMethod.GET));
            }
        });
View Full Code Here

                                                        MediaType mediaType) {
        logger.trace("setDefaultCharsetOnMediaTypeHeader({}, {}) entry", httpHeaders, mediaType); //$NON-NLS-1$

        RuntimeContext context = RuntimeContextTLS.getRuntimeContext();
        // we're on the server, so this is a safe cast
        DeploymentConfiguration config = (DeploymentConfiguration)context.getAttribute(WinkConfiguration.class);
        if (config.isDefaultResponseCharset() || config.isUseAcceptCharset()) {
            if (httpHeaders != null && (httpHeaders.isEmpty() || httpHeaders
                    .get(HttpHeaders.CONTENT_TYPE) == null)) {
                // only correct the MediaType if the MediaType was not explicitly
                // set
                logger.trace("Media Type not explicitly set on Response so going to correct charset parameter if necessary"); //$NON-NLS-1$
                if (ProviderUtils.getCharsetOrNull(mediaType) == null) { //$NON-NLS-1$
                    try {
                        String charsetValue = "UTF-8"; //$NON-NLS-1$
                        if (config.isUseAcceptCharset()) {
                            // configuration says to inspect and use the Accept-Charset header to determine response charset
                            HttpHeaders requestHeaders = null;
                            if (context != null) {
                                requestHeaders = context.getHttpHeaders();
                            }
View Full Code Here

        String acceptValue = null;
        logger.trace("alternateParameter is {}", alternateParameter); //$NON-NLS-1$
        if (alternateParameter != null) {
            // try to map alternate parameter shortcut to a real media type
            // we're on the server, so this is a safe cast
            DeploymentConfiguration deploymentConfiguration =
                (DeploymentConfiguration)msgContext.getAttribute(WinkConfiguration.class);
            Map<String, String> alternateShortcutMap =
                deploymentConfiguration.getAlternateShortcutMap();
            logger.trace("alternateShortcutMap is {}", alternateShortcutMap); //$NON-NLS-1$
            if (alternateShortcutMap != null) {
                acceptValue = alternateShortcutMap.get(alternateParameter);
            }
            if (acceptValue == null) {
View Full Code Here

        return propFile;
    }

    public void testInjectServletContfig() {
        RestServlet restServlet = (RestServlet)this.getServlet();
        DeploymentConfiguration configuration =
            restServlet.getRequestProcessor().getConfiguration();

        assertNotNull(configuration.getServletContext());
        assertNotNull(configuration.getServletConfig());
    }
View Full Code Here

        RestServlet servlet =
            (RestServlet)Class.forName("org.apache.wink.server.internal.servlet.RestServlet")
                .newInstance();

        String requestProcessorAttribute = "MOCK_REQUEST_PROCESSOR";
        DeploymentConfiguration configuration = new DeploymentConfiguration();
        configuration.init();

        RequestProcessor requestProcessor = new RequestProcessor(configuration);

        MockServletContext servletContext = new MockServletContext();
        servletContext.setAttribute(requestProcessorAttribute, requestProcessor);

        MockServletConfig servletConfig = new MockServletConfig(servletContext);
        servletConfig.addInitParameter("javax.ws.rs.Application", getApplicationClassName());
        servletConfig.addInitParameter("requestProcessorAttribute", requestProcessorAttribute);

        String propertiesFile = getPropertiesFile();
        if (propertiesFile != null) {
            servletConfig.addInitParameter("propertiesLocation", propertiesFile);
        }

        assertNull(configuration.getServletContext());
        assertNull(configuration.getServletConfig());

        ThreadLocal<MockServletInvocationTest> tls = new ThreadLocal<MockServletInvocationTest>();
        tls.set(this);
        servlet.init(servletConfig);

        DeploymentConfiguration servletConfiguration =
            servlet.getRequestProcessor().getConfiguration();

        assertEquals(configuration, servletConfiguration);

        assertNotNull(servletConfiguration.getServletContext());
        assertNotNull(servletConfiguration.getServletConfig());
    }
View Full Code Here

TOP

Related Classes of org.apache.wink.server.internal.DeploymentConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.