javax.portlet.PortletResponse Java Examples

The following examples show how to use javax.portlet.PortletResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DispatcherRenderParameterTest.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
protected TestResult checkInvalidParameters(PortletContext context,
                                            PortletRequest request,
                                            PortletResponse response)
throws IOException, PortletException {

	// Dispatch to the companion servlet: call checkInvalidParameters().
	StringBuffer buffer = new StringBuffer();
	buffer.append(SERVLET_PATH).append("?")
			.append(KEY_TARGET).append("=").append(TARGET_INVALID_PARAMS)
			.append("&").append(KEY_A)
			.append("&").append(KEY_B).append("=").append(VALUE_B)
			.append("&").append(KEY_C).append("=");
	if (LOG.isDebugEnabled()) {
		LOG.debug("Dispatching to: " + buffer.toString());
	}
	PortletRequestDispatcher dispatcher = context.getRequestDispatcher(
			buffer.toString());
	dispatcher.include((RenderRequest) request, (RenderResponse) response);

	// Retrieve test result returned by the companion servlet.
    TestResult result = (TestResult) request.getAttribute(RESULT_KEY);
	request.removeAttribute(RESULT_KEY);
	return result;
}
 
Example #2
Source File: Utils.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
private boolean checkEqualProperties(PortletResponse injectedPortletArtifact,
      PortletResponse portletResponse) {
   Collection<String> injectedProperties = injectedPortletArtifact
         .getPropertyNames();
   Collection<String> portletResponseProperties = portletResponse
         .getPropertyNames();
   Collection<String> injectedPropertyNames;
   Collection<String> portletPropertyNames;
   if (checkEqualCollection(injectedProperties, portletResponseProperties)) {
      for (String propertyName : injectedProperties) {
         injectedPropertyNames = injectedPortletArtifact
               .getPropertyValues(propertyName);
         portletPropertyNames = injectedPortletArtifact
               .getPropertyValues(propertyName);
         if (!checkEqualCollection(injectedPropertyNames,
               portletPropertyNames)) {
            return false;
         }
      }
      return true;
   } else {
      return false;
   }
}
 
Example #3
Source File: DispatcherTests3S_SPEC2_19_ForwardServletResource_servlet.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
protected void processTCKReq(HttpServletRequest request, HttpServletResponse response) throws ServletException,
      IOException {

   PortletRequest portletReq = (PortletRequest) request.getAttribute("javax.portlet.request");
   PortletResponse portletResp = (PortletResponse) request.getAttribute("javax.portlet.response");
   request.getAttribute("javax.portlet.config");
   Thread.currentThread().getId();
   portletReq.getAttribute(THREADID_ATTR);

   PrintWriter writer = ((MimeResponse) portletResp).getWriter();

   // Create result objects for the tests

   PortletURL purl = ((MimeResponse) portletResp).createRenderURL();
   TestLink tl = new TestLink(V2DISPATCHERTESTS3S_SPEC2_19_FORWARDSERVLETRESOURCE_DISPATCH4, purl);
   tl.writeTo(writer);

}
 
Example #4
Source File: NamespaceTag.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
public int doStartTag() throws JspException {
	
	PortletResponse portletResponse = (PortletResponse) pageContext.getRequest()
        .getAttribute(Constants.PORTLET_RESPONSE);
	
    String namespace = portletResponse.getNamespace();
    
    JspWriter writer = pageContext.getOut();
    
    try {
        writer.print(namespace);
    } catch (IOException ioe) {
        throw new JspException(
            "Unable to write namespace", ioe
        );
    }
    
    return SKIP_BODY;
}
 
Example #5
Source File: DispatcherRenderParameterTest.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
protected TestResult checkParameters(PortletContext context,
                                     PortletRequest request,
                                     PortletResponse response)
throws IOException, PortletException {

	// Dispatch to the companion servlet: call checkParameters().
	StringBuffer buffer = new StringBuffer();
	buffer.append(SERVLET_PATH).append("?")
			.append(KEY_TARGET).append("=").append(TARGET_PARAMS)
			.append("&").append(KEY_A).append("=").append(VALUE_A)
			.append("&").append(KEY_B).append("=").append(VALUE_B);

	if (LOG.isDebugEnabled()) {
		LOG.debug("Dispatching to: " + buffer.toString());
	}
    PortletRequestDispatcher dispatcher = context.getRequestDispatcher(
    		buffer.toString());
    dispatcher.include((RenderRequest) request, (RenderResponse) response);

	// Retrieve test result returned by the companion servlet.
    TestResult result = (TestResult) request.getAttribute(RESULT_KEY);
	request.removeAttribute(RESULT_KEY);
    return result;
}
 
Example #6
Source File: ViewEngineJspImpl.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
@Override
public void processView(ViewEngineContext viewEngineContext) throws ViewEngineException {

	String view = viewEngineContext.getView();

	String viewFolder = (String) configuration.getProperty(ViewEngine.VIEW_FOLDER);

	if (viewFolder == null) {
		viewFolder = ViewEngine.DEFAULT_VIEW_FOLDER;
	}

	String viewPath = viewFolder.concat(view);

	PortletRequestDispatcher requestDispatcher = portletContext.getRequestDispatcher(viewPath);

	try {
		requestDispatcher.include(viewEngineContext.getRequest(PortletRequest.class),
			viewEngineContext.getResponse(PortletResponse.class));
	}
	catch (Exception e) {
		throw new ViewEngineException(e);
	}
}
 
Example #7
Source File: PortletWebRequestTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecoratedNativeRequest() {
	MockRenderRequest portletRequest = new MockRenderRequest();
	MockRenderResponse portletResponse = new MockRenderResponse();
	PortletRequest decoratedRequest = new PortletRequestWrapper(portletRequest);
	PortletResponse decoratedResponse = new PortletResponseWrapper(portletResponse);
	PortletWebRequest request = new PortletWebRequest(decoratedRequest, decoratedResponse);
	assertSame(decoratedRequest, request.getNativeRequest());
	assertSame(decoratedRequest, request.getNativeRequest(PortletRequest.class));
	assertSame(portletRequest, request.getNativeRequest(RenderRequest.class));
	assertSame(portletRequest, request.getNativeRequest(MockRenderRequest.class));
	assertNull(request.getNativeRequest(MultipartRequest.class));
	assertSame(decoratedResponse, request.getNativeResponse());
	assertSame(decoratedResponse, request.getNativeResponse(PortletResponse.class));
	assertSame(portletResponse, request.getNativeResponse(RenderResponse.class));
	assertSame(portletResponse, request.getNativeResponse(MockRenderResponse.class));
	assertNull(request.getNativeResponse(MultipartRequest.class));
}
 
Example #8
Source File: PortletWebRequestTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testNativeRequest() {
	MockRenderRequest portletRequest = new MockRenderRequest();
	MockRenderResponse portletResponse = new MockRenderResponse();
	PortletWebRequest request = new PortletWebRequest(portletRequest, portletResponse);
	assertSame(portletRequest, request.getNativeRequest());
	assertSame(portletRequest, request.getNativeRequest(PortletRequest.class));
	assertSame(portletRequest, request.getNativeRequest(RenderRequest.class));
	assertSame(portletRequest, request.getNativeRequest(MockRenderRequest.class));
	assertNull(request.getNativeRequest(MultipartRequest.class));
	assertSame(portletResponse, request.getNativeResponse());
	assertSame(portletResponse, request.getNativeResponse(PortletResponse.class));
	assertSame(portletResponse, request.getNativeResponse(RenderResponse.class));
	assertSame(portletResponse, request.getNativeResponse(MockRenderResponse.class));
	assertNull(request.getNativeResponse(MultipartRequest.class));
}
 
Example #9
Source File: ServiceProcessIndexer.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest,
		PortletResponse portletResponse) throws Exception {
	Summary summary = createSummary(document);

	summary.setMaxContentLength(QueryUtil.ALL_POS);

	return summary;
}
 
Example #10
Source File: PortletServlet3.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
/**
 * must be called after all method invocations have taken place, even if an
 * exception occurs.
 */
private void afterInvoke(PortletRequest portletRequest, PortletResponse portletResponse) {

   if (acb != null) {

      // Remove the portlet session bean holder for the thread
      PortletRequestScopedBeanHolder.removeBeanHolder();

      // Remove the portlet session bean holder for the thread
      PortletSessionBeanHolder.removeBeanHolder();

      // Remove the redirect bean holder for the thread
      RedirectScopedBeanHolder.removeBeanHolder(
          (portletRequest instanceof RenderRequest) && !(portletRequest instanceof HeaderRequest));

      // Remove the render state bean holder. pass response if we're
      // dealing with a StateAwareResponse. The response is used for state
      // storage.

      StateAwareResponse sar = null;
      if (portletResponse instanceof StateAwareResponse) {
         sar = (StateAwareResponse) portletResponse;
      }
      PortletStateScopedBeanHolder.removeBeanHolder(sar);

      // remove the portlet artifact producer
      PortletArtifactProducer.remove();
      
      if (LOG.isTraceEnabled()) {
         LOG.trace("CDI context is now deactivated.");
      }
   
   }
}
 
Example #11
Source File: ApplicantIndexer.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest,
		PortletResponse portletResponse) throws Exception {
	Summary summary = createSummary(document);

	summary.setMaxContentLength(QueryUtil.ALL_POS);

	return summary;
}
 
Example #12
Source File: PortletParamProducer.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Dependent
@PortletParam
@Produces
public Integer getIntegerParam(ClientDataRequest clientDataRequest, PortletResponse portletResponse,
	InjectionPoint injectionPoint) {

	String value = getStringParam(clientDataRequest, portletResponse, injectionPoint);

	if (value == null) {
		return null;
	}

	Annotated field = injectionPoint.getAnnotated();

	Annotation[] fieldAnnotations = _getFieldAnnotations(field);

	ParamConverter<Integer> paramConverter = _getParamConverter(Integer.class, field.getBaseType(),
			fieldAnnotations);

	if (paramConverter != null) {

		try {
			return paramConverter.fromString(value);
		}
		catch (IllegalArgumentException iae) {
			_addBindingError(fieldAnnotations, iae.getMessage(), value);

			return null;
		}
	}

	if (LOG.isWarnEnabled()) {
		LOG.warn("Unable to find a ParamConverterProvider for type Integer");
	}

	return null;
}
 
Example #13
Source File: DispatcherPortlet.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * No handler found -> throw appropriate exception.
 * @param request current portlet request
 * @param response current portlet response
 * @throws Exception if preparing the response failed
 */
protected void noHandlerFound(PortletRequest request, PortletResponse response) throws Exception {
	if (pageNotFoundLogger.isWarnEnabled()) {
		pageNotFoundLogger.warn("No handler found for current request " +
				"in DispatcherPortlet with name '" + getPortletName() +
				"', mode '" + request.getPortletMode() +
				"', phase '" + request.getAttribute(PortletRequest.LIFECYCLE_PHASE) +
				"', parameters " + StylerUtils.style(request.getParameterMap()));
	}
	throw new NoHandlerFoundException("No handler found for portlet request", request);
}
 
Example #14
Source File: ActionConfigIndexer.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest,
		PortletResponse portletResponse) throws Exception {
	Summary summary = createSummary(document);

	summary.setMaxContentLength(QueryUtil.ALL_POS);

	return summary;
}
 
Example #15
Source File: PaymentConfigIndexer.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest,
		PortletResponse portletResponse) throws Exception {
	Summary summary = createSummary(document);

	summary.setMaxContentLength(QueryUtil.ALL_POS);

	return summary;
}
 
Example #16
Source File: ServiceConfigIndexer.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest,
		PortletResponse portletResponse) throws Exception {
	Summary summary = createSummary(document);

	summary.setMaxContentLength(QueryUtil.ALL_POS);

	return summary;
}
 
Example #17
Source File: RegistrationLogIndexer.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest,
		PortletResponse portletResponse) throws Exception {
	Summary summary = createSummary(document);

	summary.setMaxContentLength(QueryUtil.ALL_POS);

	return summary;
}
 
Example #18
Source File: RegistrationIndexer.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest,
		PortletResponse portletResponse) throws Exception {
	Summary summary = createSummary(document);

	summary.setMaxContentLength(QueryUtil.ALL_POS);

	return summary;
}
 
Example #19
Source File: DictItemIndexer.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected Summary doGetSummary(
	Document document, Locale locale, String snippet,
	PortletRequest portletRequest, PortletResponse portletResponse) {

	Summary summary = createSummary(document);

	summary.setMaxContentLength(QueryUtil.ALL_POS);
	
	return summary;
}
 
Example #20
Source File: CommentIndexer.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected Summary doGetSummary(
	Document document, Locale locale, String snippet,
	PortletRequest portletRequest, PortletResponse portletResponse) {

	Summary summary = createSummary(document);

	summary.setMaxContentLength(QueryUtil.ALL_POS);

	return summary;
}
 
Example #21
Source File: DispatcherTests4_SPEC2_19_ForwardServletResource_servlet.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
protected void processTCKReq(HttpServletRequest request, HttpServletResponse response) throws ServletException,
      IOException {

   PortletRequest portletReq = (PortletRequest) request.getAttribute("javax.portlet.request");
   PortletResponse portletResp = (PortletResponse) request.getAttribute("javax.portlet.response");
   request.getAttribute("javax.portlet.config");
   Thread.currentThread().getId();
   portletReq.getAttribute(THREADID_ATTR);

   PrintWriter writer = ((MimeResponse) portletResp).getWriter();

   JSR286DispatcherTestCaseDetails tcd = new JSR286DispatcherTestCaseDetails();

   // Create result objects for the tests

   /* TestCase: V2DispatcherTests4_SPEC2_19_ForwardServletResource_invoke3 */
   /* Details: "Parameters to the forward method for a target servlet */
   /* can be wrapped request and response classes from the portlet */
   /* lifecyle method initiating the include" */
   TestResult tr0 = tcd.getTestResultFailed(V2DISPATCHERTESTS4_SPEC2_19_FORWARDSERVLETRESOURCE_INVOKE3);
   try {
      // If this gets executed, include worked.
      tr0.setTcSuccess(true);
   } catch (Exception e) {
      tr0.appendTcDetail(e.toString());
   }
   tr0.writeTo(writer);

}
 
Example #22
Source File: DefaultPortletInvokerService.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
/**
 * Invoke the portlet with a load request.
 *
 * @param request  action request used for the invocation.
 * @param response action response used for the invocation.
 * @see PortletServlet3
 */
public void load(PortletRequestContext context, PortletRequest request, PortletResponse response)
throws IOException, PortletException, PortletContainerException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Performing Load Invocation.");
    }
    invoke(context, request, response, PortletInvokerService.METHOD_LOAD);
}
 
Example #23
Source File: DefaultPortletInvokerService.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
private final void invoke(PortletRequestContext context,
        PortletRequest request,
        PortletResponse response,
        Integer methodID)
throws PortletException, IOException, PortletContainerException {

    invoke(context, request, response, null, methodID);
}
 
Example #24
Source File: RenderURLTag168.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
/**
    * Creates a render PortletURL
    * @param portletResponse PortletResponse
    * @return PortletURL
    */
@Override
protected PortletURL createPortletUrl(PortletResponse portletResponse){
	if (portletResponse instanceof RenderResponse) {
		return ((RenderResponse)portletResponse).createRenderURL();			
	}
	throw new IllegalArgumentException();
}
 
Example #25
Source File: DefineObjectsTag286.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method.
 * <p>
 * Sets the portlet render and request attribute with 
 * the names described in the JSR 286 - PLT 26.1 (defineObjects Tag).
 * 
 * @param request PortletRequest
 * @param response PortletResponse
 */
protected void setPortletRequestResponseAttribute(PortletRequest request, 
		PortletResponse response ){
	
	String phase = (String)request.getAttribute(PortletRequest.LIFECYCLE_PHASE);
	
  setAttribute(request, "portletRequest");
  setAttribute(response, "portletResponse");
	
	//check where request and response where included from
	if(PortletRequest.ACTION_PHASE.equals(phase)){
		setAttribute(request, "actionRequest");
		setAttribute(response, "actionResponse");
	}    	
	else if(PortletRequest.EVENT_PHASE.equals(phase)){
		setAttribute(request, "eventRequest");
		setAttribute(response, "eventResponse");
	}
	else if(PortletRequest.RENDER_PHASE.equals(phase)){
		setAttribute(request, "renderRequest");
		setAttribute(response, "renderResponse");
	}    	
	else if(PortletRequest.RESOURCE_PHASE.equals(phase)){
		setAttribute(request, "resourceRequest");
		setAttribute(response, "resourceResponse");
	}
}
 
Example #26
Source File: MockPortletRequestDispatcher.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void include(PortletRequest request, PortletResponse response) throws PortletException, IOException {
	Assert.notNull(request, "Request must not be null");
	Assert.notNull(response, "Response must not be null");
	if (!(response instanceof MockMimeResponse)) {
		throw new IllegalArgumentException("MockPortletRequestDispatcher requires MockMimeResponse");
	}
	((MockMimeResponse) response).setIncludedUrl(this.url);
	if (logger.isDebugEnabled()) {
		logger.debug("MockPortletRequestDispatcher: including URL [" + this.url + "]");
	}
}
 
Example #27
Source File: PortletArtifactProducer.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
/**
 * Producer method for the portlet response. 
 * @return
 */
@Produces @PortletRequestScoped @Named("portletResponse")
public static PortletResponse producePortletResponse() {
   PortletArtifactProducer pap = producers.get();
   assert pap != null;
   return pap.resp;
}
 
Example #28
Source File: MockPortletRequestDispatcher.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void forward(PortletRequest request, PortletResponse response) throws PortletException, IOException {
	Assert.notNull(request, "Request must not be null");
	Assert.notNull(response, "Response must not be null");
	if (!(response instanceof MockMimeResponse)) {
		throw new IllegalArgumentException("MockPortletRequestDispatcher requires MockMimeResponse");
	}
	((MockMimeResponse) response).setForwardedUrl(this.url);
	if (logger.isDebugEnabled()) {
		logger.debug("MockPortletRequestDispatcher: forwarding to URL [" + this.url + "]");
	}
}
 
Example #29
Source File: AbstractReflectivePortletTest.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
/**
 * Invokes the test method ('<code>check*</code>') by preparing method
 * parameters. A test method may accept the following types of parameters:
 * <ul>
 *   <li><code>javax.portlet.PortletConfig</code></li>
 *   <li><code>javax.portlet.PortletContext</code></li>
 *   <li><code>javax.portlet.PortletRequest</code></li>
 *   <li><code>javax.portlet.PortletResponse</code></li>
 *   <li><code>javax.portlet.PortletSession</code></li>
 * </ul>
 */
private TestResult invoke(Method method,
                          PortletConfig config,
                          PortletContext context,
                          PortletRequest request,
                          PortletResponse response)
throws IllegalAccessException, InvocationTargetException {

    Class<?>[] paramTypes = method.getParameterTypes();
    Object[] paramValues = new Object[paramTypes.length];

    for (int i = 0; i < paramTypes.length; i++) {
        if (paramTypes[i].equals(PortletConfig.class)) {
            paramValues[i] = config;
        } else if (paramTypes[i].equals(PortletContext.class)) {
            paramValues[i] = context;
        } else if (paramTypes[i].isAssignableFrom(request.getClass())) {
            paramValues[i] = request;
        } else if (paramTypes[i].isAssignableFrom(response.getClass())) {
            paramValues[i] = response;
        } else if (paramTypes[i].equals(PortletSession.class)) {
            paramValues[i] = request.getPortletSession();
        }
    }
    TestResult result = (TestResult) method.invoke(this, paramValues);
    return result;
}
 
Example #30
Source File: ActionURLTag286.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
/**
    * Creates an action PortletURL 
    * @param portletResponse PortletResponse
    * @return PortletURL
    */
@Override
protected PortletURL createPortletUrl(PortletResponse portletResponse){
	if (portletResponse instanceof RenderResponse) {
		return ((RenderResponse)portletResponse).createActionURL();			
	}
	else if (portletResponse instanceof ResourceResponse) {
		return ((ResourceResponse)portletResponse).createActionURL();			
	}
	throw new IllegalArgumentException();
}