Request base_request = Request.getBaseRequest(request); Response base_response = base_request.getResponse(); String uri = request.getRequestURI(); if (uri==null) uri=URIUtil.SLASH; return new DeferredAuthentication(this); if (isLoginOrErrorPage(URIUtil.addPaths(request.getServletPath(),request.getPathInfo())) &&!DeferredAuthentication.isDeferred(response)) return new DeferredAuthentication(this); LOG.debug("jsecuritycheck {} {}",username,user); HttpSession session = request.getSession(false); if (user!=null) LOG.debug("authenticated {}->{}",form_auth,nuri); LOG.debug("auth failed {}->{}",username,_formErrorPage); int redirectCode = (base_request.getHttpVersion().getVersion() < HttpVersion.HTTP_1_1.getVersion() ? HttpServletResponse.SC_MOVED_TEMPORARILY : HttpServletResponse.SC_SEE_OTHER); base_response.sendRedirect(redirectCode, response.encodeRedirectURL(URIUtil.addPaths(request.getContextPath(),_formErrorPage))); LOG.debug("challenge {}->{}",session.getId(),_formLoginPage); int redirectCode = (base_request.getHttpVersion().getVersion() < HttpVersion.HTTP_1_1.getVersion() ? HttpServletResponse.SC_MOVED_TEMPORARILY : HttpServletResponse.SC_SEE_OTHER); base_response.sendRedirect(redirectCode, response.encodeRedirectURL(URIUtil.addPaths(request.getContextPath(),_formLoginPage)));
String tmp = URIUtil.decodePath(resource.getURL().getPath()); if (tmp.endsWith("/")) tmp = tmp.substring(0, tmp.length()-1); LOG.warn("Can't generate resourceBase as part of webapp tmp dir name: " + e); LOG.debug(e);
if (!URIUtil.equalsIgnoreEncodings(uri,file.toURI())) if (LOG.isDebugEnabled()) LOG.debug("ALIAS abs={} can={}",abs,can); return new URI("file://"+URIUtil.encodePath(alias.getPath())); LOG.warn("bad alias for {}: {}",file,e.toString()); LOG.debug(e); try
/** * Returns the resource contained inside the current resource with the * given name */ @Override public Resource addPath(String path) throws IOException,MalformedURLException { if (path==null) return null; path = URIUtil.canonicalPath(path); return newResource(URIUtil.addEncodedPaths(_url.toExternalForm(),URIUtil.encodePath(path)), _useCaches); }
throws IOException base=URIUtil.canonicalPath(base); if (base==null || !isDirectory()) return null; String[] ls = list(); if (ls==null) return null; Arrays.sort(ls); String decodedBase = URIUtil.decodePath(base); String title = "Directory: "+deTag(decodedBase); buf.append(URIUtil.addEncodedPaths(base,"../")); buf.append("\">Parent Directory</A></TD><TD></TD><TD></TD></TR>\n"); String path=URIUtil.addEncodedPaths(encodedBase,URIUtil.encodePath(ls[i]));
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (_newContextURL==null) return; String path=_newContextURL; if (!_discardPathInfo && request.getPathInfo()!=null) path=URIUtil.addPaths(path, request.getPathInfo()); StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL(); location.append(path); if (!_discardQuery && request.getQueryString()!=null) { location.append('?'); String q=request.getQueryString(); q=q.replaceAll("\r\n?&=","!"); location.append(q); } response.setHeader(HttpHeaders.LOCATION,location.toString()); if (_expires!=null) response.setHeader(HttpHeaders.EXPIRES,_expires); response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND); response.setContentLength(0); baseRequest.setHandled(true); }
response.sendError(HttpServletResponse.SC_FORBIDDEN); return; String base = URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH); resource=_resourceBase.addPath(pathInContext); else if (_contextHandler.getBaseResource() instanceof ResourceCollection) resource=_contextHandler.getBaseResource().addPath(pathInContext); response.sendError(HttpServletResponse.SC_FORBIDDEN, "No directory"); return; response.setContentType("text/html; charset=UTF-8"); response.setContentLength(data.length); response.getOutputStream().write(data);
protected void notFound(Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (LOG.isDebugEnabled()) LOG.debug("Not Found {}",request.getRequestURI()); if (getHandler()!=null) nextHandle(URIUtil.addPaths(request.getServletPath(),request.getPathInfo()),baseRequest,request,response); }
protected void startAsync(final ServletContext context, final ServletRequest request, final ServletResponse response) { synchronized (this) { _responseWrapped=!(response instanceof Response); doSuspend(context,request,response); if (request instanceof HttpServletRequest) { _event._pathInContext = URIUtil.addPaths(((HttpServletRequest)request).getServletPath(),((HttpServletRequest)request).getPathInfo()); } } }
if (!URIUtil.hasScheme(location)) URIUtil.appendSchemeHostPort(url,request.getScheme(),request.getServerName(),request.getServerPort()); location = URIUtil.canonicalEncodedPath(location); String path = request.getRequestURI(); String parent = (path.endsWith("/")) ? path : URIUtil.parentPath(path); location = URIUtil.canonicalPath(URIUtil.addEncodedPaths(parent,location)); if (!location.startsWith("/")) url.append('/');
if (LOG.isDebugEnabled()) LOG.debug("call filter " + _filterHolder); Filter filter= _filterHolder.getFilter(); if (_filterHolder.isAsyncSupported()) else final boolean suspendable=baseRequest.isAsyncSupported(); if (suspendable) baseRequest.setAsyncSupported(false); filter.doFilter(request, response, _next); baseRequest.setAsyncSupported(true); if (_servletHolder != null) if (LOG.isDebugEnabled()) LOG.debug("call servlet " + _servletHolder); _servletHolder.handle(baseRequest,request, response); notFound(srequest, (HttpServletResponse)response); else nextHandle(URIUtil.addPaths(srequest.getServletPath(),srequest.getPathInfo()), baseRequest,srequest,(HttpServletResponse)response);
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // only redirect if its / to hawtio if (req.getRequestURI().equals("/")) { String url = URIUtil.addPaths(req.getRequestURI(), "hawtio"); resp.sendRedirect(url); } } }
public void handleAsync(HttpChannel channel) throws IOException, ServletException { final HttpChannelState state = channel.getRequest().getHttpChannelState(); final AsyncContextEvent event = state.getAsyncContextEvent(); final Request baseRequest=channel.getRequest(); final String path=event.getPath(); if (path!=null) { // this is a dispatch with a path ServletContext context=event.getServletContext(); String query=baseRequest.getQueryString(); baseRequest.setURIPathQuery(URIUtil.addEncodedPaths(context==null?null:URIUtil.encodePath(context.getContextPath()), path)); HttpURI uri = baseRequest.getHttpURI(); baseRequest.setPathInfo(uri.getDecodedPath()); if (uri.getQuery()!=null) baseRequest.mergeQueryParameters(query,uri.getQuery(), true); //we have to assume dispatch path and query are UTF8 } final String target=baseRequest.getPathInfo(); final HttpServletRequest request=(HttpServletRequest)event.getSuppliedRequest(); final HttpServletResponse response=(HttpServletResponse)event.getSuppliedResponse(); if (LOG.isDebugEnabled()) LOG.debug("{} {} {} on {}", request.getDispatcherType(), request.getMethod(), target, channel); handle(target, baseRequest, request, response); if (LOG.isDebugEnabled()) LOG.debug("handledAsync={} async={} committed={} on {}", channel.getRequest().isHandled(),request.isAsyncStarted(),response.isCommitted(),channel); }
@Override public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException { if (_asyncNotSupportedSource!=null) throw new IllegalStateException("!asyncSupported: "+_asyncNotSupportedSource); HttpChannelState state = getHttpChannelState(); if (_async==null) _async=new AsyncContextState(state); AsyncContextEvent event = new AsyncContextEvent(_context,_async,state,this,servletRequest,servletResponse); event.setDispatchContext(getServletContext()); String uri = ((HttpServletRequest)servletRequest).getRequestURI(); if (_contextPath!=null && uri.startsWith(_contextPath)) uri = uri.substring(_contextPath.length()); else // TODO probably need to strip encoded context from requestURI, but will do this for now: uri = URIUtil.encodePath(URIUtil.addPaths(getServletPath(),getPathInfo())); event.setDispatchPath(uri); state.startAsync(event); return _async; }
public void handleAsync(HttpChannel connection) throws IOException, ServletException { final HttpChannelState state = connection.getRequest().getHttpChannelState(); final AsyncContextEvent event = state.getAsyncContextEvent(); final Request baseRequest=connection.getRequest(); final String path=event.getPath(); if (path!=null) { // this is a dispatch with a path ServletContext context=event.getServletContext(); String query=baseRequest.getQueryString(); baseRequest.setURIPathQuery(URIUtil.addPaths(context==null?null:context.getContextPath(), path)); HttpURI uri = baseRequest.getHttpURI(); baseRequest.setPathInfo(uri.getDecodedPath()); if (uri.getQuery()!=null) baseRequest.mergeQueryParameters(query,uri.getQuery(), true); //we have to assume dispatch path and query are UTF8 } final String target=baseRequest.getPathInfo(); final HttpServletRequest request=(HttpServletRequest)event.getSuppliedRequest(); final HttpServletResponse response=(HttpServletResponse)event.getSuppliedResponse(); if (LOG.isDebugEnabled()) { LOG.debug(request.getDispatcherType()+" "+request.getMethod()+" "+target+" on "+connection); handle(target, baseRequest, request, response); LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus()); } else handle(target, baseRequest, request, response); }
public void handleAsync(HttpChannel<?> connection) throws IOException, ServletException { final HttpChannelState state = connection.getRequest().getHttpChannelState(); final AsyncContextEvent event = state.getAsyncContextEvent(); final Request baseRequest=connection.getRequest(); final String path=event.getPath(); if (path!=null) { // this is a dispatch with a path ServletContext context=event.getServletContext(); HttpURI uri = new HttpURI(URIUtil.addPaths(context==null?null:context.getContextPath(), path)); baseRequest.setUri(uri); baseRequest.setRequestURI(null); baseRequest.setPathInfo(uri.getDecodedPath()); if (uri.getQuery()!=null) baseRequest.mergeQueryParameters(uri.getQuery(), true); //we have to assume dispatch path and query are UTF8 } final String target=baseRequest.getPathInfo(); final HttpServletRequest request=(HttpServletRequest)event.getSuppliedRequest(); final HttpServletResponse response=(HttpServletResponse)event.getSuppliedResponse(); if (LOG.isDebugEnabled()) { LOG.debug(request.getDispatcherType()+" "+request.getMethod()+" "+target+" on "+connection); handle(target, baseRequest, request, response); LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus()); } else handle(target, baseRequest, request, response); }
public void handleAsync(AbstractHttpConnection connection) throws IOException, ServletException { final AsyncContinuation async = connection.getRequest().getAsyncContinuation(); final AsyncContinuation.AsyncEventState state = async.getAsyncEventState(); final Request baseRequest=connection.getRequest(); final String path=state.getPath(); if (path!=null) { // this is a dispatch with a path final String contextPath=state.getServletContext().getContextPath(); HttpURI uri = new HttpURI(URIUtil.addPaths(contextPath,path)); baseRequest.setUri(uri); baseRequest.setRequestURI(null); baseRequest.setPathInfo(baseRequest.getRequestURI()); if (uri.getQuery()!=null) baseRequest.mergeQueryString(uri.getQuery()); //we have to assume dispatch path and query are UTF8 } final String target=baseRequest.getPathInfo(); final HttpServletRequest request=(HttpServletRequest)async.getRequest(); final HttpServletResponse response=(HttpServletResponse)async.getResponse(); if (LOG.isDebugEnabled()) { LOG.debug("REQUEST "+target+" on "+connection); handle(target, baseRequest, request, response); LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus()); } else handle(target, baseRequest, request, response); }
throw new IllegalArgumentException(); if (!URIUtil.hasScheme(location)) StringBuilder buf = _connection.getRequest().getRootURL(); if (location.startsWith("/")) location=URIUtil.canonicalPath(location); String path=_connection.getRequest().getRequestURI(); String parent=(path.endsWith("/"))?path:URIUtil.parentPath(path); location=URIUtil.canonicalPath(URIUtil.addPaths(parent,location)); if (!location.startsWith("/")) buf.append('/');
public Resource getResource(String path) throws MalformedURLException { if (path == null || !path.startsWith(URIUtil.SLASH)) throw new MalformedURLException(path); if (_baseResource == null) return null; try { path = URIUtil.canonicalPath(path); Resource resource = _baseResource.addPath(path); if (checkAlias(path,resource)) return resource; return null; } catch (Exception e) { LOG.ignore(e); } return null; }
@Override public StringBuffer getRequestURL() { final StringBuffer url = new StringBuffer(128); URIUtil.appendSchemeHostPort(url,getScheme(),getServerName(),getServerPort()); url.append(getRequestURI()); return url; }