.length() > 0) ? httpMethodOverrideHeadersProperty.split(",") : null; //$NON-NLS-1$ initRegistries(); initAlternateShortcutMap(); initMediaTypeMapper(); initHandlers();
@SuppressWarnings("unchecked") @Override protected Application getApplication(DeploymentConfiguration configuration) throws ClassNotFoundException, InstantiationException, IllegalAccessException { Class<? extends Application> appClass = null; String initParameter = getInitParameter(APPLICATION_INIT_PARAM); if (initParameter != null) { if (logger.isInfoEnabled()) { logger.info(Messages.getMessage("restServletJAXRSApplicationInitParam", //$NON-NLS-1$ initParameter, APPLICATION_INIT_PARAM)); } appClass = ClassUtils.loadClass(initParameter); // let the lifecycle manager create the instance and process fields // for injection ObjectFactory<? extends Application> of = configuration.getOfFactoryRegistry().getObjectFactory(appClass); configuration.addApplicationObjectFactory(of); return of.getInstance(null); } else { throw new IllegalAccessException("Can find init parameter: " + APPLICATION_INIT_PARAM + " for rest servelt"); } } }
@Override protected DeploymentConfiguration getDeploymentConfiguration() throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException { DeploymentConfiguration deploymentConfiguration = super.getDeploymentConfiguration(); deploymentConfiguration.setFilterConfig(filterConfig); return deploymentConfiguration; } }
private void registerDefaultApplication() { try { String loadWinkApplicationsProperty = configuration.getProperties().getProperty(PROPERTY_LOAD_WINK_APPLICATIONS, Boolean.toString(true)); logger.trace("{} property is set to: {}", //$NON-NLS-1$ PROPERTY_LOAD_WINK_APPLICATIONS, loadWinkApplicationsProperty); final Set<Class<?>> classes = new ServletApplicationFileLoader(Boolean.parseBoolean(loadWinkApplicationsProperty)) .getClasses(); RegistrationUtils.InnerApplication application = new RegistrationUtils.InnerApplication(classes); application.setPriority(WinkApplication.SYSTEM_PRIORITY); configuration.addApplication(application, true); } catch (FileNotFoundException e) { throw new WebApplicationException(e); } }
buildHttpMethod(configuration.getHttpMethodOverrideHeaders(), servletRequest); this.responseStatusCode = -1; new WrappedResponse(servletRequest, servletResponse, configuration.getMediaTypeMapper()); setAttribute(HttpServletResponse.class, responseWrapper); setAttribute(HttpServletResponseWrapper.class, responseWrapper); setAttribute(ServletContext.class, configuration.getServletContext()); setAttribute(ServletConfig.class, configuration.getServletConfig()); setAttribute(FilterConfig.class, configuration.getFilterConfig()); setAttribute(WinkConfiguration.class, configuration); setAttribute(DeploymentConfiguration.class, configuration); // legacy setAttribute(ResourceRegistry.class, configuration.getResourceRegistry()); setAttribute(ProvidersRegistry.class, configuration.getProvidersRegistry()); if (configuration.isDefaultResponseCharset() || configuration.isUseAcceptCharset()) { setAttribute(MediaTypeCharsetAdjuster.class, ServerMediaTypeCharsetAdjuster.getInstance()); List<Application> apps = configuration.getApplications(); if (apps != null && !apps.isEmpty()) { setAttribute(Application.class, apps.get(0));
config.setFilterConfig(new FilterConfig() { ProvidersRegistry providers = config.getProvidersRegistry(); providers.addProvider(new DataBindingJAXRSReader(registry), 0.2, true); providers.addProvider(new DataBindingJAXRSWriter(registry), 0.2, true); config.getResponseUserHandlers().add(new TuscanyResponseHandler());
logger.trace("Setting application to " + app.toString()); deploymentConfiguration.addApplication(app, false); new Resources(deploymentConfiguration.getResourceRegistry()).log(); new Providers(deploymentConfiguration.getProvidersRegistry()).log(); new Resources(deploymentConfiguration.getResourceRegistry()).log(); new Providers(deploymentConfiguration.getProvidersRegistry()).log();
@Override public void destroy() { getRequestProcessor().getConfiguration().getProvidersRegistry().removeAllProviders(); getRequestProcessor().getConfiguration().getResourceRegistry().removeAllResources(); for (ObjectFactory<?> of : getRequestProcessor().getConfiguration() .getApplicationObjectFactories()) { of.releaseAll(null); } /* * Be sure to call super.destroy() */ super.destroy(); } }
@Override protected void initRegistries() { super.initRegistries(); InjectableFactory.setInstance(new TuscanyInjectableFactory()); }
ResourceRegistry rr = this.configuration.getResourceRegistry(); List<ResourceRecord> resourceRecords = rr.getRecords(); StringBuffer sb = new StringBuffer(); .debug(Messages .getMessage("registeredResources", (sb.toString().length() > 0) ? sb.toString() : "{}")); //$NON-NLS-1$ $NON-NLS-2$ logger.debug(this.configuration.getProvidersRegistry() .getLogFormattedProvidersList(true)); } else {
private void handleWadlRequest(HttpServletRequest request, HttpServletResponse response) { try { org.apache.wink.common.model.wadl.Application wadlDocument = null; WADLGenerator generator = new WADLGenerator(); Set<Class<?>> classes = new HashSet<Class<?>>(); classes.add(resourceClass); wadlDocument = generator.generate(binding.getURI(), classes); MessageBodyWriter<org.apache.wink.common.model.wadl.Application> writer = this.getDeploymentConfiguration().getProvidersRegistry(). getMessageBodyWriter(org.apache.wink.common.model.wadl.Application.class, org.apache.wink.common.model.wadl.Application.class, annotations, MediaType.APPLICATION_XML_TYPE, null); writer.writeTo(wadlDocument, org.apache.wink.common.model.wadl.Application.class, org.apache.wink.common.model.wadl.Application.class, annotations, MediaType.APPLICATION_XML_TYPE, null, response.getOutputStream()); } catch (Exception e) { e.printStackTrace(); } }
/** * Initializes the Response Handlers Chain (the chain that handles the * out-bound response). Usually the user won't need to override this method, * but <tt>initResponseUserHandlers</tt> instead. */ protected ResponseHandlersChain initResponseHandlersChain() { ResponseHandlersChain handlersChain = new ResponseHandlersChain(); handlersChain.addHandler(createHandler(Responses.class)); handlersChain.addHandler(createHandler(PopulateResponseStatusHandler.class)); handlersChain.addHandler(createHandler(PopulateResponseMediaTypeHandler.class)); if (responseUserHandlers != null) { for (ResponseHandler h : responseUserHandlers) { h.init(properties); handlersChain.addHandler(h); } } handlersChain.addHandler(createHandler(FlushResultHandler.class)); handlersChain.addHandler(createHandler(HeadMethodHandler.class)); logger.trace("Response handlers chain is: {}", handlersChain); //$NON-NLS-1$ return handlersChain; }
protected DeploymentConfiguration createDeploymentConfiguration() throws ClassNotFoundException, InstantiationException, IllegalAccessException { String initParameter = getInitParameter(DEPLOYMENT_CONF_PARAM); if (initParameter != null) { if (logger.isInfoEnabled()) { logger.info(Messages.getMessage("restServletUseDeploymentConfigurationParam", //$NON-NLS-1$ initParameter, DEPLOYMENT_CONF_PARAM)); } // use ClassUtils.loadClass instead of Class.forName so we have // classloader visibility into the Web module in J2EE environments Class<?> confClass = ClassUtils.loadClass(initParameter); return (DeploymentConfiguration)confClass.newInstance(); } return new DeploymentConfiguration(); }
/** * Registers resources and providers provided by the Application. The * methods adds new providers and resources and DOES NOT removes the already * registered. * * @param application - application to register * @param servletContext - current servlet context * @param requestProcessorAttribute - attribute on which the request * processor is stored. It's useful, when there are multiple rest * servlets in the system and each one has a request processor. */ public static void registerApplication(Application application, ServletContext servletContext, String requestProcessorAttribute) { RequestProcessor requestProcessor = RequestProcessor.getRequestProcessor(servletContext, requestProcessorAttribute); requestProcessor.getConfiguration().addApplication(application, false); }
(DeploymentConfiguration)msgContext.getAttribute(WinkConfiguration.class); Map<String, String> alternateShortcutMap = deploymentConfiguration.getAlternateShortcutMap(); logger.trace("alternateShortcutMap is {}", alternateShortcutMap); //$NON-NLS-1$ if (alternateShortcutMap != null) {
@Override protected void initRegistries() { super.initRegistries(); InjectableFactory.setInstance(new TuscanyInjectableFactory()); }
private void initContexts() { setAttribute(Providers.class, new ProvidersImpl(getDeploymentConfiguration() .getProvidersRegistry(), this)); setAttribute(HttpHeaders.class, new HttpHeadersImpl(this)); UriInfoImpl uriInfoImpl = new UriInfoImpl(this); setAttribute(UriInfo.class, uriInfoImpl); setAttribute(UriInfoImpl.class, uriInfoImpl); setAttribute(SecurityContext.class, new SecurityContextImpl(this)); setAttribute(Request.class, new RequestImpl(this)); setAttribute(LinkBuilders.class, new LinkBuildersImpl(this)); }
private void registerRootResources() { Properties properties = configuration.getProperties(); String registerRootResource = properties.getProperty(PROPERTY_ROOT_RESOURCE, PROPERTY_ROOT_RESOURCE_DEFAULT); logger.trace("{} property is set to: {}", PROPERTY_ROOT_RESOURCE, registerRootResource); //$NON-NLS-1$ if (registerRootResource.equals(PROPERTY_ROOT_RESOURCE_ATOM)) { RegistrationUtils.InnerApplication application = new RegistrationUtils.InnerApplication(RootResource.class); application.setPriority(WinkApplication.SYSTEM_PRIORITY); configuration.addApplication(application, true); } else if (registerRootResource.equals(PROPERTY_ROOT_RESOURCE_NONE)) { // do nothing } else { String css = properties.getProperty(PROPERTY_ROOT_RESOURCE_CSS); logger.trace("{} property is set to: {}", PROPERTY_ROOT_RESOURCE_CSS, css); //$NON-NLS-1$ HtmlServiceDocumentResource instance = new HtmlServiceDocumentResource(); if (css != null) { instance.setServiceDocumentCssPath(css); } RegistrationUtils.InnerApplication application = new RegistrationUtils.InnerApplication(instance); application.setPriority(WinkApplication.SYSTEM_PRIORITY); configuration.addApplication(application, true); } }
protected RequestHandlersChain initRequestHandlersChain() { RequestHandlersChain handlersChain = new RequestHandlersChain(); handlersChain.addHandler(createHandler(Requests.class)); handlersChain.addHandler(createHandler(ResourceInvocation.class)); handlersChain.addHandler(createHandler(SearchResultHandler.class)); String optionsHandler = properties.getProperty("org.apache.wink.server.options.handler", handlersChain.addHandler(createHandler((Class<? extends RequestHandler>)Class .forName(optionsHandler))); } catch (Exception e) { logger.trace("Could not load handlers class so adding default"); handlersChain.addHandler(createHandler(OptionsMethodHandler.class)); handlersChain.addHandler(createHandler(HeadMethodHandler.class)); handlersChain.addHandler(createHandler(FindRootResourceHandler.class)); handlersChain.addHandler(createHandler(FindResourceMethodHandler.class)); handlersChain.addHandler(createHandler(CreateInvocationParametersHandler.class)); if (requestUserHandlers != null) { for (RequestHandler h : requestUserHandlers) { handlersChain.addHandler(createHandler(InvokeMethodHandler.class)); logger.trace("Request handlers chain is: {}", handlersChain); //$NON-NLS-1$ return handlersChain;
ObjectFactory of = configuration.getOfFactoryRegistry().getObjectFactory(appClass); configuration.addApplicationObjectFactory(of);