Package org.eclipse.jetty.http

Examples of org.eclipse.jetty.http.PathMap$MappedEntry


public class JettyPathMapTest {

  @Ignore( "This doesn't work like I expected." )
  @Test
  public void testPathMatching() {
    PathMap map = new PathMap();
    map.put( "/webhdfs", "/webhdfs" );
    map.put( "/webhdfs/dfshealth.jsp", "/webhdfs/dfshealth.jsp" );
    map.put( "/webhdfs/*", "/webhdfs/*" );

    assertThat( (String)map.match( "/webhdfs" ), equalTo( "/webhdfs" ) );
    assertThat( (String)map.match( "/webhdfs/dfshealth.jsp" ), equalTo( "/webhdfs/dfshealth.jsp" ) );
    assertThat( (String)map.match( "/webhdfs/v1" ), equalTo( "/webhdfs/*" ) );
  }
View Full Code Here


    public void addRewriteRule(String pattern, String prefix)
    {
        if (pattern==null || pattern.length()==0 || !pattern.startsWith("/"))
            throw new IllegalArgumentException();
        if (_rewrite==null)
            _rewrite=new PathMap(true);
        _rewrite.put(pattern,prefix);
    }
View Full Code Here

        _out = _fileOut;

        if (_ignorePaths != null && _ignorePaths.length > 0)
        {
            _ignorePathMap = new PathMap();
            for (int i = 0; i < _ignorePaths.length; i++)
                _ignorePathMap.put(_ignorePaths[i],_ignorePaths[i]);
        }
        else
            _ignorePathMap = null;
View Full Code Here

    /**
     * Remap the context paths.
     */
    public void mapContexts()
    {
        PathMap contextMap = new PathMap();
        Handler[] branches = getHandlers();
       
       
        for (int b=0;branches!=null && b<branches.length;b++)
        {
            Handler[] handlers=null;
           
            if (branches[b] instanceof ContextHandler)
            {
                handlers = new Handler[]{ branches[b] };
            }
            else if (branches[b] instanceof HandlerContainer)
            {
                handlers = ((HandlerContainer)branches[b]).getChildHandlersByClass(ContextHandler.class);
            }
            else
                continue;
           
            for (int i=0;i<handlers.length;i++)
            {
                ContextHandler handler=(ContextHandler)handlers[i];

                String contextPath=handler.getContextPath();

                if (contextPath==null || contextPath.indexOf(',')>=0 || contextPath.startsWith("*"))
                    throw new IllegalArgumentException ("Illegal context spec:"+contextPath);

                if(!contextPath.startsWith("/"))
                    contextPath='/'+contextPath;

                if (contextPath.length()>1)
                {
                    if (contextPath.endsWith("/"))
                        contextPath+="*";
                    else if (!contextPath.endsWith("/*"))
                        contextPath+="/*";
                }

                Object contexts=contextMap.get(contextPath);
                String[] vhosts=handler.getVirtualHosts();

               
                if (vhosts!=null && vhosts.length>0)
                {
                    Map hosts;

                    if (contexts instanceof Map)
                        hosts=(Map)contexts;
                    else
                    {
                        hosts=new HashMap();
                        hosts.put("*",contexts);
                        contextMap.put(contextPath, hosts);
                    }

                    for (int j=0;j<vhosts.length;j++)
                    {
                        String vhost=vhosts[j];
                        contexts=hosts.get(vhost);
                        contexts=LazyList.add(contexts,branches[b]);
                        hosts.put(vhost,contexts);
                    }
                }
                else if (contexts instanceof Map)
                {
                    Map hosts=(Map)contexts;
                    contexts=hosts.get("*");
                    contexts= LazyList.add(contexts, branches[b]);
                    hosts.put("*",contexts);
                }
                else
                {
                    contexts= LazyList.add(contexts, branches[b]);
                    contextMap.put(contextPath, contexts);
                }
            }
        }
        _contextMap=contextMap;

View Full Code Here

 
  // data structure which maps a request to a context; first-best match wins
  // { context path =>
  //     { virtual host => context }
  // }
  PathMap map = _contextMap;
  if (map!=null && target!=null && target.startsWith("/"))
  {
      // first, get all contexts matched by context path
      Object contexts = map.getLazyMatches(target);

            for (int i=0; i<LazyList.size(contexts); i++)
            {
                // then, match against the virtualhost of each context
                Map.Entry entry = (Map.Entry)LazyList.get(contexts, i);
View Full Code Here

            if (addr.endsWith("."))
                deprecated = true;
            if (path!=null && (path.startsWith("|") || path.startsWith("/*.")))
                path=path.substring(1);
          
            PathMap pathMap = patternMap.get(addr);
            if (pathMap == null)
            {
                pathMap = new PathMap(true);
                patternMap.put(addr,pathMap);
            }
            if (path != null)
                pathMap.put(path,path);
           
            if (deprecated)
                LOG.debug(toString() +" - deprecated specification syntax: "+entry);
        }
    }
View Full Code Here

            {
                List whiteList = (whiteObj instanceof List) ? (List)whiteObj : Collections.singletonList(whiteObj);

                for (Object entry: whiteList)
                {
                    PathMap pathMap = ((Map.Entry<String,PathMap>)entry).getValue();
                    if (match = (pathMap!=null && (pathMap.size()==0 || pathMap.match(path)!=null)))
                        break;
                }
            }
           
            if (!match)
                return false;
        }

        if (_black.size() > 0)
        {
            Object blackObj = _black.getLazyMatches(addr);
            if (blackObj != null)
            {
                List blackList = (blackObj instanceof List) ? (List)blackObj : Collections.singletonList(blackObj);
   
                for (Object entry: blackList)
                {
                    PathMap pathMap = ((Map.Entry<String,PathMap>)entry).getValue();
                    if (pathMap!=null && (pathMap.size()==0 || pathMap.match(path)!=null))
                        return false;
                }
            }
        }
       
View Full Code Here

        this.properties = properties;
        this.enabled = getBoolean("enabled", true);
        this.type = getString("type", "jetty");
        String ignorePaths = getString("ignorePaths", "");
        if (ignorePaths != null && ignorePaths.length() > 0) {
            ignorePathMap = new PathMap();
            for (String s : ignorePaths.split(",")) {
                ignorePathMap.put(s, s);
            }
        }
        else {
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.http.PathMap$MappedEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.