public synchronized HttpSession getSession() { return getSession(false); }
public void init() throws ServletException { log.debug("Initialing Abdera Servlet"); manager = createServiceManager(); provider = createProvider(); log.debug("Using provider - " + provider); }
@SuppressWarnings("unchecked") public String[] getHeaderNames() { return enum2array(request.getHeaderNames()); }
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestContext reqcontext = new ServletRequestContext(provider, request, getServletContext()); FilterChain chain = new FilterChain(provider, reqcontext); try { output(request, response, chain.next(reqcontext)); } catch (Throwable t) { error("Error servicing request", t, response); return; } log.debug("Request complete"); }
public ServletRequestContext(Provider provider, HttpServletRequest request, ServletContext servletContext) { super(provider, request.getMethod(), initRequestUri(request), initBaseUri(provider, request)); this.request = request; this.servletContext = servletContext; this.session = request.getSession(false); this.principal = request.getUserPrincipal(); this.subject = provider.resolveSubject(this); this.target = initTarget(); }
private void registerServlet() throws Exception { if (registryService == null) { String msg = "Unable to Register Servlet. Registry Service Not Found."; log.error(msg); throw new Exception(msg); } if (!CarbonUtils.isRemoteRegistry()) { Dictionary servletParam = new Hashtable(2); servletParam.put("org.apache.abdera.protocol.server.Provider", "org.wso2.carbon.registry.app.RegistryProvider"); httpService.registerServlet("/registry/atom", new AbderaServlet(), servletParam, defaultHttpContext); httpService.registerServlet("/registry/tags", new AbderaServlet(), servletParam, defaultHttpContext); } registerJUDDIServlet(); httpService.registerServlet("/registry/resource", new ResourceServlet(), null, defaultHttpContext); }
protected Provider createProvider() { return manager.newProvider(getProperties(getServletConfig())); }
@SuppressWarnings("unchecked") public String[] getAttributeNames(Scope scope) { switch (scope) { case REQUEST: return enum2array(request.getAttributeNames()); case SESSION: return (session != null) ? enum2array(session.getAttributeNames()) : null; case CONTAINER: { ServletContext scontext = getServletContext(); return scontext != null ? enum2array(scontext.getAttributeNames()) : null; } } return null; }
public RequestContext setAttribute(Scope scope, String name, Object value) { switch (scope) { case REQUEST: request.setAttribute(name, value); break; case SESSION: getSession(true).setAttribute(name, value); break; case CONTAINER: { ServletContext scontext = getServletContext(); if (scontext != null) scontext.setAttribute(name, value); } } return this; }
private static IRI initBaseUri(Provider provider, HttpServletRequest request) { StringBuilder buffer = new StringBuilder((request.isSecure()) ? "https" : "http"); buffer.append("://"); buffer.append(getHost(provider, request)); int port = getPort(provider, request); if ((port != 80) && (port != 443)) { buffer.append(":"); buffer.append(port); } buffer.append(request.getContextPath()); // So that .resolve() works appropriately. buffer.append("/"); return new IRI(buffer.toString()); }
public Object getAttribute(Scope scope, String name) { switch (scope) { case REQUEST: return request.getAttribute(name); case SESSION: return (session != null) ? session.getAttribute(name) : null; case CONTAINER: { ServletContext scontext = getServletContext(); return scontext != null ? scontext.getAttribute(name) : null; } } return null; }
private void error(String message, Throwable t, HttpServletResponse response) throws IOException { if (t != null) log.error(message, t); else log.error(message); if (response.isCommitted()) { log.error("Could not write an error message as the headers & HTTP status were already committed!"); } else { response.setStatus(500); StreamWriter sw = getAbdera().newStreamWriter().setOutputStream(response.getOutputStream(), "UTF-8"); Error.create(sw, 500, message, t); sw.close(); } }
error("Internal Server Error", null, response);
@Override public void init() throws ServletException { abderaReference = getAbdera(); final String configLocation = getConfigurationLocation(); LOG.info("Reading configuration: " + configLocation); try { try { configurationParser.setConfigurationResource(new URIConfigurationResource(new URI(configLocation))); } catch (URISyntaxException ex) { configurationParser.setConfigurationResource(new FileConfigurationResource(configLocation)); } configuration = configurationParser.read(); } catch (ConfigurationParserException cpe) { LOG.error("Failed to read configuration file: " + configLocation, cpe); throw new ServletInitException(cpe.getMessage(), cpe); } applicationContextAdapter = getContextAdapter(); applicationContextAdapter.usingServletContext(getServletContext()); super.init(); }
server.setHandler(overallContext); final AbderaServlet abderaServlet = new AbderaServlet(); final ServletHolder abderaHolder = new ServletHolder(abderaServlet); abderaHolder.setInitParameter(ServiceManager.PROVIDER,
@SuppressWarnings("unchecked") public String[] getParameterNames() { return enum2array(request.getParameterNames()); }