Package org.apache.wink.common

Examples of org.apache.wink.common.RuntimeContext


            createClientRequest(method, responseEntity, responseEntityType, requestEntity);
        HandlerContext context = createHandlerContext();

        ProvidersRegistry providersRegistry = request.getAttribute(ProvidersRegistry.class);
        ClientRuntimeContext runtimeContext = new ClientRuntimeContext(providersRegistry);
        RuntimeContext saved = RuntimeContextTLS.getRuntimeContext();
        RuntimeContextTLS.setRuntimeContext(runtimeContext);

        try {
            ClientResponse response = context.doChain(request);
            int statusCode = response.getStatusCode();
View Full Code Here


                        Type genericType,
                        Annotation[] annotations,
                        MediaType mediaType,
                        MultivaluedMap<String, Object> httpHeaders,
                        OutputStream entityStream) throws IOException, WebApplicationException {
        RuntimeContext context = getRuntimeContext();
        // instantiate parameters of the asset method
        Object[] args =
            InjectableFactory.getInstance().instantiate(method.getFormalParameters(), context);
        try {
            // invoke the asset method to produce the object to write
View Full Code Here

                           Type genericType,
                           Annotation[] annotations,
                           MediaType mediaType,
                           MultivaluedMap<String, String> httpHeaders,
                           InputStream entityStream) throws IOException, WebApplicationException {
        RuntimeContext context = getRuntimeContext();
        // instantiate parameters of the asset method.
        // since the formal parameters contain an Entity parameter, it is
        // populated
        // during the call to the instantiate method. there is no need to
        // manually call
View Full Code Here

                                      new InvocationHandler() {
                                          public Object invoke(Object proxy,
                                                               Method method,
                                                               Object[] args) throws Throwable {
                                              // use runtimeContext from TLS
                                              RuntimeContext runtimeContext =
                                                  RuntimeContextTLS.getRuntimeContext();
                                              // get the real context from the
                                              // RuntimeContext
                                              Object context =
                                                  runtimeContext.getAttribute(contextClass);
                                              // invoke the method on the real
                                              // context
                                              return method.invoke(context, args);
                                          }
                                      });
View Full Code Here

        }

        if (value instanceof byte[]) {
            if (providers == null) {
                // try to get Providers from the TLS
                RuntimeContext runtimeContext = RuntimeContextTLS.getRuntimeContext();
                if (runtimeContext != null) {
                    providers = runtimeContext.getProviders();
                }

                if (providers == null) {
                    LifecycleManagersRegistry ofFactoryRegistry = new LifecycleManagersRegistry();
                    ofFactoryRegistry.addFactoryFactory(new ScopeLifecycleManager<Object>());
                    ProvidersRegistry providersRegistry =
                        new ProvidersRegistry(ofFactoryRegistry, new ApplicationValidator());

                    final Set<Class<?>> classes = new ApplicationFileLoader(true).getClasses();

                    processApplication(providersRegistry, new WinkApplication() {
                        @Override
                        public Set<Class<?>> getClasses() {
                            return classes;
                        }

                        @Override
                        public double getPriority() {
                            return WinkApplication.SYSTEM_PRIORITY;
                        }
                    });

                    providers = new ProvidersImpl(providersRegistry, runtimeContext);
                }
            }

            /*
             * Need to set a temporary RuntimeContextTLS just in case we're
             * already outside of the runtime context. This may occur when a
             * client app is retrieving the AtomContent value, expecting it to
             * be unmarshalled automatically, but we are already outside of the
             * client-server thread, and thus no longer have a RuntimeContextTLS
             * from which to retrieve or inject providers.
             */

            RuntimeContext tempRuntimeContext = RuntimeContextTLS.getRuntimeContext();
            if (tempRuntimeContext == null) {
                final Providers p = providers;
                RuntimeContextTLS.setRuntimeContext(new AbstractRuntimeContext() {
                    {
                        setAttribute(Providers.class, p);
View Full Code Here

     * @param mediaType the current media type
     * @return the chosen media type
     */
    public static MediaType setDefaultCharsetOnMediaTypeHeader(MultivaluedMap<String, Object> httpHeaders,
                                                               MediaType mediaType) {
        RuntimeContext context = RuntimeContextTLS.getRuntimeContext();
        MediaTypeCharsetAdjuster adjuster = null;
        if (context != null) {
            adjuster = context.getAttribute(MediaTypeCharsetAdjuster.class);
            if (adjuster != null) {
                return adjuster.setDefaultCharsetOnMediaTypeHeader(httpHeaders, mediaType);
            }
        }
        return mediaType;
View Full Code Here

        }

        @Override
        public ResponseBuilder location(URI location) {
            if (location != null && !location.isAbsolute()) {
                RuntimeContext rtContext = RuntimeContextTLS.getRuntimeContext();
                if (rtContext != null) {
                    UriInfo info =
                        RuntimeContextTLS.getRuntimeContext().getAttribute(UriInfo.class);
                    if (info != null) {
                        location =
View Full Code Here

                                  MultivaluedMap<String, String> httpHeaders,
                                  InputStream entityStream) throws IOException,
            WebApplicationException {
            try {
                DocumentBuilder dbuilder = documentBuilderFactory.newDocumentBuilder();
                RuntimeContext runtimeContext = RuntimeContextTLS.getRuntimeContext();
                WinkConfiguration winkConfig = runtimeContext.getAttribute(WinkConfiguration.class);
                if (winkConfig != null) {
                    Properties props = winkConfig.getProperties();
                    if (props != null) {
                        // use valueOf method to require the word "true"
                        if (!Boolean.valueOf(props.getProperty("wink.supportDTDEntityExpansion"))) {
View Full Code Here

    @Override
    public void setUp() throws Exception {
        super.setUp();
        Mockery mockery = new Mockery();
        final RuntimeContext context = mockery.mock(RuntimeContext.class);
        mockery.checking(new Expectations() {{
            allowing(context).getAttribute(WinkConfiguration.class); will(returnValue(null));
        }});
       
        RuntimeContextTLS.setRuntimeContext(context);
View Full Code Here

    public MediaType setDefaultCharsetOnMediaTypeHeader(MultivaluedMap<String, Object> httpHeaders,
                                                        MediaType mediaType) {
        logger.debug("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.debug("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";
                        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();
                            }
                            charsetValue = ProviderUtils.getCharset(mediaType, requestHeaders);
                        }
                        String newMediaTypeStr = mediaType.toString() + ";charset=" + charsetValue;
                        mediaType = MediaType.valueOf(newMediaTypeStr);
View Full Code Here

TOP

Related Classes of org.apache.wink.common.RuntimeContext

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.