Package javax.servlet.http

Examples of javax.servlet.http.HttpServletResponse


  }


  // implements Response
  public OutputStream getRawOutputStream() {
    HttpServletResponse response = _getHttpServletResponse();

    if (response instanceof Response) {
      return ((Response) response).getRawOutputStream();
    }
    return null;
View Full Code Here


    if (!(request instanceof HttpServletRequest && response instanceof HttpServletResponse))
      throw new ServletException("Must be http request");

    HttpServletRequest wrappedRequest = new RequestWrapper(
                                                           (HttpServletRequest) request);
    HttpServletResponse wrappedResponse = new ResponseWrapper(
                                                              (HttpServletResponse) response);

    wrappedRequest.setAttribute("javax.servlet.include.request_uri", uri);
    wrappedRequest.setAttribute("javax.servlet.include.context_path", "");
    wrappedRequest.setAttribute("javax.servlet.include.servlet_path",
View Full Code Here

    return !PatternMatchUtils.simpleMatch(publicPattern, context.getExtensionPath());
  }

  public void handleRequest(Context context) {
    HttpServletRequest request = new JibeServletRequestWrapper(context.getServletRequest());
    HttpServletResponse servletResponse = context.getServletResponse();
    try {
      dispatcher.service(request, servletResponse);
    } catch (Exception e) {
      handleException(e, context);
    }
View Full Code Here

  public boolean applies(Context context) {
    return context.getParams().containsKey("remoteMethod");
  }

  private void writeResponse(Object retValue, Context context) {
    HttpServletResponse response = context.getServletResponse();
    if (!response.isCommitted()) {
      try {
        StringWriter writer = new StringWriter();
        if (retValue != null) {
          writer.append(JacksonUtil.toJson(retValue));
        } else {
          JsonGenerator g = JacksonUtil.getMapper().getJsonFactory().createJsonGenerator(writer);
          g.writeStartObject();
          g.writeFieldName("__cmds");
          g.writeStartArray();
          List<Object> functions = new ArrayList<Object>(context.getFunctions());
          for (Object function : functions) {
            g.writeObject(function);
          }
          g.writeEndArray();
          g.writeEndObject();
          g.close();
        }
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/javascript");
        response.setStatus(200);
        response.getWriter().write(writer.toString());
        response.getWriter().flush();
      } catch (IOException e) {
        logger.error(e.getMessage(), e);
      }

    }
View Full Code Here

import org.araneaframework.jsp.util.UiUtil;
import org.araneaframework.servlet.ServletOutputData;

public class HelloWorldService extends BaseService {
  protected void action(Path path, InputData input, OutputData output) throws Exception {
    HttpServletResponse response = ((ServletOutputData) output).getResponse();   
    response.setContentType("text/html");
       
    Writer out = new OutputStreamWriter(response.getOutputStream());
    try {
      UiUtil.writeStartTag(out, "html"); {
        UiUtil.writeStartTag(out, "head"); {
          UiUtil.writeStartTag(out, "title"); {
            out.write("Hello world!");
View Full Code Here

    return new StandardServletInputData(req);
  }
 
  public static StandardServletOutputData getOutput() {
    HttpServletRequest req = new MockHttpServletRequest();
    HttpServletResponse res = new MockHttpServletResponse();
    return new StandardServletOutputData(req, res);
  }
View Full Code Here

    log.debug("Header filter service destroyed.");
  }
 
  protected void action(Path path, InputData input, OutputData output) throws Exception {
    HttpServletRequest request = ((ServletInputData) input).getRequest();
    HttpServletResponse response = ((ServletOutputData) output).getResponse();
   
   
    if (contentType == null) {
      throw new AraneaRuntimeException("Content type not set!");
    }
   
    response.setContentType(contentType);
   
    if (!cacheable) {
      response.setHeader("Pragma", "no-cache");      
      response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
      response.setDateHeader ("Expires", 1);
    }
    else {
      response.setHeader("Cache-Control", "max-age=" + (cacheHoldingTime / 1000));
      response.setDateHeader ("Expires", System.currentTimeMillis () + cacheHoldingTime);
    }
   
    for (Iterator i = headers.entrySet().iterator(); i.hasNext();) {
      Map.Entry entry = (Map.Entry) i.next();     
      response.setHeader((String) entry.getKey(), (String) entry.getValue());   
    }
   
    for (Iterator i = cookies.entrySet().iterator(); i.hasNext();) {
      Map.Entry entry = (Map.Entry) i.next();     
      response.addCookie(new Cookie((String) entry.getKey(), (String) entry.getValue()));   
    }
   
    request.setCharacterEncoding(requestEncoding);

    childService._getService().action(path, input, output);
View Full Code Here

  public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
      FilterChain filterChain) throws IOException, ServletException
  {
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpServletResponse response = (HttpServletResponse) servletResponse;
    boolean forward = true;
    boolean handled = true;
       
    String command = request.getRequestURI().substring(request.getContextPath().length() + 1);
    if (command.indexOf(';') != -1)
      command = command.substring(0, command.indexOf(';') - 1);
       
    if (!isJmxEnabled())
    {
      response.sendError(503 ,"JMX is not enabled, unable to use cipango console. Please start Cipango with:\n" +
      "\tjava -jar start.jar --ini=start-cipango.ini --pre=etc/cipango-jmx.xml");
      return;
    }
   
    Principal principal = request.getUserPrincipal();
    if (principal != null && !principal.equals(request.getSession().getAttribute(Principal.class.getName())))
    {   
      _logger.info("User " + principal.getName() + " has logged in console");
      request.getSession().setAttribute(Principal.class.getName(), principal);
    }
   
    Menu menuPrinter = getMenuFactory().getMenu(command, request.getContextPath());
    try
    {

      if (command == null || command.equals(""))
      {
        forward = false;
        response.sendRedirect(MenuPrinter.ABOUT.getName());
        return;
      }
      Page currentPage = menuPrinter.getCurrentPage();
     
      if (currentPage != null && !currentPage.isEnabled(_mbsc))
      {
        forward = false;
        request.getSession().setAttribute(Attributes.WARN, "The page " + command + " is not available");
        response.sendRedirect(MenuPrinter.ABOUT.getName());
        return;
      }
       
      if (currentPage != null)
      {
        registerActions();
        Action action = getAction(currentPage, request);
        if (action != null)
        {
          action.process(request);
          forward = false;
          if (action.isAjax(request))
          {
            action.setAjaxContent(request, response);
            return;
          }
          else
            response.sendRedirect(command);
        }
      }

      if (command.equals(MenuPrinter.CONFIG_SIP.getName()))
        doSipConfig(request);
      else if (command.equals(MenuPrinter.MAPPINGS.getName()))
      {
        request.setAttribute(Attributes.JAVASCRIPT_SRC, "javascript/upload.js");
        request.setAttribute(Attributes.CONTENT, new ApplicationPrinter(_mbsc));
      }
      else if (command.equals(MenuPrinter.STATISTICS_SIP.getName()))
        request.setAttribute(Attributes.CONTENT, new SipStatisticPrinter(_mbsc, _statisticGraph,
            (Integer) request.getSession().getAttribute(Parameters.TIME)));
      else if (command.equals(MenuPrinter.ABOUT.getName()))
        doAbout(request);
      else if (command.equals(MenuPrinter.SYSTEM_PROPERTIES.getName()))
        request.setAttribute(Attributes.CONTENT, new SystemPropertiesPrinter());
      else if (command.equals(MenuPrinter.CONFIG_DIAMETER.getName()))
        doDiameterConfig(request);
      else if (command.equals(MenuPrinter.STATISTICS_DIAMETER.getName()))
        request.setAttribute(Attributes.CONTENT, new DiameterStatisticsPrinter(_mbsc));
      else if (command.equals(MenuPrinter.CONFIG_HTTP.getName()))
        doHttpConfig(request);
      else if (command.equals(MenuPrinter.STATISTICS_HTTP.getName()))
        request.setAttribute(Attributes.CONTENT, new HttpStatisticsPrinter(_mbsc));
      else if (command.equals(MenuPrinter.HTTP_LOGS.getName()))
        request.setAttribute(Attributes.CONTENT, new FileLogPrinter(_mbsc, MenuPrinter.HTTP_LOGS, HTTP_LOG, false));
      else if (command.equals(MenuPrinter.DAR.getName()))
        request.setAttribute(Attributes.CONTENT, new DarPrinter(_mbsc));
      else if (command.equals("statisticGraph.png"))
      {
        forward = false;
        doGraph(request, response);
      }
      else if (command.equals(MenuPrinter.SIP_LOGS.getName()))
      {
        request.setAttribute(Attributes.JAVASCRIPT_SRC, "javascript/jquery-1.6.1.js,javascript/webSocket.js");
        request.setAttribute(Attributes.CONTENT, new SipLogPrinter(_mbsc, request, Output.HTML));
      }
      else if (command.equals(MenuPrinter.DIAMETER_LOGS.getName()))
        request.setAttribute(Attributes.CONTENT, new DiameterLogPrinter(_mbsc, request, Output.HTML));
      else if (command.equals(MenuPrinter.CONFIG_SNMP.getName()))
      {
        MultiplePrinter printer = new MultiplePrinter();
        ObjectName[] connectors = (ObjectName[]) _mbsc.getAttribute(SNMP_AGENT, "connectors");
        printer.add(new SetPrinter(connectors, "snmp.connectors", _mbsc));
       
        ObjectName[] traps = (ObjectName[]) _mbsc.getAttribute(SNMP_AGENT, "trapReceivers");
        printer.add(new SetPrinter(traps, "snmp.trap", _mbsc));
        request.setAttribute(Attributes.CONTENT, printer);
      }
      else if (command.equals(MenuPrinter.CALLS.getName()))
        request.setAttribute(Attributes.CONTENT, new CallsPrinter(_mbsc, request.getParameter("callID")));
      else if (command.equals("message.log"))
      {
        forward = false;
        response.setContentType("text/plain");
        PrintWriter out = response.getWriter();
        new SipLogPrinter(_mbsc, request, Output.TEXT).print(out);
      }
      else if (command.equals("diameter.log"))
      {
        forward = false;
        response.setContentType("text/plain");
        PrintWriter out = response.getWriter();
        new DiameterLogPrinter(_mbsc, request, Output.TEXT).print(out);
      }
      else if (command.equals("message.svg"))
      {
        forward = false;
        doMessageSvg(request, response);
      }
      else if (command.equals("dump.txt"))
      {
        forward = false;
        response.setContentType("text/plain");
        response.setBufferSize(65536);
        new DumpPrinter(getMbsc(), this).print(response.getWriter());
      }
      else if (doResource(command, response))
      {
        forward = false;
      }
      else if (currentPage != null && currentPage.isDynamic())
      {
        request.setAttribute(Attributes.CONTENT, new OamPrinter(_mbsc, request, currentPage.getObjectName()));
      }
      else
      {
        ObjectName objectName = new ObjectName("org.cipango.console", "page", command);
        if (_mbsc.isRegistered(objectName))
          request.setAttribute(Attributes.CONTENT, new OamPrinter(_mbsc, request, objectName));
        else
        {
          handled = false;
          forward = false;
        }
      }
     
    }
    catch (Throwable e)
    {
      _logger.warn("Unable to process request: {}", request.getRequestURL().toString(), e);
      _logger.debug("Unable to process request: " +  request.getRequestURL().toString(), e);
      HtmlPrinter printer = new ErrorPrinter(e.toString());
      response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
      request.setAttribute(Attributes.CONTENT, printer);
    }
    finally
    {
      if (!handled)
        filterChain.doFilter(request, response);
      else if (forward)
      {
        request.setAttribute(Attributes.MENU, menuPrinter);
        response.setContentType("text/html");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        response.setDateHeader("Expires", 0);
        request.getRequestDispatcher("/WEB-INF/template.jsp").forward(request, response);
      }
    }
  }
View Full Code Here

  @Override
  public void doFilter(ServletRequest request, ServletResponse response)
    throws ServletException, IOException
  {
    HttpServletResponse res = (HttpServletResponse) response;

    res.addHeader(_name, _value);

    _next.doFilter(request, response);
  }
View Full Code Here

  @Override
  public Principal getUserPrincipalImpl(HttpServletRequest request)
  {
    ServletContext app = request.getServletContext();

    HttpServletResponse response = null;
   
    return getUserPrincipal(request, response, app);
  }
View Full Code Here

TOP

Related Classes of javax.servlet.http.HttpServletResponse

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.