Search in sources :

Example 1 with HeaderRequest

use of javax.portlet.HeaderRequest in project liferay-faces-bridge-impl by liferay.

the class Tests method getRequestContentLengthTest.

// Test 6.144
@BridgeTest(test = "getRequestContentLengthTest")
public String getRequestContentLengthTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Bridge.PortletPhase portletRequestPhase = BridgeUtil.getPortletRequestPhase(facesContext);
    if (portletRequestPhase == Bridge.PortletPhase.ACTION_PHASE) {
        ExternalContext externalContext = facesContext.getExternalContext();
        ActionRequest actionRequest = (ActionRequest) externalContext.getRequest();
        ActionResponse actionResponse = (ActionResponse) externalContext.getResponse();
        MutableRenderParameters renderParameters = actionResponse.getRenderParameters();
        renderParameters.setValue("getRequestContentLengthTest", Boolean.valueOf(actionRequest.getContentLength() == externalContext.getRequestContentLength()).toString());
        return "multiRequestTestResultRenderCheck";
    } else if (portletRequestPhase == Bridge.PortletPhase.HEADER_PHASE) {
        ExternalContext externalContext = facesContext.getExternalContext();
        HeaderRequest headerRequest = (HeaderRequest) externalContext.getRequest();
        RenderParameters renderParameters = headerRequest.getRenderParameters();
        if (Boolean.valueOf(renderParameters.getValue("getRequestContentLengthTest"))) {
            testBean.setTestResult(true, "externalContext.getRequestContentLength() returned the expected value");
        } else {
            testBean.setTestResult(false, "externalContext.getRequestContentLength() did not return the expected value");
        }
        testBean.setTestComplete(true);
        if (testBean.getTestStatus()) {
            return Constants.TEST_SUCCESS;
        } else {
            return Constants.TEST_FAILED;
        }
    }
    return "";
}
Also used : FacesContext(javax.faces.context.FacesContext) ActionRequest(javax.portlet.ActionRequest) ExternalContext(javax.faces.context.ExternalContext) MutableRenderParameters(javax.portlet.MutableRenderParameters) HeaderRequest(javax.portlet.HeaderRequest) MutableRenderParameters(javax.portlet.MutableRenderParameters) RenderParameters(javax.portlet.RenderParameters) Bridge(javax.portlet.faces.Bridge) ActionResponse(javax.portlet.ActionResponse) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 2 with HeaderRequest

use of javax.portlet.HeaderRequest in project liferay-faces-bridge-impl by liferay.

the class Tests method bridgeSetsContentTypeTest.

/**
 * As defined in portlet.xml, this test uses {@link ManualBridgeInvokePortlet} rather than {@link
 * com.liferay.faces.bridge.tck.common.portlet.GenericFacesTestSuitePortlet}. It relies on
 * NullContentTypePortletFilter to decorate the HeaderResponse to ensure that the HeaderResponse.getContentType()
 * method returns null. {@link ManualBridgeInvokePortlet} will invoke the bridge directly and not set the
 * contentType (as is normally done in its outputTestResult method). All this will cause the bridge's implementation
 * of ExternalContext.getResponseContentType() to consult HeaderRequest.getContentType() in order to determine the
 * content type.
 */
// Test is Header test
// Test #5.29
@BridgeTest(test = "bridgeSetsContentTypeTest")
public String bridgeSetsContentTypeTest(TestBean testBean) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    testBean.setTestComplete(true);
    HeaderResponse headerResponse = (HeaderResponse) externalContext.getResponse();
    String headerResponseContentType = headerResponse.getContentType();
    HeaderRequest headerRequest = (HeaderRequest) externalContext.getRequest();
    String headerRequestContentType = headerRequest.getResponseContentType();
    String externalContextResponseContentType = externalContext.getResponseContentType();
    if ((headerResponseContentType == null) && (externalContextResponseContentType != null) && (headerRequestContentType != null) && externalContextResponseContentType.equals(headerRequestContentType)) {
        testBean.setTestResult(true, "Bridge correctly set the proper (default) content type when not set by portlet.");
        return Constants.TEST_SUCCESS;
    } else if (headerResponseContentType != null) {
        testBean.setTestResult(false, "NullContentTypePortletFilter did not return null for the response contentType. Current: " + headerRequestContentType + " expected: null");
        return Constants.TEST_FAILED;
    } else {
        testBean.setTestResult(false, "Bridge didn't set the proper (default) content type when not set by portlet.  Current: " + externalContextResponseContentType + " expected: " + headerRequestContentType);
        return Constants.TEST_FAILED;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) HeaderResponse(javax.portlet.HeaderResponse) ExternalContext(javax.faces.context.ExternalContext) HeaderRequest(javax.portlet.HeaderRequest) BridgeTest(com.liferay.faces.bridge.tck.annotation.BridgeTest)

Example 3 with HeaderRequest

use of javax.portlet.HeaderRequest in project liferay-faces-bridge-impl by liferay.

the class ViewDeclarationLanguageBridgeJspImpl method buildView.

@Override
public void buildView(FacesContext facesContext, UIViewRoot uiViewRoot) throws IOException {
    ExternalContext externalContext = facesContext.getExternalContext();
    ProductFactory productFactory = (ProductFactory) FactoryExtensionFinder.getFactory(externalContext, ProductFactory.class);
    final Product MYFACES = productFactory.getProductInfo(Product.Name.MYFACES);
    final boolean MYFACES_DETECTED = MYFACES.isDetected();
    PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
    PortletResponse portletResponse = (PortletResponse) externalContext.getResponse();
    // adapter that implements HttpServletRequest.
    if (MYFACES_DETECTED) {
        if (portletRequest instanceof HeaderRequest) {
            String requestCharacterEncoding = externalContext.getRequestCharacterEncoding();
            externalContext.setRequest(new HeaderRequestHttpServletAdapter((HeaderRequest) portletRequest, requestCharacterEncoding));
        } else if (portletRequest instanceof ResourceRequest) {
            externalContext.setRequest(new ResourceRequestHttpServletAdapter((ResourceRequest) portletRequest));
        }
    }
    final Product MOJARRA = productFactory.getProductInfo(Product.Name.MOJARRA);
    final boolean MOJARRA_DETECTED = MOJARRA.isDetected();
    // PortletResponse with an adapter that implements HttpServletResponse.
    if (MOJARRA_DETECTED || MYFACES_DETECTED) {
        if (portletResponse instanceof HeaderResponse) {
            externalContext.setResponse(new HeaderResponseHttpServletAdapter((HeaderResponse) portletResponse));
        } else if (portletResponse instanceof ResourceResponse) {
            externalContext.setResponse(new ResourceResponseHttpServletAdapter((ResourceResponse) portletResponse));
        }
    }
    // Delegate
    super.buildView(facesContext, uiViewRoot);
    // If Mojarra or MyFaces is detected, then un-decorate the PortletRequest.
    if (MOJARRA_DETECTED || MYFACES_DETECTED) {
        externalContext.setResponse(portletResponse);
    }
    // If MyFaces is detected, then un-decorate the PortletResponse.
    if (MYFACES_DETECTED) {
        externalContext.setRequest(portletRequest);
    }
}
Also used : ProductFactory(com.liferay.faces.util.product.ProductFactory) ResourceResponseHttpServletAdapter(com.liferay.faces.bridge.filter.internal.ResourceResponseHttpServletAdapter) PortletResponse(javax.portlet.PortletResponse) Product(com.liferay.faces.util.product.Product) ResourceRequestHttpServletAdapter(com.liferay.faces.bridge.filter.internal.ResourceRequestHttpServletAdapter) HeaderResponseHttpServletAdapter(com.liferay.faces.bridge.filter.internal.HeaderResponseHttpServletAdapter) HeaderResponse(javax.portlet.HeaderResponse) PortletRequest(javax.portlet.PortletRequest) HeaderRequestHttpServletAdapter(com.liferay.faces.bridge.filter.internal.HeaderRequestHttpServletAdapter) ResourceResponse(javax.portlet.ResourceResponse) ExternalContext(javax.faces.context.ExternalContext) HeaderRequest(javax.portlet.HeaderRequest) ResourceRequest(javax.portlet.ResourceRequest)

Aggregations

ExternalContext (javax.faces.context.ExternalContext)3 HeaderRequest (javax.portlet.HeaderRequest)3 BridgeTest (com.liferay.faces.bridge.tck.annotation.BridgeTest)2 FacesContext (javax.faces.context.FacesContext)2 HeaderResponse (javax.portlet.HeaderResponse)2 HeaderRequestHttpServletAdapter (com.liferay.faces.bridge.filter.internal.HeaderRequestHttpServletAdapter)1 HeaderResponseHttpServletAdapter (com.liferay.faces.bridge.filter.internal.HeaderResponseHttpServletAdapter)1 ResourceRequestHttpServletAdapter (com.liferay.faces.bridge.filter.internal.ResourceRequestHttpServletAdapter)1 ResourceResponseHttpServletAdapter (com.liferay.faces.bridge.filter.internal.ResourceResponseHttpServletAdapter)1 Product (com.liferay.faces.util.product.Product)1 ProductFactory (com.liferay.faces.util.product.ProductFactory)1 ActionRequest (javax.portlet.ActionRequest)1 ActionResponse (javax.portlet.ActionResponse)1 MutableRenderParameters (javax.portlet.MutableRenderParameters)1 PortletRequest (javax.portlet.PortletRequest)1 PortletResponse (javax.portlet.PortletResponse)1 RenderParameters (javax.portlet.RenderParameters)1 ResourceRequest (javax.portlet.ResourceRequest)1 ResourceResponse (javax.portlet.ResourceResponse)1 Bridge (javax.portlet.faces.Bridge)1