/** * Check whether the given request matches the specified request methods. * @param methods the request methods to check against * @param request the current request to check */ public static boolean checkRequestMethod(RequestMethod[] methods, PortletRequest request) { if (methods.length == 0) { return true; } if (!(request instanceof ClientDataRequest)) { return false; } String method = ((ClientDataRequest) request).getMethod(); for (RequestMethod candidate : methods) { if (method.equals(candidate.name())) { return true; } } return false; }
@Override public void validate(PortletRequest request) throws PortletException { if (!PortletAnnotationMappingUtils.checkHeaders(this.headers, request)) { throw new PortletRequestBindingException("Header conditions \"" + StringUtils.arrayToDelimitedString(this.headers, ", ") + "\" not met for actual request"); } if (!this.methods.isEmpty()) { if (!(request instanceof ClientDataRequest)) { throw new PortletRequestMethodNotSupportedException(StringUtils.toStringArray(this.methods)); } String method = ((ClientDataRequest) request).getMethod(); if (!this.methods.contains(method)) { throw new PortletRequestMethodNotSupportedException(method, StringUtils.toStringArray(this.methods)); } } }
public void validate(PortletRequest request) throws PortletException { if (!PortletAnnotationMappingUtils.checkHeaders(this.headers, request)) { throw new PortletRequestBindingException("Header conditions \"" + StringUtils.arrayToDelimitedString(this.headers, ", ") + "\" not met for actual request"); } if (!this.methods.isEmpty()) { if (!(request instanceof ClientDataRequest)) { throw new PortletRequestMethodNotSupportedException(StringUtils.toStringArray(this.methods)); } String method = ((ClientDataRequest) request).getMethod(); if (!this.methods.contains(method)) { throw new PortletRequestMethodNotSupportedException(method, StringUtils.toStringArray(this.methods)); } } }
/** * Check whether the given request matches the specified request methods. * @param methods the request methods to check against * @param request the current request to check */ public static boolean checkRequestMethod(Set<String> methods, PortletRequest request) { if (!methods.isEmpty()) { if (!(request instanceof ClientDataRequest)) { return false; } String method = ((ClientDataRequest) request).getMethod(); if (!methods.contains(method)) { return false; } } return true; }
@Override public String getCharacterEncoding() { if (isClosed) return null; if (preq instanceof ClientDataRequest) { return ((ClientDataRequest) preq).getCharacterEncoding(); } return null; }
@Override public void setCharacterEncoding(String enc) throws UnsupportedEncodingException { if (isClosed) return; if (preq instanceof ClientDataRequest) { ((ClientDataRequest) preq).setCharacterEncoding(enc); } }
@Override public int getContentLength() { if (isClosed) return 0; if (preq instanceof ClientDataRequest) { return ((ClientDataRequest) preq).getContentLength(); } return 0; }
@Override public long getContentLengthLong() { if (isClosed) return 0L; if (preq instanceof ClientDataRequest) { return ((ClientDataRequest) preq).getContentLengthLong(); } return 0L; }
@Override public String getContentType() { if (isClosed) return null; if (preq instanceof ClientDataRequest) { return ((ClientDataRequest) preq).getContentType(); } return null; }
@Override public ServletInputStream getInputStream() throws IOException { if (isClosed) return null; if (preq instanceof ClientDataRequest) { return (ServletInputStream) ((ClientDataRequest) preq).getPortletInputStream(); } return null; }
@Override public BufferedReader getReader() throws IOException { if (preq instanceof ClientDataRequest) { return ((ClientDataRequest) preq).getReader(); } return null; }
@Override public Part getPart(String name) throws IOException, ServletException { if (preq instanceof ClientDataRequest) { try { return ((ClientDataRequest) preq).getPart(name); } catch (PortletException e) { throw new ServletException(e.getCause()); } } return null; }
@Override public Collection<Part> getParts() throws IOException, ServletException { if (preq instanceof ClientDataRequest) { try { return ((ClientDataRequest) preq).getParts(); } catch (PortletException e) { throw new ServletException(e.getCause()); } } return null; }
/** * Producer method for the ClientDataRequest. */ @Produces @PortletRequestScoped @Named("clientDataRequest") @Typed(ClientDataRequest.class) public static ClientDataRequest produceClientDataRequest() { PortletArtifactProducer pap = producers.get(); assert pap != null; ClientDataRequest req = null; if (pap.req instanceof ClientDataRequest) { req = (ClientDataRequest) pap.req; } return req; }
public void setCharacterEncoding(String enc) throws UnsupportedEncodingException { PortletRequest portletRequest = getWrapped(); if (portletRequest instanceof ClientDataRequest) { ClientDataRequest clientDataRequest = (ClientDataRequest) portletRequest; clientDataRequest.setCharacterEncoding(enc); } else { throw new UnsupportedOperationException(); } }
public int getContentLength() { PortletRequest portletRequest = getWrapped(); if (portletRequest instanceof ClientDataRequest) { ClientDataRequest clientDataRequest = (ClientDataRequest) portletRequest; return clientDataRequest.getContentLength(); } else { throw new UnsupportedOperationException(); } }
public String getContentType() { PortletRequest portletRequest = getWrapped(); if (portletRequest instanceof ClientDataRequest) { ClientDataRequest clientDataRequest = (ClientDataRequest) portletRequest; return clientDataRequest.getContentType(); } else { throw new UnsupportedOperationException(); } }
public String getMethod() { PortletRequest portletRequest = getWrapped(); if (portletRequest instanceof ClientDataRequest) { ClientDataRequest clientDataRequest = (ClientDataRequest) portletRequest; return clientDataRequest.getMethod(); } else { throw new UnsupportedOperationException(); } }
public BufferedReader getReader() throws IOException { PortletRequest portletRequest = getWrapped(); if (portletRequest instanceof ClientDataRequest) { ClientDataRequest clientDataRequest = (ClientDataRequest) portletRequest; return clientDataRequest.getReader(); } else { throw new UnsupportedOperationException(); } }
@Override protected Object resolveStandardArgument(Class<?> parameterType, NativeWebRequest webRequest) throws Exception { PortletRequest request = webRequest.getNativeRequest(PortletRequest.class); PortletResponse response = webRequest.getNativeResponse(PortletResponse.class); if (PortletRequest.class.isAssignableFrom(parameterType) || MultipartRequest.class.isAssignableFrom(parameterType)) { Object nativeRequest = webRequest.getNativeRequest(parameterType); if (nativeRequest == null) { throw new IllegalStateException( "Current request is not of type [" + parameterType.getName() + "]: " + request); } return nativeRequest; } else if (PortletResponse.class.isAssignableFrom(parameterType)) { Object nativeResponse = webRequest.getNativeResponse(parameterType); if (nativeResponse == null) { throw new IllegalStateException( "Current response is not of type [" + parameterType.getName() + "]: " + response); } return nativeResponse; } else if (PortletSession.class.isAssignableFrom(parameterType)) { return request.getPortletSession(); } else if (PortletPreferences.class.isAssignableFrom(parameterType)) { return request.getPreferences(); } else if (PortletMode.class.isAssignableFrom(parameterType)) { return request.getPortletMode(); } else if (WindowState.class.isAssignableFrom(parameterType)) { return request.getWindowState(); } else if (PortalContext.class.isAssignableFrom(parameterType)) { return request.getPortalContext(); } else if (Principal.class.isAssignableFrom(parameterType)) { return request.getUserPrincipal(); } else if (Locale.class == parameterType) { return request.getLocale(); } else if (InputStream.class.isAssignableFrom(parameterType)) { if (!(request instanceof ClientDataRequest)) { throw new IllegalStateException("InputStream can only get obtained for Action/ResourceRequest"); } return ((ClientDataRequest) request).getPortletInputStream(); } else if (Reader.class.isAssignableFrom(parameterType)) { if (!(request instanceof ClientDataRequest)) { throw new IllegalStateException("Reader can only get obtained for Action/ResourceRequest"); } return ((ClientDataRequest) request).getReader(); } else if (OutputStream.class.isAssignableFrom(parameterType)) { if (!(response instanceof MimeResponse)) { throw new IllegalStateException("OutputStream can only get obtained for Render/ResourceResponse"); } return ((MimeResponse) response).getPortletOutputStream(); } else if (Writer.class.isAssignableFrom(parameterType)) { if (!(response instanceof MimeResponse)) { throw new IllegalStateException("Writer can only get obtained for Render/ResourceResponse"); } return ((MimeResponse) response).getWriter(); } else if (Event.class == parameterType) { if (!(request instanceof EventRequest)) { throw new IllegalStateException("Event can only get obtained from EventRequest"); } return ((EventRequest) request).getEvent(); } return super.resolveStandardArgument(parameterType, webRequest); }
@Override protected Object resolveStandardArgument(Class<?> parameterType, NativeWebRequest webRequest) throws Exception { PortletRequest request = webRequest.getNativeRequest(PortletRequest.class); PortletResponse response = webRequest.getNativeResponse(PortletResponse.class); if (PortletRequest.class.isAssignableFrom(parameterType) || MultipartRequest.class.isAssignableFrom(parameterType)) { Object nativeRequest = webRequest.getNativeRequest(parameterType); if (nativeRequest == null) { throw new IllegalStateException( "Current request is not of type [" + parameterType.getName() + "]: " + request); } return nativeRequest; } else if (PortletResponse.class.isAssignableFrom(parameterType)) { Object nativeResponse = webRequest.getNativeResponse(parameterType); if (nativeResponse == null) { throw new IllegalStateException( "Current response is not of type [" + parameterType.getName() + "]: " + response); } return nativeResponse; } else if (PortletSession.class.isAssignableFrom(parameterType)) { return request.getPortletSession(); } else if (PortletPreferences.class.isAssignableFrom(parameterType)) { return request.getPreferences(); } else if (PortletMode.class.isAssignableFrom(parameterType)) { return request.getPortletMode(); } else if (WindowState.class.isAssignableFrom(parameterType)) { return request.getWindowState(); } else if (PortalContext.class.isAssignableFrom(parameterType)) { return request.getPortalContext(); } else if (Principal.class.isAssignableFrom(parameterType)) { return request.getUserPrincipal(); } else if (Locale.class.equals(parameterType)) { return request.getLocale(); } else if (InputStream.class.isAssignableFrom(parameterType)) { if (!(request instanceof ClientDataRequest)) { throw new IllegalStateException("InputStream can only get obtained for Action/ResourceRequest"); } return ((ClientDataRequest) request).getPortletInputStream(); } else if (Reader.class.isAssignableFrom(parameterType)) { if (!(request instanceof ClientDataRequest)) { throw new IllegalStateException("Reader can only get obtained for Action/ResourceRequest"); } return ((ClientDataRequest) request).getReader(); } else if (OutputStream.class.isAssignableFrom(parameterType)) { if (!(response instanceof MimeResponse)) { throw new IllegalStateException("OutputStream can only get obtained for Render/ResourceResponse"); } return ((MimeResponse) response).getPortletOutputStream(); } else if (Writer.class.isAssignableFrom(parameterType)) { if (!(response instanceof MimeResponse)) { throw new IllegalStateException("Writer can only get obtained for Render/ResourceResponse"); } return ((MimeResponse) response).getWriter(); } else if (Event.class.equals(parameterType)) { if (!(request instanceof EventRequest)) { throw new IllegalStateException("Event can only get obtained from EventRequest"); } return ((EventRequest) request).getEvent(); } return super.resolveStandardArgument(parameterType, webRequest); }
@Override protected void setPortletRequestResponseAttribute(PortletRequest request, PortletResponse response) { PortletContext poco = request.getPortletContext(); setAttribute(poco, "portletContext"); PortletConfig config = (PortletConfig) pageContext.getRequest().getAttribute(Constants.PORTLET_CONFIG); setAttribute(config.getPortletName(), "portletName"); setAttribute(request.getRenderParameters(), "renderParams"); setAttribute(request.getPortletMode(), "portletMode"); setAttribute(request.getWindowState(), "windowState"); setAttribute(request.getCookies(), "cookies"); setAttribute(Collections.list(request.getLocales()).toArray(new Locale[0]), "locales"); setAttribute(request.getLocale(), "locale"); setAttribute(request.getWindowID(), "windowId"); setAttribute(request.getContextPath(), "contextPath"); setAttribute(response.getNamespace(), "namespace"); if (request instanceof ClientDataRequest) { setAttribute(request, "clientDataRequest"); if (request instanceof ActionRequest) { setAttribute(((ActionRequest) request).getActionParameters(), "actionParameters"); } else { setAttribute(((ResourceRequest) request).getResourceParameters(), "resourceParameters"); } } if (response instanceof StateAwareResponse) { setAttribute(response, "stateAwareResponse"); setAttribute(((StateAwareResponse) response).getRenderParameters(), "mutableRenderParams"); } if (response instanceof MimeResponse) { setAttribute(response, "mimeResponse"); } if(request instanceof HeaderRequest){ setAttribute(request, "headerRequest"); setAttribute(response, "headerResponse"); } super.setPortletRequestResponseAttribute(request, response); }
/** * @param request */ public ClientDataRequestWrapper(ClientDataRequest request) { super(request); }
public InputStream getPortletInputStream() throws IOException { return ((ClientDataRequest)wrapped).getPortletInputStream(); }
public void setCharacterEncoding(String enc) throws UnsupportedEncodingException { ((ClientDataRequest)wrapped).setCharacterEncoding(enc); }
public BufferedReader getReader() throws UnsupportedEncodingException, IOException { return ((ClientDataRequest)wrapped).getReader(); }
public String getCharacterEncoding() { return ((ClientDataRequest)wrapped).getCharacterEncoding(); }
public String getContentType() { return ((ClientDataRequest)wrapped).getContentType(); }
public int getContentLength() { return ((ClientDataRequest)wrapped).getContentLength(); }
@Override public long getContentLengthLong() { return ((ClientDataRequest)wrapped).getContentLengthLong(); }
public String getMethod() { return ((ClientDataRequest)wrapped).getMethod(); }
@Override public Part getPart(String name) throws IOException, PortletException { return ((ClientDataRequest)wrapped).getPart(name); }
@Override public Collection<Part> getParts() throws IOException, PortletException { return ((ClientDataRequest)wrapped).getParts(); }
public String getCharacterEncoding() { PortletRequest portletRequest = getWrapped(); if (portletRequest instanceof ClientDataRequest) { ClientDataRequest clientDataRequest = (ClientDataRequest) portletRequest; return clientDataRequest.getCharacterEncoding(); } else { return null; } }
/** * Return the wrapped request object. * * @return the wrapped request */ public ClientDataRequest getRequest() { return (ClientDataRequest) super.getRequest(); }
/** * Sets the request object being wrapped. * * @param request * the request to set * @throws java.lang.IllegalArgumentException * if the request is null. */ public void setRequest(ClientDataRequest request) { super.setRequest(request); }