Package org.mortbay.jetty

Examples of org.mortbay.jetty.Request


        //TODO
        //do we need to check that this request should be handled by this handler?
        if (! target.startsWith(contextPath)) {
            return;
        }
        Request jettyRequest = (Request) req;
        Response jettyResponse = (Response) res;
        res.setContentType("text/xml");
        RequestAdapter request = new RequestAdapter(jettyRequest);
        ResponseAdapter response = new ResponseAdapter(jettyResponse);

        request.setAttribute(WebServiceContainer.SERVLET_REQUEST, req);
        request.setAttribute(WebServiceContainer.SERVLET_RESPONSE, res);
        // TODO: add support for context
        request.setAttribute(WebServiceContainer.SERVLET_CONTEXT, null);

        if (req.getParameter("wsdl") != null) {
            try {
                webServiceContainer.getWsdl(request, response);
                jettyRequest.setHandled(true);
            } catch (IOException e) {
                throw e;
            } catch (Exception e) {
                throw (HttpException) new HttpException(500, "Could not fetch wsdl!").initCause(e);
            }
        } else {
            if (isConfidentialTransportGuarantee) {
                if (!req.isSecure()) {
                    throw new HttpException(403, null);
                }
            } else if (isIntegralTransportGuarantee) {
                if (!jettyRequest.getConnection().isIntegral(jettyRequest)) {
                    throw new HttpException(403, null);
                }
            }
            Thread currentThread = Thread.currentThread();
            ClassLoader oldClassLoader = currentThread.getContextClassLoader();
            currentThread.setContextClassLoader(classLoader);
            //hard to imagine this could be anything but null, but....
//            Subject oldSubject = ContextManager.getCurrentCaller();
            try {
                if (authenticator != null) {
                    String pathInContext = org.mortbay.util.URIUtil.canonicalPath(req.getContextPath());
                    if (authenticator.authenticate(realm, pathInContext, jettyRequest, jettyResponse) == null) {
                        throw new HttpException(403, null);
                    }
                } else {
                    //EJB will figure out correct defaultSubject shortly
                    //TODO consider replacing the GenericEJBContainer.DefaultSubjectInterceptor with this line
                    //setting the defaultSubject.
                    ContextManager.popCallers(null);
                }
                try {
                    webServiceContainer.invoke(request, response);
                    jettyRequest.setHandled(true);
                } catch (IOException e) {
                    throw e;
                } catch (Exception e) {
                    throw (HttpException) new HttpException(500, "Could not process message!").initCause(e);
                }
View Full Code Here


        //TODO
        //do we need to check that this request should be handled by this handler?
        if (! target.startsWith(contextPath)) {
            return;
        }
        Request jettyRequest = (Request) req;
        Response jettyResponse = (Response) res;
        RequestAdapter request = new RequestAdapter(jettyRequest);
        ResponseAdapter response = new ResponseAdapter(jettyResponse);

        request.setAttribute(WebServiceContainer.SERVLET_REQUEST, req);
        request.setAttribute(WebServiceContainer.SERVLET_RESPONSE, res);
        // TODO: add support for context
        request.setAttribute(WebServiceContainer.SERVLET_CONTEXT, null);

        if (req.getParameter("wsdl") != null) {
            try {
                webServiceContainer.getWsdl(request, response);
                //WHO IS RESPONSIBLE FOR CLOSING OUT?
            } catch (IOException e) {
                throw e;
            } catch (Exception e) {
                throw (HttpException) new HttpException(500, "Could not fetch wsdl!").initCause(e);
            }
        } else {
            if (isConfidentialTransportGuarantee) {
                if (!req.isSecure()) {
                    throw new HttpException(403, null);
                }
            } else if (isIntegralTransportGuarantee) {
                if (!jettyRequest.getConnection().isIntegral(jettyRequest)) {
                    throw new HttpException(403, null);
                }
            }
            Thread currentThread = Thread.currentThread();
            ClassLoader oldClassLoader = currentThread.getContextClassLoader();
            currentThread.setContextClassLoader(classLoader);
            //hard to imagine this could be anything but null, but....
//            Subject oldSubject = ContextManager.getCurrentCaller();
            try {
                if (authenticator != null) {
                    String pathInContext = org.mortbay.util.URIUtil.canonicalPath(req.getContextPath());
                    if (authenticator.authenticate(realm, pathInContext, jettyRequest, jettyResponse) == null) {
                        throw new HttpException(403, null);
                    }
                } else {
                    //EJB will figure out correct defaultSubject shortly
                    //TODO consider replacing the GenericEJBContainer.DefaultSubjectInterceptor with this line
                    //setting the defaultSubject.
                    ContextManager.popCallers(null);
                }
                try {
                    webServiceContainer.invoke(request, response);
                    jettyRequest.setHandled(true);
                } catch (IOException e) {
                    throw e;
                } catch (Exception e) {
                    throw (HttpException) new HttpException(500, "Could not process message!").initCause(e);
                }
View Full Code Here

        {
            public void handle( String target, HttpServletRequest servletRequest, HttpServletResponse response,
                                int dispatch ) throws IOException,
                ServletException
            {
                Request request = (Request) servletRequest;
                try
                {
                    Thread.sleep( 1000 );
                }
                catch ( InterruptedException e )
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                request.setHandled( true );
            }
        } );
        try
        {
            server.start();
View Full Code Here

            public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException
            {
                int i=0;
                try
                {
                    Request base_request=(request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
                    base_request.setHandled(true);
                    response.setStatus(200);
                    _count.incrementAndGet();
                   
                    if (request.getServerName().equals("jetty.mortbay.org"))
                    {
View Full Code Here

    @Override
    public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException
    {
        setRequestedId(request, dispatch);

        Request currentRequest = (request instanceof Request) ? (Request)request : HttpConnection.getCurrentConnection().getRequest();

        SessionManager requestSessionManager = currentRequest.getSessionManager();
        HttpSession requestSession = currentRequest.getSession(false);

        TerracottaSessionManager sessionManager = (TerracottaSessionManager)getSessionManager();
        Log.debug("SessionManager = {}", sessionManager);

        // Is it a cross context dispatch or a direct hit to this context ?
        if (sessionManager != requestSessionManager)
        {
            // Setup the request for this context
            currentRequest.setSessionManager(sessionManager);
            currentRequest.setSession(null);
        }

        // Tell the session manager that the request is entering
        if (sessionManager != null) sessionManager.enter(currentRequest);
        try
        {
            HttpSession currentSession = null;
            if (sessionManager != null)
            {
                currentSession = currentRequest.getSession(false);
                if (currentSession != null)
                {
                    if (currentSession != requestSession)
                    {
                        // Access the session only if we did not already
                        Cookie cookie = sessionManager.access(currentSession, request.isSecure());
                        if (cookie != null)
                        {
                            // Handle changed session id or cookie max-age refresh
                            response.addCookie(cookie);
                        }
                    }
                    else
                    {
                        // Handle resume of the request
                        currentSession = currentRequest.recoverNewSession(sessionManager);
                        if (currentSession != null) currentRequest.setSession(currentSession);
                    }
                }
            }
            Log.debug("Session = {}", currentSession);

            getHandler().handle(target, request, response, dispatch);
        }
        catch (RetryRequest x)
        {
            // User may have invalidated the session, must get it again
            HttpSession currentSession = currentRequest.getSession(false);
            if (currentSession != null && currentSession.isNew())
                currentRequest.saveNewSession(sessionManager, currentSession);

            throw x;
        }
        finally
        {
            if (sessionManager != null)
            {
                // User may have invalidated the session, must get it again
                HttpSession currentSession = currentRequest.getSession(false);
                if (currentSession != null) sessionManager.complete(currentSession);

                sessionManager.exit(currentRequest);
            }

            // Restore cross context dispatch
            if (sessionManager != requestSessionManager)
            {
                currentRequest.setSessionManager(requestSessionManager);
                currentRequest.setSession(requestSession);
            }
        }
    }
View Full Code Here

        //TODO
        //do we need to check that this request should be handled by this handler?
        if (! target.startsWith(contextPath)) {
            return;
        }
        Request jettyRequest = (Request) req;
        Response jettyResponse = (Response) res;
        RequestAdapter request = new RequestAdapter(jettyRequest);
        ResponseAdapter response = new ResponseAdapter(jettyResponse);

        request.setAttribute(WebServiceContainer.SERVLET_REQUEST, req);
        request.setAttribute(WebServiceContainer.SERVLET_RESPONSE, res);
        // TODO: add support for context
        request.setAttribute(WebServiceContainer.SERVLET_CONTEXT, null);

        if (req.getParameter("wsdl") != null) {
            try {
                webServiceContainer.getWsdl(request, response);
                jettyRequest.setHandled(true);
            } catch (IOException e) {
                throw e;
            } catch (Exception e) {
                throw (HttpException) new HttpException(500, "Could not fetch wsdl!").initCause(e);
            }
        } else {
            if (isConfidentialTransportGuarantee) {
                if (!req.isSecure()) {
                    throw new HttpException(403, null);
                }
            } else if (isIntegralTransportGuarantee) {
                if (!jettyRequest.getConnection().isIntegral(jettyRequest)) {
                    throw new HttpException(403, null);
                }
            }
            Thread currentThread = Thread.currentThread();
            ClassLoader oldClassLoader = currentThread.getContextClassLoader();
            currentThread.setContextClassLoader(classLoader);
            //hard to imagine this could be anything but null, but....
//            Subject oldSubject = ContextManager.getCurrentCaller();
            try {
                if (authenticator != null) {
                    String pathInContext = org.mortbay.util.URIUtil.canonicalPath(req.getContextPath());
                    if (authenticator.authenticate(realm, pathInContext, jettyRequest, jettyResponse) == null) {
                        throw new HttpException(403, null);
                    }
                } else {
                    //EJB will figure out correct defaultSubject shortly
                    //TODO consider replacing the GenericEJBContainer.DefaultSubjectInterceptor with this line
                    //setting the defaultSubject.
                    ContextManager.popCallers(null);
                }
                try {
                    webServiceContainer.invoke(request, response);
                    jettyRequest.setHandled(true);
                } catch (IOException e) {
                    throw e;
                } catch (Exception e) {
                    throw (HttpException) new HttpException(500, "Could not process message!").initCause(e);
                }
View Full Code Here

    /*
     * @see javax.servlet.RequestDispatcher#include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
     */
    public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException
    {
        Request base_request=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
        request.removeAttribute(__JSP_FILE); // TODO remove when glassfish 1044 is fixed
       
        // TODO - allow stream or writer????
       
        Attributes old_attr=base_request.getAttributes();
        MultiMap old_params=base_request.getParameters();
        try
        {
            base_request.getConnection().include();
            if (_named!=null)
                _contextHandler.handle(_named, (HttpServletRequest)request, (HttpServletResponse)response, Handler.INCLUDE);
            else
            {
                String query=_dQuery;
               
                if (query!=null)
                {
                    MultiMap parameters=new MultiMap();
                    UrlEncoded.decodeTo(query,parameters,request.getCharacterEncoding());
                   
                    if (old_params!=null && old_params.size()>0)
                    {
                        // Merge parameters.
                        Iterator iter = old_params.entrySet().iterator();
                        while (iter.hasNext())
                        {
                            Map.Entry entry = (Map.Entry)iter.next();
                            String name=(String)entry.getKey();
                            Object values=entry.getValue();
                            for (int i=0;i<LazyList.size(values);i++)
                                parameters.add(name, LazyList.get(values, i));
                        }
                       
                    }
                    base_request.setParameters(parameters);
                }
               
                IncludeAttributes attr = new IncludeAttributes(old_attr);
               
                attr._requestURI=_uri;
                attr._contextPath=_contextHandler.getContextPath();
                attr._servletPath=null; // set by ServletHandler
                attr._pathInfo=_path;
                attr._query=query;
               
                base_request.setAttributes(attr);
               
                _contextHandler.handle(_named==null?_path:_named, (HttpServletRequest)request, (HttpServletResponse)response, Handler.INCLUDE);
            }
        }
        finally
        {
            base_request.setAttributes(old_attr);
            base_request.getConnection().included();
            base_request.setParameters(old_params);
        }
    }
View Full Code Here

    /*
     * @see javax.servlet.RequestDispatcher#forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
     */
    protected void forward(ServletRequest request, ServletResponse response, int dispatch) throws ServletException, IOException
    {
        Request base_request=(request instanceof Request)?((Request)request):HttpConnection.getCurrentConnection().getRequest();
        response.resetBuffer();
        request.removeAttribute(__JSP_FILE); // TODO remove when glassfish 1044 is fixed
       
        String old_uri=base_request.getRequestURI();
        String old_context_path=base_request.getContextPath();
        String old_servlet_path=base_request.getServletPath();
        String old_path_info=base_request.getPathInfo();
        String old_query=base_request.getQueryString();
        Attributes old_attr=base_request.getAttributes();
        MultiMap old_params=base_request.getParameters();
        try
        {
            if (_named!=null)
                _contextHandler.handle(_named, (HttpServletRequest)request, (HttpServletResponse)response, dispatch);
            else
            {
                String query=_dQuery;
               
                if (query!=null)
                {
                    MultiMap parameters=new MultiMap();
                    UrlEncoded.decodeTo(query,parameters,request.getCharacterEncoding());
                   
                    if (old_params!=null && old_params.size()>0)
                    {
                        // Merge parameters.
                        Iterator iter = old_params.entrySet().iterator();
                        while (iter.hasNext())
                        {
                            Map.Entry entry = (Map.Entry)iter.next();
                            String name=(String)entry.getKey();
                            Object values=entry.getValue();
                            for (int i=0;i<LazyList.size(values);i++)
                                parameters.add(name, LazyList.get(values, i));
                        }
                    }
                   
                    if (old_query!=null && old_query.length()>0)
                        query=query+"&"+old_query;
                   
                    base_request.setParameters(parameters);
                    base_request.setQueryString(query);
                }
               
                ForwardAttributes attr = new ForwardAttributes(old_attr);
               
                //If we have already been forwarded previously, then keep using the established
                //original value. Otherwise, this is the first forward and we need to establish the values.
                //Note: the established value on the original request for pathInfo and
                //for queryString is allowed to be null, but cannot be null for the other values.
                if ((String)old_attr.getAttribute(__FORWARD_REQUEST_URI) != null)
                {
                    attr._pathInfo=(String)old_attr.getAttribute(__FORWARD_PATH_INFO);
                    attr._query=(String)old_attr.getAttribute(__FORWARD_QUERY_STRING);
                    attr._requestURI=(String)old_attr.getAttribute(__FORWARD_REQUEST_URI);
                    attr._contextPath=(String)old_attr.getAttribute(__FORWARD_CONTEXT_PATH);
                    attr._servletPath=(String)old_attr.getAttribute(__FORWARD_SERVLET_PATH);
                }
                else
                {
                    attr._pathInfo=old_path_info;
                    attr._query=old_query;
                    attr._requestURI=old_uri;
                    attr._contextPath=old_context_path;
                    attr._servletPath=old_servlet_path;
                }               
  
             
               
                base_request.setRequestURI(_uri);
                base_request.setContextPath(_contextHandler.getContextPath());
                base_request.setAttributes(attr);
                base_request.setQueryString(query);
               
                _contextHandler.handle(_path, (HttpServletRequest)request, (HttpServletResponse)response, dispatch);
               
                if (base_request.getConnection().getResponse().isWriting())
                {
                    try {response.getWriter().close();}
                    catch(IllegalStateException e) { response.getOutputStream().close(); }
                }
                else
                {
                    try {response.getOutputStream().close();}
                    catch(IllegalStateException e) { response.getWriter().close(); }
                }
            }
        }
        finally
        {
            base_request.setRequestURI(old_uri);
            base_request.setContextPath(old_context_path);
            base_request.setServletPath(old_servlet_path);
            base_request.setPathInfo(old_path_info);
            base_request.setAttributes(old_attr);
            base_request.setParameters(old_params);
            base_request.setQueryString(old_query);
        }
    }
View Full Code Here

    {
        Handler[] handlers = getHandlers();
        if (handlers==null || handlers.length==0)
      return;

  Request base_request = HttpConnection.getCurrentConnection().getRequest();
  PathMap map = _contextMap;
  if (map!=null && target!=null && target.startsWith("/"))
  {
      Object contexts = map.getLazyMatches(target);

            for (int i=0; i<LazyList.size(contexts); i++)
            {
                Map.Entry entry = (Map.Entry)LazyList.get(contexts, i);
                Object list = entry.getValue();

                if (list instanceof Map)
                {
                    Map hosts = (Map)list;
                    list=hosts.get(request.getServerName());
                    for (int j=0; j<LazyList.size(list); j++)
                    {
                        Handler handler = (Handler)LazyList.get(list,j);
                        handler.handle(target,request, response, dispatch);
                        if (base_request.isHandled())
                            return;
                    }
                    list=hosts.get("*");
                    for (int j=0; j<LazyList.size(list); j++)
                    {
                        Handler handler = (Handler)LazyList.get(list,j);
                        handler.handle(target,request, response, dispatch);
                        if (base_request.isHandled())
                            return;
                    }
                }
                else
                {
                    for (int j=0; j<LazyList.size(list); j++)
                    {
                        Handler handler = (Handler)LazyList.get(list,j);
                        handler.handle(target,request, response, dispatch);
                        if (base_request.isHandled())
                            return;
                    }
                }
      }
  }
  else
  {
            // This may not work in all circumstances... but then I think it should never be called
      for (int i=0;i<handlers.length;i++)
      {
    handlers[i].handle(target,request, response, dispatch);
    if ( base_request.isHandled())
        return;
      }
  }
    }
View Full Code Here

    /*
     * @see org.mortbay.jetty.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
     */
    public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException
    {
        Request base_request = request instanceof Request?(Request)request:HttpConnection.getCurrentConnection().getRequest();
        if (base_request.isHandled() || !request.getMethod().equals(HttpMethods.GET))
            return;
    
        Resource resource=getResource(request);
       
        if (resource==null || !resource.exists())
            return;

        // We are going to server something
        base_request.setHandled(true);
       
        if (resource.isDirectory())
        {
            if (!request.getPathInfo().endsWith(URIUtil.SLASH))
            {
View Full Code Here

TOP

Related Classes of org.mortbay.jetty.Request

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.