Java Code Examples for javax.servlet.ServletRequest

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Blitz, under directory /src/com/laxser/blitz/web/impl/thread/.

Source file: RootEngine.java

  18 
vote

/** 
 * Keep a snapshot of the request attributes in case of an include, to be able to restore the original attributes after the include.
 * @param inv
 */
private void saveAttributesBeforeInclude(final Invocation inv){
  ServletRequest request=inv.getRequest();
  logger.debug("Taking snapshot of request attributes before include");
  Map<String,Object> attributesSnapshot=new HashMap<String,Object>();
  Enumeration<?> attrNames=request.getAttributeNames();
  while (attrNames.hasMoreElements()) {
    String attrName=(String)attrNames.nextElement();
    attributesSnapshot.put(attrName,request.getAttribute(attrName));
  }
  inv.setAttribute("$$paoding-blitz.attributesBeforeInclude",attributesSnapshot);
}
 

Example 2

From project candlepin, under directory /src/test/java/org/candlepin/servlet/filter/.

Source file: CandlepinPersistFilterTest.java

  18 
vote

@Test public void transaction() throws IOException, ServletException {
  ServletRequest req=mock(ServletRequest.class);
  ServletResponse rsp=mock(ServletResponse.class);
  FilterChain chain=mock(FilterChain.class);
  filter.doFilter(req,rsp,chain);
  verify(work,atLeastOnce()).begin();
  verify(work,atLeastOnce()).end();
  verify(chain,atLeastOnce()).doFilter(eq(req),eq(rsp));
}
 

Example 3

From project capedwarf-blue, under directory /appidentity/src/main/java/org/jboss/capedwarf/appidentity/.

Source file: GAEListener.java

  18 
vote

public void requestInitialized(ServletRequestEvent sre){
  long requestStartMillis=System.currentTimeMillis();
  final ServletRequest req=sre.getServletRequest();
  if (req instanceof HttpServletRequest)   initJBossEnvironment((HttpServletRequest)req);
  getLogService().requestStarted(sre.getServletRequest(),requestStartMillis);
}
 

Example 4

From project cas, under directory /cas-server-core/src/test/java/org/jasig/cas/web/init/.

Source file: SafeDispatcherServletTests.java

  18 
vote

public void testService() throws ServletException, IOException {
  this.safeServlet.init(this.mockConfig);
  ServletRequest mockRequest=new MockHttpServletRequest();
  ServletResponse mockResponse=new MockHttpServletResponse();
  try {
    this.safeServlet.service(mockRequest,mockResponse);
  }
 catch (  ApplicationContextException ace) {
    return;
  }
  fail("Should have thrown ApplicationContextException since init() failed.");
}
 

Example 5

From project entando-core-engine, under directory /src/main/java/com/agiletec/aps/tags/.

Source file: CheckHeadInfoOutputterTag.java

  18 
vote

public int doStartTag() throws JspException {
  ServletRequest request=this.pageContext.getRequest();
  RequestContext reqCtx=(RequestContext)request.getAttribute(RequestContext.REQCTX);
  HeadInfoContainer headInfo=(HeadInfoContainer)reqCtx.getExtraParam(SystemConstants.EXTRAPAR_HEAD_INFO_CONTAINER);
  List<Object> infos=headInfo.getInfos(this.getType());
  if (infos == null || infos.size() == 0) {
    return SKIP_BODY;
  }
 else {
    return EVAL_BODY_INCLUDE;
  }
}
 

Example 6

From project amber, under directory /oauth-2.0/dynamicreg-server/src/main/java/org/apache/amber/oauth2/ext/dynamicreg/server/request/.

Source file: JSONHttpServletRequestWrapper.java

  17 
vote

/** 
 * Lazily read JSON from request
 * @throws OAuthProblemException
 */
private void readJsonBody(){
  if (!bodyRead) {
    bodyRead=true;
    try {
      final ServletRequest request=getRequest();
      String contentType=request.getContentType();
      final String expectedContentType=OAuth.ContentType.JSON;
      if (!OAuthUtils.hasContentType(contentType,expectedContentType)) {
        return;
      }
      final ServletInputStream inputStream=request.getInputStream();
      if (inputStream == null) {
        return;
      }
      final String jsonString=OAuthUtils.saveStreamAsString(inputStream);
      body=new JSONObject(jsonString);
    }
 catch (    JSONException e) {
      log.error("Cannot decode request body as a JSON: ",e);
    }
catch (    Exception e) {
      log.error("Dynamic client registration error: ",e);
      throw new OAuthRuntimeException("OAuth server error");
    }
  }
}
 

Example 7

From project guice-jit-providers, under directory /extensions/servlet/src/com/google/inject/servlet/.

Source file: ManagedServletPipeline.java

  17 
vote

/** 
 * @return Returns a request dispatcher wrapped with a servlet mapped tothe given path or null if no mapping was found.
 */
RequestDispatcher getRequestDispatcher(String path){
  final String newRequestUri=path;
  for (  final ServletDefinition servletDefinition : servletDefinitions) {
    if (servletDefinition.shouldServe(path)) {
      return new RequestDispatcher(){
        public void forward(        ServletRequest servletRequest,        ServletResponse servletResponse) throws ServletException, IOException {
          Preconditions.checkState(!servletResponse.isCommitted(),"Response has been committed--you can only call forward before" + " committing the response (hint: don't flush buffers)");
          servletResponse.resetBuffer();
          ServletRequest requestToProcess;
          if (servletRequest instanceof HttpServletRequest) {
            requestToProcess=new RequestDispatcherRequestWrapper(servletRequest,newRequestUri);
          }
 else {
            requestToProcess=servletRequest;
          }
          doServiceImpl(servletDefinition,requestToProcess,servletResponse);
        }
        public void include(        ServletRequest servletRequest,        ServletResponse servletResponse) throws ServletException, IOException {
          doServiceImpl(servletDefinition,servletRequest,servletResponse);
        }
        private void doServiceImpl(        ServletDefinition servletDefinition,        ServletRequest servletRequest,        ServletResponse servletResponse) throws ServletException, IOException {
          servletRequest.setAttribute(REQUEST_DISPATCHER_REQUEST,Boolean.TRUE);
          try {
            servletDefinition.doService(servletRequest,servletResponse);
          }
  finally {
            servletRequest.removeAttribute(REQUEST_DISPATCHER_REQUEST);
          }
        }
      }
;
    }
  }
  return null;
}
 

Example 8

From project 3Dto2DApplet, under directory /src/java/nl/dannyarends/www/http/.

Source file: Webserver.java

  15 
vote

public void forward(ServletRequest _request,ServletResponse _response) throws ServletException, java.io.IOException {
  _request.removeAttribute("javax.servlet.forward.request_uri");
  _response.reset();
  servlet.service(new HttpServletRequestWrapper((HttpServletRequest)_request){
    public java.lang.String getPathInfo(){
      return dispatchLen >= dispatchPath.length() ? null : dispatchPath.substring(dispatchLen);
    }
    public String getRequestURI(){
      return dispatchPath;
    }
    public String getQueryString(){
      return dispatchQuery;
    }
    public String getPathTranslated(){
      ServletContext context=((HttpServletRequest)getRequest()).getSession().getServletContext();
      return context.getRealPath(((HttpServletRequest)getRequest()).getContextPath());
    }
    public String getServletPath(){
      return dispatchLen <= 0 ? "" : dispatchPath.substring(0,dispatchLen);
    }
    public synchronized Enumeration<?> getAttributeNames(){
      if (super.getAttribute("javax.servlet.forward.request_uri") == null) {
        setAttribute("javax.servlet.forward.request_uri",super.getRequestURI());
        setAttribute("javax.servlet.forward.context_path",this.getContextPath());
        setAttribute("javax.servlet.forward.servlet_path",super.getServletPath());
        setAttribute("javax.servlet.forward.path_info",super.getPathInfo());
        setAttribute("javax.servlet.forward.query_string",super.getQueryString());
      }
      return super.getAttributeNames();
    }
    public Object getAttribute(    String name){
      getAttributeNames();
      return super.getAttribute(name);
    }
  }
,_response);
}
 

Example 9

From project accesointeligente, under directory /src/org/accesointeligente/server/.

Source file: GWTCacheControlFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain filterChain) throws IOException, ServletException {
  HttpServletRequest httpRequest=(HttpServletRequest)request;
  String requestURI=httpRequest.getRequestURI();
  if (requestURI.contains(".nocache.")) {
    Date now=new Date();
    HttpServletResponse httpResponse=(HttpServletResponse)response;
    httpResponse.setDateHeader("Date",now.getTime());
    httpResponse.setDateHeader("Expires",now.getTime() - 86400000L);
    httpResponse.setHeader("Pragma","no-cache");
    httpResponse.setHeader("Cache-control","no-cache, no-store, must-revalidate");
  }
  filterChain.doFilter(request,response);
}
 

Example 10

From project AdServing, under directory /modules/server/adserver/src/main/java/net/mad/ads/server/utils/http/listener/.

Source file: AdContextListener.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest req=(HttpServletRequest)request;
  HttpServletResponse res=(HttpServletResponse)response;
  AdContext context=AdContextHelper.getAdContext(req,res);
  ADCONTEXT.set(context);
  chain.doFilter(request,response);
  ADCONTEXT.remove();
}
 

Example 11

From project aio-webos, under directory /webui/webos/src/main/java/org/exoplatform/webos/common/filter/.

Source file: LazyDesktopPageCreation.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest httpRequest=(HttpServletRequest)request;
  String userName=httpRequest.getRemoteUser();
  try {
    ExoContainer container=ExoContainerContext.getCurrentContainer();
    RequestLifeCycle.begin(container);
    if (userName != null) {
      try {
        Class.forName(UIDesktopPage.class.getName());
      }
 catch (      ClassNotFoundException e) {
        throw new ServletException(e);
      }
      createPortalConfig(container,userName);
      createUserPage(container,userName);
    }
  }
 catch (  Throwable t) {
    log.debug("Could not create User Portal Config or User Desktop Page for " + userName,t);
  }
 finally {
    chain.doFilter(httpRequest,response);
    RequestLifeCycle.end();
  }
}
 

Example 12

From project airlift, under directory /http-server/src/main/java/io/airlift/http/server/.

Source file: GZipRequestFilter.java

  15 
vote

public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain filterChain) throws IOException, ServletException {
  HttpServletRequest request=(HttpServletRequest)servletRequest;
  HttpServletResponse response=(HttpServletResponse)servletResponse;
  String contentEncoding=request.getHeader("content-encoding");
  if (equalsIgnoreCase(contentEncoding,"gzip")) {
    filterChain.doFilter(new GZipRequestWrapper(request),servletResponse);
  }
 else {
    filterChain.doFilter(request,response);
  }
}
 

Example 13

From project ajah, under directory /ajah-servlet/src/main/java/com/ajah/servlet/filter/.

Source file: JSONPFilter.java

  15 
vote

/** 
 * Wraps a JSON response with a JSONP callback, if possible and appropriate.
 * @see com.ajah.servlet.filter.BaseFilter#doFilter(javax.servlet.ServletRequest,javax.servlet.ServletResponse,javax.servlet.FilterChain)
 */
@Override public void doFilter(final ServletRequest request,final ServletResponse response,final FilterChain chain) throws IOException, ServletException {
  final String callback=request.getParameter("callback");
  if (StringUtils.isBlank(callback)) {
    log.finest("Not adding callback, no \"callback\" parameter specified");
    chain.doFilter(request,response);
    return;
  }
  final OutputStream out=response.getOutputStream();
  final GenericResponseWrapper wrapper=new GenericResponseWrapper((HttpServletResponse)response);
  chain.doFilter(request,wrapper);
  if ("application/json".equals(wrapper.getContentType()) || "jsonp".equals(request.getParameter("format"))) {
    if (log.isLoggable(Level.FINEST)) {
      log.finest("Adding callback \"" + callback + "\" to  "+ wrapper.getData().length+ " bytes");
    }
    out.write(callback.getBytes());
    out.write('(');
    out.write(wrapper.getData());
    out.write(");".getBytes());
  }
 else {
    if (log.isLoggable(Level.FINEST)) {
      log.finest("Not adding callback, response is not JSON (" + wrapper.getContentType() + ")");
    }
    out.write(wrapper.getData());
  }
  out.close();
}
 

Example 14

From project alfredo, under directory /alfredo/src/test/java/com/cloudera/alfredo/server/.

Source file: TestAuthenticationFilter.java

  15 
vote

public void testDoFilterNotAuthenticated() throws Exception {
  AuthenticationFilter filter=new AuthenticationFilter();
  try {
    FilterConfig config=Mockito.mock(FilterConfig.class);
    Mockito.when(config.getInitParameter(AuthenticationFilter.AUTH_TYPE)).thenReturn(DummyAuthenticationHandler.class.getName());
    Mockito.when(config.getInitParameterNames()).thenReturn(new Vector(Arrays.asList(AuthenticationFilter.AUTH_TYPE)).elements());
    filter.init(config);
    HttpServletRequest request=Mockito.mock(HttpServletRequest.class);
    Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://foo:8080/bar"));
    HttpServletResponse response=Mockito.mock(HttpServletResponse.class);
    FilterChain chain=Mockito.mock(FilterChain.class);
    Mockito.doAnswer(new Answer(){
      @Override public Object answer(      InvocationOnMock invocation) throws Throwable {
        fail();
        return null;
      }
    }
).when(chain).doFilter(Mockito.<ServletRequest>anyObject(),Mockito.<ServletResponse>anyObject());
    filter.doFilter(request,response,chain);
    Mockito.verify(response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
  }
  finally {
    filter.destroy();
  }
}
 

Example 15

From project alphaportal_dev, under directory /sys-src/alphaportal/web/src/test/java/alpha/portal/webapp/filter/.

Source file: MockFilterChain.java

  15 
vote

public void doFilter(final ServletRequest request,final ServletResponse response) throws IOException, ServletException {
  String uri=((HttpServletRequest)request).getRequestURI();
  final String requestContext=((HttpServletRequest)request).getContextPath();
  if (StringUtils.isNotEmpty(requestContext) && uri.startsWith(requestContext)) {
    uri=uri.substring(requestContext.length());
  }
  this.forwardURL=uri;
  this.log.debug("Forwarding to: " + uri);
  final RequestDispatcher dispatcher=request.getRequestDispatcher(uri);
  dispatcher.forward(request,response);
}
 

Example 16

From project arquillian-container-weld, under directory /weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/mock/.

Source file: MockServletContext.java

  15 
vote

/** 
 * Wicket does not use the RequestDispatcher, so this implementation just returns a dummy value.
 * @param name The name of the resource to get the dispatcher for
 * @return The dispatcher
 */
public RequestDispatcher getRequestDispatcher(final String name){
  return new RequestDispatcher(){
    public void forward(    ServletRequest servletRequest,    ServletResponse servletResponse) throws IOException {
      servletResponse.getWriter().write("FORWARD TO RESOURCE: " + name);
    }
    public void include(    ServletRequest servletRequest,    ServletResponse servletResponse) throws IOException {
      servletResponse.getWriter().write("INCLUDE OF RESOURCE: " + name);
    }
  }
;
}
 

Example 17

From project arquillian-extension-warp, under directory /impl/src/main/java/org/jboss/arquillian/warp/impl/server/execution/.

Source file: WarpFilter.java

  15 
vote

/** 
 * Detects whenever the request is HTTP request and if yes, delegates to {@link #doFilterHttp(HttpServletRequest,HttpServletResponse,FilterChain)}.
 */
@Override public void doFilter(ServletRequest req,ServletResponse resp,final FilterChain chain) throws IOException, ServletException {
  if (req instanceof HttpServletRequest && resp instanceof HttpServletResponse) {
    doFilterHttp((HttpServletRequest)req,(HttpServletResponse)resp,chain);
  }
 else {
    chain.doFilter(req,resp);
  }
}
 

Example 18

From project arquillian-weld-embedded-1.1, under directory /src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/mock/.

Source file: MockServletContext.java

  15 
vote

/** 
 * Wicket does not use the RequestDispatcher, so this implementation just returns a dummy value.
 * @param name The name of the resource to get the dispatcher for
 * @return The dispatcher
 */
public RequestDispatcher getRequestDispatcher(final String name){
  return new RequestDispatcher(){
    public void forward(    ServletRequest servletRequest,    ServletResponse servletResponse) throws IOException {
      servletResponse.getWriter().write("FORWARD TO RESOURCE: " + name);
    }
    public void include(    ServletRequest servletRequest,    ServletResponse servletResponse) throws IOException {
      servletResponse.getWriter().write("INCLUDE OF RESOURCE: " + name);
    }
  }
;
}
 

Example 19

From project arquillian_deprecated, under directory /containers/weld-ee-embedded-1.1/src/main/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/mock/.

Source file: MockServletContext.java

  15 
vote

/** 
 * Wicket does not use the RequestDispatcher, so this implementation just returns a dummy value.
 * @param name The name of the resource to get the dispatcher for
 * @return The dispatcher
 */
public RequestDispatcher getRequestDispatcher(final String name){
  return new RequestDispatcher(){
    public void forward(    ServletRequest servletRequest,    ServletResponse servletResponse) throws IOException {
      servletResponse.getWriter().write("FORWARD TO RESOURCE: " + name);
    }
    public void include(    ServletRequest servletRequest,    ServletResponse servletResponse) throws IOException {
      servletResponse.getWriter().write("INCLUDE OF RESOURCE: " + name);
    }
  }
;
}
 

Example 20

From project azure-sdk-for-java-samples, under directory /WAAD.WebSSO.JAVA/java/code/samples/sample/src/main/java/.

Source file: FederationFilter.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (request instanceof HttpServletRequest) {
    HttpServletRequest httpRequest=(HttpServletRequest)request;
    if (!httpRequest.getRequestURL().toString().contains(this.loginPage)) {
      ConfigurableFederatedLoginManager loginManager=ConfigurableFederatedLoginManager.fromRequest(httpRequest);
      boolean allowedUrl=Pattern.compile(this.allowedRegex).matcher(httpRequest.getRequestURL().toString()).find();
      if (!allowedUrl && !loginManager.isAuthenticated()) {
        HttpServletResponse httpResponse=(HttpServletResponse)response;
        String encodedReturnUrl=URLUTF8Encoder.encode(httpRequest.getRequestURL().toString());
        httpResponse.setHeader("Location",this.loginPage + "?returnUrl=" + encodedReturnUrl);
        httpResponse.setStatus(302);
        return;
      }
    }
  }
  chain.doFilter(request,response);
}
 

Example 21

From project azure4j-blog-samples, under directory /ACSExample/src/com/persistent/azure/acs/filter/.

Source file: AuthorizationFilter.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest httpServletRequest=(HttpServletRequest)request;
  HttpServletResponse httpServletResponse=(HttpServletResponse)response;
  String acsToken=httpServletRequest.getParameter("wresult");
  if (null != acsToken && acsToken.trim().length() == 0) {
    acsToken=null;
  }
  if (!(httpServletRequest.getRequestURI().contains("claims.do") && acsToken != null)) {
    Cookie[] cookies=httpServletRequest.getCookies();
    Cookie currentCookie=null;
    String cookieName=resourceBundle.getString("acs.cookie.name");
    if (cookies != null && cookies.length > 0) {
      for (      Cookie c : cookies) {
        if (cookieName.equals(c.getName())) {
          currentCookie=c;
          break;
        }
      }
    }
    if (currentCookie == null) {
      StringBuffer loginURL=new StringBuffer();
      loginURL.append(resourceBundle.getString("acs.url"));
      loginURL.append("/v2/wsfederation?wa=wsignin1.0&wtrealm=");
      loginURL.append(resourceBundle.getString("acs.realm"));
      httpServletResponse.sendRedirect(loginURL.toString());
    }
 else {
      chain.doFilter(request,response);
    }
  }
 else {
    chain.doFilter(request,response);
  }
}
 

Example 22

From project b3log-latke, under directory /latke/src/main/java/org/b3log/latke/servlet/filter/.

Source file: AbstractGZIPFilter.java

  15 
vote

/** 
 * Wraps the http servlet response with GZIP if could.
 * @param request the specified request
 * @param response the specified response
 * @param chain filter chain
 * @throws IOException io exception
 * @throws ServletException servlet exception
 */
@Override public void doFilter(final ServletRequest request,final ServletResponse response,final FilterChain chain) throws IOException, ServletException {
  final HttpServletRequest httpServletRequest=(HttpServletRequest)request;
  final String requestURI=httpServletRequest.getRequestURI();
  if (shouldSkip(requestURI)) {
    LOGGER.log(Level.FINEST,"Skip GZIP filter request[URI={0}]",requestURI);
    chain.doFilter(request,response);
    return;
  }
  final String acceptEncoding=httpServletRequest.getHeader("Accept-Encoding");
  boolean supportGZIP=false;
  if (null != acceptEncoding && 0 <= acceptEncoding.indexOf("gzip")) {
    supportGZIP=true;
  }
  if (!supportGZIP) {
    LOGGER.info("Gzip NOT be supported");
    chain.doFilter(request,response);
    return;
  }
  final HttpServletResponse httpServletResponse=(HttpServletResponse)response;
  httpServletResponse.addHeader("Content-Encoding","gzip");
  httpServletResponse.addHeader("Vary","Accept-Encoding");
  chain.doFilter(request,new GZIPServletResponseWrapper(httpServletResponse));
}
 

Example 23

From project b3log-solo, under directory /core/src/main/java/org/b3log/solo/filter/.

Source file: AuthFilter.java

  15 
vote

/** 
 * If the specified request is NOT made by an authenticated user, sends  error 403.
 * @param request the specified request
 * @param response the specified response
 * @param chain filter chain
 * @throws IOException io exception
 * @throws ServletException servlet exception
 */
@Override public void doFilter(final ServletRequest request,final ServletResponse response,final FilterChain chain) throws IOException, ServletException {
  final HttpServletResponse httpServletResponse=(HttpServletResponse)response;
  final HttpServletRequest httpServletRequest=(HttpServletRequest)request;
  try {
    LoginProcessor.tryLogInWithCookie(httpServletRequest,httpServletResponse);
    final GeneralUser currentUser=userService.getCurrentUser(httpServletRequest);
    if (null == currentUser) {
      LOGGER.warning("The request has been forbidden");
      httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
      return;
    }
    final String currentUserEmail=currentUser.getEmail();
    LOGGER.log(Level.FINER,"Current user email[{0}]",currentUserEmail);
    if (users.isSoloUser(currentUserEmail)) {
      chain.doFilter(request,response);
      return;
    }
    LOGGER.warning("The request has been forbidden");
    httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
  }
 catch (  final Exception e) {
    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
  }
}
 

Example 24

From project CalendarPortlet, under directory /src/main/java/org/jasig/portlet/calendar/mvc/.

Source file: AggregationAwareFilterBean.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (this.elementsProvider.getIncludedType((HttpServletRequest)request) == Included.AGGREGATED) {
    if (logger.isDebugEnabled()) {
      logger.debug("Aggregation enabled, delegating to filter: " + this.filter);
    }
    this.filter.doFilter(request,response,chain);
  }
 else {
    if (logger.isDebugEnabled()) {
      logger.debug("Aggregation disabled, skipping filter: " + this.filter);
    }
    chain.doFilter(request,response);
  }
}
 

Example 25

From project CampusLifePortlets, under directory /src/main/java/org/jasig/portlet/campuslife/mvc/.

Source file: AggregationAwareFilterBean.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (this.elementsProvider.getIncludedType((HttpServletRequest)request) == Included.AGGREGATED) {
    if (logger.isDebugEnabled()) {
      logger.debug("Aggregation enabled, delegating to filter: " + this.filter);
    }
    this.filter.doFilter(request,response,chain);
  }
 else {
    if (logger.isDebugEnabled()) {
      logger.debug("Aggregation disabled, skipping filter: " + this.filter);
    }
    chain.doFilter(request,response);
  }
}
 

Example 26

From project Carolina-Digital-Repository, under directory /access-security/src/main/java/edu/unc/lib/dl/security/access/.

Source file: SpoofShibbolethHeadersFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (request instanceof HttpServletRequest) {
    String members=(String)((HttpServletRequest)request).getHeader("isMemberOf");
    LOG.debug("Unspoofed isMemberOf: " + members);
    if (!(((HttpServletRequest)request).getServletPath().startsWith("/js/") || ((HttpServletRequest)request).getServletPath().startsWith("/css/") || ((HttpServletRequest)request).getServletPath().startsWith("/images/"))) {
      request=new javax.servlet.http.HttpServletRequestWrapper((HttpServletRequest)request){
        @Override public String getHeader(        String name){
          if ("isMemberOf".equals(name)) {
            return isMemberOfHeader;
          }
 else {
            return super.getHeader(name);
          }
        }
        @Override public String getRemoteUser(){
          return remoteUser;
        }
      }
;
      LOG.warn("SpoofShibbolethHeadersFilter: remoteUser = " + remoteUser);
      LOG.warn("SpoofShibbolethHeadersFilter: isMemberOf header = " + isMemberOfHeader);
    }
    chain.doFilter(request,response);
  }
 else {
    throw new RuntimeException("Not an HTTP request.");
  }
}
 

Example 27

From project cloudbees-api-client, under directory /cloudbees-api-client/src/test/java/com/cloudbees/api/util/.

Source file: ProxyServer.java

  15 
vote

public void service(ServletRequest req,ServletResponse res) throws ServletException, IOException {
  final HttpServletRequest request=(HttpServletRequest)req;
  final HttpServletResponse response=(HttpServletResponse)res;
  requestsReceived++;
  if (this.authentications != null && !this.authentications.isEmpty()) {
    String proxyAuthorization=request.getHeader("Proxy-Authorization");
    if (proxyAuthorization != null && proxyAuthorization.startsWith("Basic ")) {
      String proxyAuth=proxyAuthorization.substring(6);
      String authorization=B64Code.decode(proxyAuth);
      String[] authTokens=authorization.split(":");
      String user=authTokens[0];
      String password=authTokens[1];
      if (this.authentications.get(user) == null) {
        throw new IllegalArgumentException(user + " not found in the map!");
      }
      if (sleepTime > 0) {
        try {
          Thread.sleep(sleepTime);
        }
 catch (        InterruptedException e) {
        }
      }
      String authPass=this.authentications.get(user).toString();
      if (password.equals(authPass)) {
        super.service(req,res);
        return;
      }
    }
    response.addHeader("Proxy-Authenticate","Basic realm=\"Jetty Proxy Authorization\"");
    response.setStatus(HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED);
    return;
  }
  super.service(req,res);
}
 

Example 28

From project Coffee-Framework, under directory /coffeeframework-core/src/main/java/coffee/.

Source file: Cafeteria.java

  15 
vote

public static CoffeeRequestContext createRequestContext(ServletRequest request,ServletResponse response,ServletContext servletContext){
  HttpServletRequest httpRequest=(HttpServletRequest)request;
  CoffeeRequestContext context=new CoffeeRequestContext();
  context.setRequest(request);
  context.setResponse(response);
  context.setServletContext(servletContext);
  if (servletContext != null) {
    CoffeeApplicationContext applicationContext=getOrCreateApplicationContext(servletContext);
    context.setApplicationContext(applicationContext);
    context.setRegisteredTagLibs(applicationContext.getRegisteredTagLibs());
  }
  if (httpRequest != null) {
    context.put("contextPath",httpRequest.getContextPath());
    context.put("path",httpRequest.getRequestURI());
  }
  return context;
}
 

Example 29

From project com.idega.content, under directory /src/java/com/idega/content/filter/.

Source file: ContentDispatcher.java

  15 
vote

public void doFilter(ServletRequest srequest,ServletResponse sresponse,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest request=(HttpServletRequest)srequest;
  String jackrabbitBasePath="/repository/default";
  if (contentRepository.equals(CONTENT_REPOSITORY_JACKRABBIT)) {
    String url=getURIMinusContextPath(request);
    String newUrl=jackrabbitBasePath + url;
    RequestDispatcher dispatcher=request.getRequestDispatcher(newUrl);
    dispatcher.include(srequest,sresponse);
  }
 else {
    chain.doFilter(srequest,sresponse);
  }
}
 

Example 30

From project cometd, under directory /cometd-java/cometd-java-server/src/test/java/org/cometd/server/.

Source file: SlowConnectionTest.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  try {
    chain.doFilter(request,response);
  }
 catch (  EofException x) {
    exceptionLatch.countDown();
    throw x;
  }
}
 

Example 31

From project components, under directory /soap/src/main/java/org/switchyard/component/soap/composer/.

Source file: SOAPBindingData.java

  15 
vote

private ServletRequest getServletRequest(){
  if (_webServiceContext != null) {
    return (ServletRequest)_webServiceContext.getMessageContext().get(MessageContext.SERVLET_REQUEST);
  }
  return null;
}
 

Example 32

From project components-ness-tracking, under directory /src/main/java/com/nesscomputing/tracking/.

Source file: TrackingFilter.java

  15 
vote

@Override public void doFilter(@Nonnull ServletRequest request,@Nonnull ServletResponse response,@Nonnull FilterChain chain) throws IOException, ServletException {
  final HttpServletRequest req=(HttpServletRequest)request;
  final HttpServletResponse res=(HttpServletResponse)response;
  try {
    if (request.getAttribute(ThreadDelegatingScopeFilter.THREAD_DELEGATING_SCOPE_ACTIVE) == null) {
      LOG.warn("Called the tracking filter before the ThreadDelegatingScopeFilter. Tracking will not work. You need to reshuffle your guice modules to bind the filters in the right order!");
    }
 else {
      final TrackingToken trackingToken=scopedProvider.get();
      final UUID trackingUUID=trackingTokenProvider.get(new ServletApiAdapter(req));
      trackingToken.setValue(trackingUUID);
      if (trackingUUID != null) {
        request.setAttribute(X_NESS_TRACK,trackingUUID);
        res.setHeader(X_NESS_TRACK,trackingUUID.toString());
      }
    }
  }
  finally {
    chain.doFilter(request,response);
  }
}
 

Example 33

From project ConferenceProgramPortlet, under directory /src/main/java/org/jasig/portlet/conference/program/mvc/.

Source file: AggregationAwareFilterBean.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (this.elementsProvider.getIncludedType((HttpServletRequest)request) == Included.AGGREGATED) {
    if (logger.isDebugEnabled()) {
      logger.debug("Aggregation enabled, delegating to filter: " + this.filter);
    }
    this.filter.doFilter(request,response,chain);
  }
 else {
    if (logger.isDebugEnabled()) {
      logger.debug("Aggregation disabled, skipping filter: " + this.filter);
    }
    chain.doFilter(request,response);
  }
}
 

Example 34

From project conversation, under directory /spi/src/test/java/org/jboss/seam/conversation/support/.

Source file: RealTestFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  String cid=request.getParameter("cid");
  System.err.println("Testing ..." + cid + ", sessionId = "+ ((HttpServletRequest)request).getSession().getId());
  Assert.assertNotNull(bean);
  Conversation conversation=bean.getConversation();
  Assert.assertNotNull(conversation);
  if (cid == null) {
    conversation.begin(cId);
  }
 else {
    Assert.assertEquals(cId,conversation.getId());
  }
  try {
    chain.doFilter(request,response);
  }
  finally {
    if (cid != null)     conversation.end();
  }
}
 

Example 35

From project core_1, under directory /security/src/main/java/org/switchyard/security/credential/extract/.

Source file: ServletRequestCredentialsExtractor.java

  15 
vote

/** 
 * {@inheritDoc}
 */
@Override public Set<Credential> extractCredentials(ServletRequest source){
  Set<Credential> credentials=new HashSet<Credential>();
  if (source != null) {
    credentials.add(new ConfidentialityCredential(source.isSecure()));
    if (source instanceof HttpServletRequest) {
      HttpServletRequest request=(HttpServletRequest)source;
      Principal userPrincipal=request.getUserPrincipal();
      if (userPrincipal != null) {
        credentials.add(new PrincipalCredential(userPrincipal,true));
      }
      String remoteUser=request.getRemoteUser();
      if (remoteUser != null) {
        credentials.add(new PrincipalCredential(new User(remoteUser),true));
      }
      String charsetName=source.getCharacterEncoding();
      AuthorizationHeaderCredentialsExtractor ahce;
      if (charsetName != null) {
        ahce=new AuthorizationHeaderCredentialsExtractor(charsetName);
      }
 else {
        ahce=new AuthorizationHeaderCredentialsExtractor();
      }
      credentials.addAll(ahce.extractCredentials(request.getHeader("Authorization")));
    }
  }
  return credentials;
}
 

Example 36

From project core_4, under directory /impl/src/main/java/org/richfaces/webapp/.

Source file: PushFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
    HttpServletRequest httpReq=(HttpServletRequest)request;
    HttpServletResponse httpResp=(HttpServletResponse)response;
    if ("GET".equals(httpReq.getMethod()) && httpReq.getQueryString() != null && httpReq.getQueryString().contains("__richfacesPushAsync")) {
      if (pushServlet == null) {
        pushServlet=new PushServlet();
        pushServlet.init(servletConfig);
      }
      pushServlet.doGet(httpReq,httpResp);
      return;
    }
  }
  chain.doFilter(request,response);
}
 

Example 37

From project core_5, under directory /exo.core.component.security.core/src/main/java/org/exoplatform/services/security/j2ee/websphere/.

Source file: WebsphereFilter.java

  15 
vote

/** 
 * Do filter. Remove ltpa token cookie when we are going on public context, nothing to do otherwise.
 */
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest httpRequest=(HttpServletRequest)request;
  HttpServletResponse httpResponse=(HttpServletResponse)response;
  if (httpRequest.getQueryString() == null && httpRequest.getRequestURI() != null && httpRequest.getRequestURI().contains("/public")) {
    removeLtpaTokenCookie(httpRequest,httpResponse);
  }
 else   if (httpRequest.getQueryString() != null && httpRequest.getQueryString().contains("UIPortalComponentLogin") && httpRequest.getRequestURI() != null && httpRequest.getRequestURI().contains("/public")) {
    removeLtpaTokenCookie(httpRequest,httpResponse);
  }
  chain.doFilter(request,response);
}
 

Example 38

From project Cours-3eme-ann-e, under directory /Java/tomcat/examples/WEB-INF/classes/filters/.

Source file: ExampleFilter.java

  15 
vote

/** 
 * Time the processing that is performed by all subsequent filters in the current filter stack, including the ultimately invoked servlet.
 * @param request The servlet request we are processing
 * @param result The servlet response we are creating
 * @param chain The filter chain we are processing
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet error occurs
 */
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (attribute != null)   request.setAttribute(attribute,this);
  long startTime=System.currentTimeMillis();
  chain.doFilter(request,response);
  long stopTime=System.currentTimeMillis();
  filterConfig.getServletContext().log(this.toString() + ": " + (stopTime - startTime)+ " milliseconds");
}
 

Example 39

From project cxf-dosgi, under directory /dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/.

Source file: SecurityDelegatingHttpContext.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response) throws IOException, ServletException {
  if (current < filters.length && !response.isCommitted()) {
    Filter filter=filters[current++];
    LOG.info("doFilter() on " + filter);
    filter.doFilter(request,response,this);
  }
}
 

Example 40

From project demoiselle-contrib, under directory /demoiselle-fuselage/src/main/java/br/gov/frameworkdemoiselle/fuselage/filter/.

Source file: AuthorizerURL.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (!config.isWebfilterEnabled()) {
    chain.doFilter(request,response);
    return;
  }
  this.request=(HttpServletRequest)request;
  String url=this.request.getRequestURI().replaceAll("^/.+?/","/");
  if (isPublicURL(url) || hasPermission(url))   chain.doFilter(request,response);
 else   redirect(response,getContext() + config.getLoginPage());
}
 

Example 41

From project dev-examples, under directory /misc-demo/src/main/java/org/richfaces/demo/.

Source file: TestIdentityFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequestWrapper wrapper=new HttpServletRequestWrapper((HttpServletRequest)request){
    private UserBean getUserBean(){
      HttpSession session=getSession(false);
      if (session != null) {
        return (UserBean)session.getAttribute("userBean");
      }
      return null;
    }
    @Override public boolean isUserInRole(    String role){
      UserBean userBean=getUserBean();
      if (userBean != null) {
        return userBean.isUserInRole(role);
      }
      return false;
    }
    @Override public Principal getUserPrincipal(){
      UserBean userBean=getUserBean();
      if (userBean != null) {
        return userBean.getPrincipal();
      }
      return null;
    }
    @Override public String getRemoteUser(){
      UserBean userBean=getUserBean();
      if (userBean != null) {
        return userBean.getRolename();
      }
      return null;
    }
  }
;
  chain.doFilter(wrapper,response);
}
 

Example 42

From project dolphin, under directory /dolphinmaple/src/com/tan/filter/.

Source file: EncodingFilter.java

  15 
vote

public final void doFilter(ServletRequest req,ServletResponse res,FilterChain chain) throws IOException, ServletException {
  if (encoding != null) {
    req.setCharacterEncoding(encoding);
  }
  chain.doFilter(req,res);
}
 

Example 43

From project EasySOA, under directory /easysoa-registry/easysoa-registry-rest-miner/src/main/java/org/easysoa/records/filters/.

Source file: ExchangeRecordServletFilterImpl.java

  15 
vote

/** 
 * Process the filter 
 */
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (exchangeHandler != null) {
    logger.info("Filtering a EasySOA API request");
    if (!(request instanceof CopyHttpServletResponse)) {
      request=new CopyHttpServletRequest((HttpServletRequest)request);
    }
    if (!(response instanceof CopyHttpServletResponse)) {
      response=new CopyHttpServletResponse((HttpServletResponse)response);
    }
  }
  chain.doFilter(request,response);
  if (exchangeHandler != null) {
    if (request instanceof HttpServletRequest) {
      try {
        InMessage inMessage=new InMessage((CopyHttpServletRequest)request);
        OutMessage outMessage=new OutMessage((CopyHttpServletResponse)response);
        this.exchangeHandler.handleMessage(inMessage,outMessage);
      }
 catch (      Exception e) {
        logger.error("An error occurred during the exchange handling",e);
      }
    }
  }
}
 

Example 44

From project egov-data, under directory /easyCompany2/src/main/java/egovframework/rte/tex/com/.

Source file: EgovAccessDeniedHandlerImpl.java

  15 
vote

public void handle(ServletRequest request,ServletResponse response,AccessDeniedException accessDeniedException) throws IOException, ServletException {
  if (errorPage != null) {
    ((HttpServletRequest)request).setAttribute(SPRING_SECURITY_ACCESS_DENIED_EXCEPTION_KEY,accessDeniedException);
    ((HttpServletResponse)response).sendRedirect(errorPage);
  }
  if (!response.isCommitted()) {
    ((HttpServletResponse)response).sendError(HttpServletResponse.SC_FORBIDDEN,accessDeniedException.getMessage());
  }
}
 

Example 45

From project exo-training, under directory /gxt-showcase/src/main/java/com/sencha/gxt/examples/resources/server/.

Source file: EntityManagerFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  EntityManager em=null;
  try {
    em=factory.createEntityManager();
    EntityManagerUtil.MANAGERS.set(em);
    chain.doFilter(request,response);
    EntityManagerUtil.MANAGERS.remove();
  }
  finally {
    try {
      if (em != null)       em.close();
    }
 catch (    Throwable t) {
      t.printStackTrace();
    }
  }
}
 

Example 46

From project Extlet6, under directory /liferay-6.0.5-patch/portal-impl/src/com/liferay/portal/struts/.

Source file: PortalTilesDefinitionsFactory.java

  15 
vote

/** 
 * Extract key that will be used to get the sub factory.
 * @param name Name of requested definition
 * @param request Current servlet request.
 * @param servletContext Current servlet context.
 * @return the key or <code>null</code> if not found.
 */
protected Object getDefinitionsFactoryKey(String name,ServletRequest request,ServletContext servletContext){
  Locale locale=null;
  try {
    HttpSession session=((HttpServletRequest)request).getSession(false);
    if (session != null) {
      locale=(Locale)session.getAttribute(ComponentConstants.LOCALE_KEY);
    }
  }
 catch (  ClassCastException ex) {
    log.error("I18nFactorySet.getDefinitionsFactoryKey");
    ex.printStackTrace();
  }
  return locale;
}
 

Example 47

From project flatpack-java, under directory /demo-server/src/main/java/com/getperka/flatpack/demo/server/.

Source file: DummyAuthenticator.java

  15 
vote

@Override public Authentication validateRequest(ServletRequest request,ServletResponse response,boolean mandatory) throws ServerAuthException {
  HttpServletRequest req=(HttpServletRequest)request;
  DummyPrincipal principal;
  if (req.getParameter("isAdmin") != null) {
    principal=new DummyPrincipal("Hacker T. Admin",Roles.ADMIN);
  }
 else {
    principal=DummyPrincipal.NOBODY;
  }
  return new UserAuthentication(getAuthMethod(),new DefaultUserIdentity(null,principal,new String[]{principal.getRole()}));
}
 

Example 48

From project flip, under directory /servlet/src/main/java/com/tacitknowledge/flip/servlet/.

Source file: FlipOverrideFilter.java

  15 
vote

/** 
 * The method which uses the request parameters and apply them into the session attribute  {@link #SESSION_FEATURES_KEY}. This session attribute holds the map  {@link FeatureDescriptorsMap}. The method do not creates the session. So if the session do not exists then the request parameters will be ignored. If in the session under key  {@link #SESSION_FEATURES_KEY} persists the object other than of type  {@link FeatureDescriptorsMap} or there isno object in the session then the new object will be created and stored there. 
 * @param request the request to process 
 */
private void applyFeaturesFromRequestParameters(final ServletRequest request){
  final HttpServletRequest httpRequest=(HttpServletRequest)request;
  final HttpSession session=httpRequest.getSession(false);
  FeatureDescriptorsMap featureDescriptors;
  if (session != null) {
    featureDescriptors=getSafeSessionFeatures(session);
    session.setAttribute(SESSION_FEATURES_KEY,featureDescriptors);
  }
 else {
    featureDescriptors=new FeatureDescriptorsMap();
  }
  applyRequestFeaturesToFeatureDescriptorsMap(request,featureDescriptors);
  FlipWebContext.setFeatureDescriptors(featureDescriptors);
}
 

Example 49

From project gatein-sso, under directory /agent/src/main/java/org/gatein/sso/agent/filter/.

Source file: AbstractLogoutFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest httpRequest=(HttpServletRequest)request;
  HttpServletResponse httpResponse=(HttpServletResponse)response;
  boolean isLogoutInProgress=this.isLogoutInProgress(httpRequest);
  if (isLogoutInProgress) {
    if (httpRequest.getSession().getAttribute("SSO_LOGOUT_FLAG") == null) {
      httpRequest.getSession().setAttribute("SSO_LOGOUT_FLAG",Boolean.TRUE);
      String redirectUrl=this.getRedirectUrl(httpRequest);
      redirectUrl=httpResponse.encodeRedirectURL(redirectUrl);
      httpResponse.sendRedirect(redirectUrl);
      return;
    }
 else {
      httpRequest.getSession().removeAttribute("SSO_LOGOUT_FLAG");
    }
  }
  chain.doFilter(request,response);
}
 

Example 50

From project gatein-toolbox, under directory /CoreOrganizationInitializer/src/main/java/org/exoplatform/core/component/organization/initializer/.

Source file: TriggerInitializerFilter.java

  15 
vote

public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain filterChain) throws IOException, ServletException {
  if (log.isTraceEnabled()) {
    log.trace("filter in progress. checkFolders=" + checkFolders + ", TriggerListenersForGroups="+ triggerListenersForGroups);
  }
  HttpServletRequest httpServletRequest=(HttpServletRequest)servletRequest;
  if (httpServletRequest.getRemoteUser() != null && httpServletRequest.getSession().getAttribute(ATTR_FLAG_NAME) == null) {
    ExoContainer container=ExoContainerContext.getCurrentContainer();
    OrganizationListenersInitializerService initializer=(OrganizationListenersInitializerService)container.getComponentInstanceOfType(OrganizationListenersInitializerService.class);
    OrganizationService orgService=(OrganizationService)container.getComponentInstanceOfType(OrganizationService.class);
    RequestLifeCycle.begin(container);
    try {
      String username=httpServletRequest.getRemoteUser();
      User user=orgService.getUserHandler().findUserByName(username);
      initializer.treatUser(user,checkFolders);
      if (triggerListenersForGroups) {
        Collection<Group> groups=orgService.getGroupHandler().findGroupsOfUser(username);
        for (        Group group : groups) {
          initializer.treatGroup(group,checkFolders);
        }
      }
      httpServletRequest.getSession().setAttribute(ATTR_FLAG_NAME,"true");
    }
 catch (    Exception e) {
      log.error("Error occured in TriggerInitializerFilter",e);
    }
 finally {
      RequestLifeCycle.end();
    }
  }
  filterChain.doFilter(servletRequest,servletResponse);
}
 

Example 51

From project gengweibo, under directory /src/com/gengweibo/web/.

Source file: SessionFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain filter) throws IOException, ServletException {
  String api=request.getParameter("api");
  if (null == api) {
    String queryString=((HttpServletRequest)request).getQueryString();
    if (queryString.length() > 0) {
      Pattern pattern=Pattern.compile("(\\?|&){0,1}api=(.*?)&{0,1}");
      Matcher matcher=pattern.matcher(queryString);
      if (matcher.matches() && matcher.groupCount() >= 2) {
        api=matcher.group(2);
      }
    }
  }
  if (null != api && !"link".equalsIgnoreCase(api) && !"logout".equalsIgnoreCase(api) && !"flush".equalsIgnoreCase(api) && null == ((HttpServletRequest)request).getSession().getAttribute(Account.ACCOUNT_SESSION_KEY)) {
    ((HttpServletResponse)response).sendRedirect(((HttpServletRequest)request).getContextPath() + "/error.jsp?desc=UnLogin");
    return;
  }
  filter.doFilter(request,response);
}
 

Example 52

From project gmc, under directory /src/org.gluster.storage.management.gateway/src/org/gluster/storage/management/gateway/filters/.

Source file: AuthenticationFailureFilter.java

  15 
vote

@Override public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest request=(HttpServletRequest)req;
  if (request.getRequestURI().contains("download")) {
    chain.doFilter(req,res);
    return;
  }
  CharResponseWrapper wrapper=new CharResponseWrapper((HttpServletResponse)res);
  chain.doFilter(req,wrapper);
  if (wrapper.getStatus() == Response.Status.UNAUTHORIZED.ordinal()) {
    PrintWriter out=res.getWriter();
    out.println("<status><code>1</code><message>Authentication Failed!</message></status>");
  }
}
 

Example 53

From project GNDMS, under directory /gndms/src/de/zib/gndms/gndms/security/.

Source file: LocalRequestSkippingChannelProcessingFilter.java

  15 
vote

@Override public void doFilter(final ServletRequest req,final ServletResponse res,final FilterChain chain) throws IOException, ServletException {
  final String remoteAddr=req.getRemoteAddr();
  logger.info("request from: " + remoteAddr);
  if (remoteAddr.equals(req.getLocalAddr()))   chain.doFilter(req,res);
 else   super.doFilter(req,res,chain);
}
 

Example 54

From project Guit, under directory /src/main/java/com/guit/server/crawling/.

Source file: CrawlingFilter.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest r=(HttpServletRequest)request;
  String query=r.getQueryString();
  if (query == null || !query.contains("_escaped_fragment_=")) {
    chain.doFilter(request,response);
  }
 else {
    String reqUrl=r.getRequestURL().toString();
    String queryString=r.getQueryString();
    if (queryString != null) {
      reqUrl+="?" + queryString;
    }
    URL fetchUrl=new URL(snapshootService + "/ajaxcrawler?url=" + URLEncoder.encode(reqUrl,"UTF-8"));
    response.setContentType("text/html");
    response.setCharacterEncoding("ISO-8859-1");
    ServletOutputStream out=response.getOutputStream();
    InputStream in=fetchUrl(fetchUrl);
    if (in == null) {
      out.print("<html><head></head><body></body></html>");
      return;
    }
    final byte[] bytes=new byte[4096];
    int bytesRead=in.read(bytes);
    while (bytesRead > -1) {
      out.write(bytes,0,bytesRead);
      bytesRead=in.read(bytes);
    }
  }
}
 

Example 55

From project guj.com.br, under directory /src/br/com/caelum/guj/vraptor/filter/.

Source file: BookmarkableURIFilter.java

  15 
vote

@Override public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest request=(HttpServletRequest)req;
  HttpServletResponse response=(HttpServletResponse)res;
  ConverterMatcher converters=new ConverterMatcher(AllBookmarkableToCompatibleConverters.get(request.getRequestURI()));
  if (converters.oneMatched()) {
    String compatibleURI=converters.getConverter().convert();
    if (converters.shortBookmarkableURI()) {
      redirectUsingCache(request,response,compatibleURI);
    }
 else {
      setRequestAttributesToCanonicalLink(request,converters);
      request.getRequestDispatcher(compatibleURI).forward(request,response);
    }
  }
 else {
    chain.doFilter(request,response);
  }
}
 

Example 56

From project hadoop_framework, under directory /webapp/src/main/java/org/sleuthkit/web/sampleapp/server/.

Source file: SecurityFilter.java

  15 
vote

@Override public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain) throws IOException, ServletException {
  boolean authorized=false;
  HttpSession session=((HttpServletRequest)req).getSession();
  String authVal=(String)session.getAttribute("SAMPLE_GWT_AUTH");
  if (authVal != null)   authorized=authVal.equals("y");
  if (authorized) {
    chain.doFilter(req,res);
  }
 else {
    String username=req.getParameter("username");
    String password=req.getParameter("password");
    if (username != null && password != null) {
      if (checkCredentials(username,password)) {
        session.setAttribute("SAMPLE_GWT_AUTH","y");
        session.setMaxInactiveInterval(SESSION_TIMEOUT * 60);
        ((HttpServletResponse)res).sendRedirect("/sampleapp/SampleApp.jsp");
      }
 else {
        String loginUrl="/sampleapp/login.jsp?failed=true";
        ((HttpServletResponse)res).sendRedirect(loginUrl);
      }
    }
 else {
      String loginUrl="/sampleapp/login.jsp";
      ((HttpServletResponse)res).sendRedirect(loginUrl);
    }
  }
}
 

Example 57

From project harmony, under directory /harmony.common.serviceinterface/src/main/java/org/opennaas/extensions/idb/serviceinterface/utils/.

Source file: CommonServletFilter.java

  15 
vote

@Override public void doFilter(final ServletRequest arg0,final ServletResponse arg1,final FilterChain arg2) throws IOException, ServletException {
  if (null != this.servletFiler) {
    this.servletFiler.doFilter(arg0,arg1,arg2);
  }
 else {
    arg2.doFilter(arg0,arg1);
  }
}
 

Example 58

From project Hesperid, under directory /server/src/main/java/ch/astina/hesperid/installer/web/services/.

Source file: TapestryDelayedFilter.java

  15 
vote

public final void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (!installed) {
    HttpServletRequest httpRequest=(HttpServletRequest)request;
    if (httpRequest.getServletPath().equals(com.spreadthesource.tapestry.installer.InternalConstants.RESTART_URI)) {
      this.start();
      ((HttpServletResponse)response).sendRedirect(httpRequest.getContextPath());
    }
 else {
      try {
        handler.service(httpRequest,(HttpServletResponse)response);
        return;
      }
  finally {
        registry.cleanupThread();
      }
    }
    return;
  }
  chain.doFilter(request,response);
}
 

Example 59

From project hoop, under directory /hoop-server/src/main/java/com/cloudera/lib/servlet/.

Source file: FileSystemReleaseFilter.java

  15 
vote

/** 
 * It delegates the incoming request to the <code>FilterChain</code>, and at its completion (in a finally block) releases the filesystem instance back to the  {@link Hadoop} service.
 * @param servletRequest servlet request.
 * @param servletResponse servlet response.
 * @param filterChain filter chain.
 * @throws IOException thrown if an IO error occurrs.
 * @throws ServletException thrown if a servet error occurrs.
 */
@Override public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain filterChain) throws IOException, ServletException {
  try {
    filterChain.doFilter(servletRequest,servletResponse);
  }
  finally {
    FileSystem fs=FILE_SYSTEM_TL.get();
    if (fs != null) {
      FILE_SYSTEM_TL.remove();
      getHadoop().releaseFileSystem(fs);
    }
  }
}