Package javax.portlet

Examples of javax.portlet.ResourceResponse


          throw new BridgeException("Unable to serve resource");
        }

      } else {
        // FACES REQUEST.
        ResourceResponse wrappedResponse = strategy
                .createResponseWrapper(response);
        RequestScopeManager requestStateManager = RequestScopeManager
                .getInstance(request, numberOfRequestScopes);
        FacesContext facesContext = createFacesContext(request,
                wrappedResponse);
        StateId stateId = requestStateManager.getStateId(request,
                wrappedResponse);
        bridgeContext.setStateId(stateId);
        BridgeRequestScope windowState = requestStateManager
                .getRequestScope(stateId);
        if (null == windowState) {
          windowState = new BridgeRequestScope();
          requestStateManager.saveRequestScope(stateId, windowState);
        } else {
          windowState.reset();
        }
        bridgeContext.setRequestScope(windowState);
        try {
          strategy.beforeResourceRequest(facesContext);
          processIncomingParameters(facesContext, request);
          execute(facesContext);
          // TODO - create applicable processing function.
//          processOutgoingParameters(facesContext,request,response);
          strategy.afterResourceRequestExecute(facesContext);
          windowState.saveRequest(facesContext, false);
          if (!facesContext.getResponseComplete()) {
            render(facesContext);
          }
        } catch (Exception e) {
          wrappedResponse.resetBuffer();
          log.log(Level.SEVERE, "Error processing execute lifecycle", e);
          exceptionHandler.processResourceException(facesContext,
              windowState, e);
          facesContext = FacesContext.getCurrentInstance();
        } finally {
View Full Code Here


        PortletInvokerService invoker = getContainerServices().getPortletInvokerService();

        PortletResourceRequestContext requestContext = rcService.getPortletResourceRequestContext(this, request, response, portletWindow);
        PortletResourceResponseContext responseContext = rcService.getPortletResourceResponseContext(this, request, response, portletWindow);
        ResourceRequest portletRequest = envService.createResourceRequest(requestContext, responseContext);
        ResourceResponse portletResponse = envService.createResourceResponse(responseContext, requestContext.getCacheability());

        FilterManager filterManager = filterInitialisation(portletWindow,PortletRequest.RESOURCE_PHASE);

        try
        {
View Full Code Here

            // The requested method is RESOURCE: call
            // ResourceServingPortlet.serveResource(..)
            else if (methodId == PortletInvokerService.METHOD_RESOURCE)
            {
                ResourceRequest resourceRequest = (ResourceRequest) portletRequest;
                ResourceResponse resourceResponse = (ResourceResponse) portletResponse;
                filterManager.processFilter(resourceRequest, resourceResponse,
                        resourceServingPortlet, portletContext);
            }

            // The requested method is ACTION: call Portlet.processAction(..)
View Full Code Here

            safeName = safeName.substring(1);
        }

        String filename = new StringBuilder(type).append("_").append(safeName).append("_").append(getTimestamp()).append(".zip").toString();

        ResourceResponse response = (ResourceResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();

        response.reset();
        response.setContentType("application/zip");
        response.setProperty("Content-disposition", "attachment; filename=\"" + filename + "\"");

        ManagementController controller = (ManagementController) PortalContainer.getComponent(ManagementController.class);
        PathAddress address = PathAddress.pathAddress("mop", type + "sites", name);

        ManagedRequest request = ManagedRequest.Factory.create(OperationNames.EXPORT_RESOURCE, address, ContentType.ZIP);
View Full Code Here

         TemplateModel model = createModel();
         // Give subclasses a chance to hook into preprocessing
         if (preTemplateProcess(template, model)) {
             try {
                 // Process the template
                 ResourceResponse response = PortletActionContext.getResourceResponse();
                 response.setContentType(pContentType);
                 template.process(model, response.getWriter());
             } finally {
                 // Give subclasses a chance to hook into postprocessing
                 postTemplateProcess(template, model);
             }
         }
View Full Code Here

      ActionRequest areq = getActionRequest();
      ActionResponse aresp = getActionResponse();
      EventRequest ereq = getEventRequest();
      EventResponse eresp = getEventResponse();
      ResourceRequest rsreq = getResourceRequest();
      ResourceResponse rsresp = getResourceResponse();
      PortletConfig portletConfig = getConfig();
      PortletSession portletSession = getSession();
      Map<String, Object> portletSessionScope = getPortletSessionScope();
      PortletPreferences portletPreferences = getPortletPreferences();
      Map<String, String[]> portletPreferencesValues = getPortletPreferenceValues();
View Full Code Here

      cookies = null;
    }

    if (isMimeResponse) {
      MimeResponse mimeResponse = (MimeResponse) response;
      ResourceResponse resourceResponse = isResourceResponse ? (ResourceResponse) response : null;

      if (locale != null) {
        try {
          resourceResponse.setLocale(locale);
        }
        catch (UnsupportedOperationException usoe) {
          // TODO: temporary "fix" for JBoss Portal which doesn't
          // yet
          // support this
          // (although required by the Portlet API 2.0!)
        }
      }

      if (contentType != null) {
        if (characterEncoding != null) {
          if (setContentTypeAfterEncoding) {
            resourceResponse.setCharacterEncoding(characterEncoding);
            resourceResponse.setContentType(contentType);
          }
          else {
            resourceResponse.setContentType(contentType);
            resourceResponse.setCharacterEncoding(characterEncoding);
          }
        }
        else {
          mimeResponse.setContentType(contentType);
        }
      }
      else if (characterEncoding != null) {
        resourceResponse.setCharacterEncoding(characterEncoding);
      }

      if (headers != null) {
        for (Map.Entry<String, ArrayList<String>> entry : headers.entrySet()) {
          for (String value : entry.getValue()) {
            mimeResponse.addProperty(entry.getKey(), value);
          }
        }
        headers = null;
      }

      if (isResourceResponse && hasStatus) {
        resourceResponse.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(statusCode));
      }

      if (isResourceResponse && contentLength > -1) {
        try {
          resourceResponse.setContentLength(contentLength);
        }
        catch (UnsupportedOperationException usoe) {
          // TODO: temporary "fix" for JBoss Portal which doesn't
          // yet
          // support this
View Full Code Here

      {
         protected Response run(Servlet servlet, HttpServletRequest request, HttpServletResponse response, PortletTestContext context) throws ServletException, IOException
         {
            //we get this object to assert some of it's method compare wieth http request methods
            ResourceRequest portletRequest = (ResourceRequest)request.getAttribute("javax.portlet.request");
            ResourceResponse portletResponse = (ResourceResponse)request.getAttribute("javax.portlet.response");

            assertNotNull(portletRequest);
            assertNotNull(portletResponse);

            //SPEC:231
            //Those should do nothing - some of the getters will be checked later
            response.setCharacterEncoding("lolo");
            response.setContentType("lolo");
            response.setContentLength(22);
            response.setLocale(Locale.TRADITIONAL_CHINESE);
            response.addCookie(new Cookie("lolo", "bobo"));
            response.sendError(404,"bobo");
            response.sendRedirect("http://www.jboss.org");
            response.setDateHeader("bobo",11);
            response.addDateHeader("bobo",21);
            response.setHeader("bobo", "toto");
            response.addHeader("bobo", "bubu");
            response.setIntHeader("toto",13);
            response.addIntHeader("lala",25);
            response.setStatus(505);

            //SPEC:220
            assertNull(request.getRemoteAddr());
            assertNull(request.getRemoteHost());
            assertNull(request.getRealPath("toto"));
            assertNull(request.getLocalAddr());
            assertNull(request.getLocalName());
            assertNull(request.getRequestURL());

            //SPEC:221
            assertEquals(0, request.getRemotePort());
            assertEquals(0, request.getLocalPort());

            //SPEC:222
            assertEquals(null, request.getPathInfo());
            //TODO:NYI
            //assertEquals("",request.getPathTranslated());
            assertEquals("key1=k1value1&key2=k2value1", request.getQueryString());
            assertEquals(seq.getContext().getContextPath() + "/universalServletA",request.getRequestURI());
            assertEquals("/universalServletA", request.getServletPath());


            //SPEC:223
            assertEquals(portletRequest.getScheme(), request.getScheme());
            assertEquals(portletRequest.getServerName(), request.getServerName());
            assertEquals(portletRequest.getServerPort(), request.getServerPort());

            // getAttributeNames, setAttribute, getAttribute, removeAttribute
            request.setAttribute("key1", "k1atrr1");
            request.setAttribute("key2", "k2attr2");
            List attrNames = new LinkedList();
            Enumeration attrEnum = request.getAttributeNames();
            while (attrEnum.hasMoreElements())
            {
               attrNames.add(attrEnum.nextElement());
            }
            assertNotNull(request.getAttribute("key1"));
            assertNotNull(request.getAttribute("key2"));

            assertTrue(attrNames.contains("key1"));
            assertTrue(attrNames.contains("key2"));

            request.removeAttribute("key1");
            assertNull(request.getAttribute("key1"));
            assertNotNull(request.getAttribute("key2"));

            //getLocale, getLocales
            assertEquals(portletRequest.getLocale(), request.getLocale());

            List portletLocales = new LinkedList();
            List servletLocales = new LinkedList();
            Enumeration pl = portletRequest.getLocales();
            while (pl.hasMoreElements())
            {
               portletLocales.add(pl.nextElement());
            }
            Enumeration sl = request.getLocales();
            while (sl.hasMoreElements())
            {
               servletLocales.add(sl.nextElement());
            }

            assertTrue(portletLocales.equals(servletLocales));

            assertEquals(portletRequest.isSecure(), request.isSecure());
            assertEquals(portletRequest.getAuthType(), request.getAuthType());
            assertEquals(portletRequest.getContextPath(), request.getContextPath());
            assertEquals(portletRequest.getRemoteUser(), request.getRemoteUser());
            assertEquals(portletRequest.getUserPrincipal(), request.getUserPrincipal());
            assertEquals(portletRequest.getRequestedSessionId(), request.getRequestedSessionId());
            assertEquals(portletRequest.isRequestedSessionIdValid(), request.isRequestedSessionIdValid());
            assertEquals(portletRequest.getCookies(), request.getCookies());

            //SPEC:224
            try
            {
               // request was already read
               request.setCharacterEncoding("utf8");
               assertTrue(false);
            }
            catch (IllegalStateException e)
            {
               //expected
            }
            assertEquals(portletRequest.getCharacterEncoding(), request.getCharacterEncoding());
            //
            assertEquals(portletRequest.getContentType(), request.getContentType());
            assertEquals(portletRequest.getMethod(), request.getMethod());
            assertEquals(portletRequest.getContentLength(), request.getContentLength());
            assertEquals(portletRequest.getReader(), request.getReader());


            //SPEC:225
            //in this assertions we use parameters passed in query string of dispatcher
            List paramNames = new LinkedList();
            Enumeration paramEnum = request.getParameterNames();
            while (paramEnum.hasMoreElements())
            {
               paramNames.add(paramEnum.nextElement());
            }
            assertTrue(paramNames.contains("key1"));
            assertTrue(paramNames.contains("key2"));

            assertEquals("k1value1", request.getParameter("key1"));
            assertEquals(new String[]{"k1value1"}, request.getParameterValues("key1"));

            Map paramNamesMap = request.getParameterMap();
            assertTrue(paramNamesMap.containsKey("key1"));
            assertTrue(paramNamesMap.containsKey("key2"));

            //SPEC:226
            assertEquals(portletRequest.getProperty("myheader"), request.getHeader("myheader"));
            List rheaders = Collections.list(request.getHeaders("myheader"));
            List pheaders = Collections.list(portletRequest.getProperties("myheader"));

            for (Iterator iterator = pheaders.iterator(); iterator.hasNext();)
            {
               Object o = iterator.next();
               assertTrue(rheaders.contains(o));
            }

            List headerNames = Collections.list(request.getHeaderNames());
            Enumeration propertyNamesE = portletRequest.getPropertyNames();
            while (propertyNamesE.hasMoreElements())
            {
               Object o = propertyNamesE.nextElement();
               assertTrue(headerNames.contains(o));
            }
            assertTrue(headerNames.contains("myheader"));

            //TODO: seems to not be implemented
            //assertEquals("?", request.getDateHeader("myheader"));
            //assertEquals("?", request.getIntHeader("myheader"));

            //SPEC:227
            //TODO:
            //TODO: The following methods of the HttpServletRequest must provide the
            //TODO: functionality defined by the Servlet Specification: getRequestDispatcher, isUserInRole, getSession,
            //TODO: isRequestedSessionIdFromCookie, isRequestedSessionIdFromURL and isRequestedSessionIdFromUrl.

            //SPEC:228
            assertEquals("HTTP/1.1", request.getProtocol());

            //SPEC:229
            assertNull(response.encodeRedirectURL("lolo"));
            assertNull(response.encodeRedirectUrl("blah"));


            //SPEC:230
            assertEquals(portletResponse.getCharacterEncoding(), response.getCharacterEncoding());
            //TODO: setBufferSize, flushBuffer, resetBuffer, reset
            assertEquals(portletResponse.getBufferSize(), response.getBufferSize());
            assertEquals(portletResponse.isCommitted(), response.isCommitted());
            //TODO: How to check if its the same behaviour as in PR? Its not the same object.
            assertNotNull(response.getOutputStream());
            //Cannot invoke both writer and outputstream in single request
            //assertEquals(portletResponse.getWriter(), response.getWriter());
            assertEquals(portletResponse.getLocale(), response.getLocale());
            assertEquals(portletResponse.encodeURL("http://www.jboss.com/"), response.encodeURL("http://www.jboss.com/"));
            assertEquals(portletResponse.encodeURL("http://www.jboss.com/"), response.encodeUrl("http://www.jboss.com/"));



            //SPEC:232
            assertEquals(false, response.containsHeader("blah"));
View Full Code Here

      {
         protected Response run(Servlet servlet, HttpServletRequest request, HttpServletResponse response, PortletTestContext context) throws ServletException, IOException
         {
            //we get this object to assert some of it's method compare wieth http request methods
            ResourceRequest portletRequest = (ResourceRequest)request.getAttribute("javax.portlet.request");
            ResourceResponse portletResponse = (ResourceResponse)request.getAttribute("javax.portlet.response");

            assertNotNull(portletRequest);
            assertNotNull(portletResponse);

            //Part of SPEC:288 - must be set at the beggining
            response.setContentType("text/html");

            //SPEC:278
            assertNull(request.getRemoteAddr());
            assertNull(request.getRemoteHost());
            assertNull(request.getRealPath("toto"));
            assertNull(request.getLocalAddr());
            assertNull(request.getLocalName());
            assertNull(request.getRequestURL());

            //SPEC:279
            assertEquals(0, request.getRemotePort());
            assertEquals(0, request.getLocalPort());

            //SPEC:280
            assertEquals(null, request.getPathInfo());
            //TODO:NYI
            //assertEquals("",request.getPathTranslated());
            assertEquals("key1=k1value1&key2=k2value1", request.getQueryString());
            assertEquals(seq.getContext().getContextPath() + "/universalServletA",request.getRequestURI());
            assertEquals("/universalServletA", request.getServletPath());


            //SPEC:281
            assertEquals(portletRequest.getScheme(), request.getScheme());
            assertEquals(portletRequest.getServerName(), request.getServerName());
            assertEquals(portletRequest.getServerPort(), request.getServerPort());

            // getAttributeNames, setAttribute, getAttribute, removeAttribute
            request.setAttribute("key1", "k1atrr1");
            request.setAttribute("key2", "k2attr2");
            List attrNames = new LinkedList();
            Enumeration attrEnum = request.getAttributeNames();
            while (attrEnum.hasMoreElements())
            {
               attrNames.add(attrEnum.nextElement());
            }
            assertNotNull(request.getAttribute("key1"));
            assertNotNull(request.getAttribute("key2"));

            assertTrue(attrNames.contains("key1"));
            assertTrue(attrNames.contains("key2"));

            request.removeAttribute("key1");
            assertNull(request.getAttribute("key1"));
            assertNotNull(request.getAttribute("key2"));

            //getLocale, getLocales
            assertEquals(portletRequest.getLocale(), request.getLocale());

            List portletLocales = new LinkedList();
            List servletLocales = new LinkedList();
            Enumeration pl = portletRequest.getLocales();
            while (pl.hasMoreElements())
            {
               portletLocales.add(pl.nextElement());
            }
            Enumeration sl = request.getLocales();
            while (sl.hasMoreElements())
            {
               servletLocales.add(sl.nextElement());
            }

            assertTrue(portletLocales.equals(servletLocales));

            assertEquals(portletRequest.isSecure(), request.isSecure());
            assertEquals(portletRequest.getAuthType(), request.getAuthType());
            assertEquals(portletRequest.getContextPath(), request.getContextPath());
            assertEquals(portletRequest.getRemoteUser(), request.getRemoteUser());
            assertEquals(portletRequest.getUserPrincipal(), request.getUserPrincipal());
            assertEquals(portletRequest.getRequestedSessionId(), request.getRequestedSessionId());
            assertEquals(portletRequest.isRequestedSessionIdValid(), request.isRequestedSessionIdValid());
            assertEquals(portletRequest.getCookies(), request.getCookies());

            //SPEC:282
            try
            {
               // request was already read
               request.setCharacterEncoding("utf8");
               assertTrue(false);
            }
            catch (IllegalStateException e)
            {
               //expected
            }
            assertEquals(portletRequest.getCharacterEncoding(), request.getCharacterEncoding());
            //
            assertEquals(portletRequest.getContentType(), request.getContentType());
            assertEquals(portletRequest.getMethod(), request.getMethod());
            assertEquals(portletRequest.getReader(), request.getReader());


            //SPEC:283
            //in this assertions we use parameters passed in query string of dispatcher
            List paramNames = new LinkedList();
            Enumeration paramEnum = request.getParameterNames();
            while (paramEnum.hasMoreElements())
            {
               paramNames.add(paramEnum.nextElement());
            }
            assertTrue(paramNames.contains("key1"));
            assertTrue(paramNames.contains("key2"));

            assertEquals("k1value1", request.getParameter("key1"));
            assertEquals(new String[]{"k1value1"}, request.getParameterValues("key1"));

            Map paramNamesMap = request.getParameterMap();
            assertTrue(paramNamesMap.containsKey("key1"));
            assertTrue(paramNamesMap.containsKey("key2"));

            //SPEC:284
            assertEquals(portletRequest.getProperty("myheader"), request.getHeader("myheader"));
            List rheaders = Collections.list(request.getHeaders("myheader"));
            List pheaders = Collections.list(portletRequest.getProperties("myheader"));

            for (Iterator iterator = pheaders.iterator(); iterator.hasNext();)
            {
               Object o = iterator.next();
               assertTrue(rheaders.contains(o));
            }

            List headerNames = Collections.list(request.getHeaderNames());
            Enumeration propertyNamesE = portletRequest.getPropertyNames();
            while (propertyNamesE.hasMoreElements())
            {
               Object o = propertyNamesE.nextElement();
               assertTrue(headerNames.contains(o));
            }
            assertTrue(headerNames.contains("myheader"));

            //TODO: seems to not be implemented
            //assertEquals("?", request.getDateHeader("myheader"));
            //assertEquals("?", request.getIntHeader("myheader"));

            //SPEC:285
            //TODO:
            //TODO: The following methods of the HttpServletRequest must provide the
            //TODO: functionality defined by the Servlet Specification: getRequestDispatcher, isUserInRole, getSession,
            //TODO: isRequestedSessionIdFromCookie, isRequestedSessionIdFromURL and isRequestedSessionIdFromUrl.

            //SPEC:286
            assertEquals("HTTP/1.1", request.getProtocol());

            //SPEC:287
            assertNull(response.encodeRedirectURL("lolo"));
            assertNull(response.encodeRedirectUrl("blah"));


            //SPEC:288
            assertEquals(portletResponse.getCharacterEncoding(), response.getCharacterEncoding());
            //TODO: setBufferSize, flushBuffer, resetBuffer, reset
            assertEquals(portletResponse.getBufferSize(), response.getBufferSize());
            assertEquals(portletResponse.isCommitted(), response.isCommitted());
            //TODO: How to check if its the same behaviour as in PR? Its not the same object.
            //and btw. if line below is failing this means that HSResponse.setContentType is not impl ok
            assertNotNull(response.getOutputStream());
            //Cannot invoke both writer and outputstream in single request
            //assertEquals(portletResponse.getWriter(), response.getWriter());
            assertEquals(portletResponse.getLocale(), response.getLocale());
            assertEquals(portletResponse.encodeURL("http://www.jboss.com/"), response.encodeURL("http://www.jboss.com/"));
            assertEquals(portletResponse.encodeURL("http://www.jboss.com/"), response.encodeUrl("http://www.jboss.com/"));

            return new EndTestResponse();
         }
      });
View Full Code Here

  public void setResponseCharacterEncoding(String encoding) {

    if (encoding != null) {

      if (portletResponse instanceof ResourceResponse) {
        ResourceResponse resourceResponse = (ResourceResponse) portletResponse;
        resourceResponse.setCharacterEncoding(encoding);
      }
      else {

        if (manageIncongruities) {
          incongruityContext.setResponseCharacterEncoding(encoding);
View Full Code Here

TOP

Related Classes of javax.portlet.ResourceResponse

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.