Java 类javax.portlet.filter.PortletRequestWrapper 实例源码

项目:spring4-understanding    文件:PortletWebRequestTests.java   
@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));
}
项目:class-guard    文件:PortletWebRequestTests.java   
@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));
}
项目:spring4-understanding    文件:PortletUtils.java   
/**
 * Return an appropriate request object of the specified type, if available,
 * unwrapping the given request as far as necessary.
 * @param request the portlet request to introspect
 * @param requiredType the desired type of request object
 * @return the matching request object, or {@code null} if none
 * of that type is available
 */
@SuppressWarnings("unchecked")
public static <T> T getNativeRequest(PortletRequest request, Class<T> requiredType) {
    if (requiredType != null) {
        if (requiredType.isInstance(request)) {
            return (T) request;
        }
        else if (request instanceof PortletRequestWrapper) {
            return getNativeRequest(((PortletRequestWrapper) request).getRequest(), requiredType);
        }
    }
    return null;
}
项目:class-guard    文件:PortletUtils.java   
/**
 * Return an appropriate request object of the specified type, if available,
 * unwrapping the given request as far as necessary.
 * @param request the portlet request to introspect
 * @param requiredType the desired type of request object
 * @return the matching request object, or {@code null} if none
 * of that type is available
 */
@SuppressWarnings("unchecked")
public static <T> T getNativeRequest(PortletRequest request, Class<T> requiredType) {
    if (requiredType != null) {
        if (requiredType.isInstance(request)) {
            return (T) request;
        }
        else if (request instanceof PortletRequestWrapper) {
            return getNativeRequest(((PortletRequestWrapper) request).getRequest(), requiredType);
        }
    }
    return null;
}