knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [19/24] knox git commit: Merge branch 'master' into KNOX-998-Package_Restructuring
Date Fri, 08 Sep 2017 15:15:12 GMT
http://git-wip-us.apache.org/repos/asf/knox/blob/50f46e9e/gateway-server/src/test/java/org/apache/knox/gateway/deploy/DeploymentFactoryTest.java
----------------------------------------------------------------------
diff --cc gateway-server/src/test/java/org/apache/knox/gateway/deploy/DeploymentFactoryTest.java
index 2f2ea9b,0000000..2973f40
mode 100644,000000..100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/deploy/DeploymentFactoryTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/deploy/DeploymentFactoryTest.java
@@@ -1,324 -1,0 +1,324 @@@
 +/**
 + * Licensed to the Apache Software Foundation (ASF) under one
 + * or more contributor license agreements.  See the NOTICE file
 + * distributed with this work for additional information
 + * regarding copyright ownership.  The ASF licenses this file
 + * to you under the Apache License, Version 2.0 (the
 + * "License"); you may not use this file except in compliance
 + * with the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.knox.gateway.deploy;
 +
 +import java.io.IOException;
 +import javax.xml.parsers.ParserConfigurationException;
 +import javax.xml.transform.TransformerException;
 +
 +import org.apache.knox.gateway.config.GatewayConfig;
 +import org.apache.knox.gateway.config.impl.GatewayConfigImpl;
 +import org.apache.knox.gateway.topology.Application;
 +import org.apache.knox.gateway.topology.Service;
 +import org.apache.knox.gateway.topology.Topology;
 +import org.apache.knox.gateway.util.XmlUtils;
 +import org.apache.hadoop.test.TestUtils;
 +import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
 +import org.junit.Test;
 +import org.w3c.dom.Document;
 +import org.xml.sax.SAXException;
 +
- import static junit.framework.TestCase.fail;
 +import static org.hamcrest.MatcherAssert.assertThat;
 +import static org.hamcrest.core.IsEqual.equalTo;
 +import static org.hamcrest.xml.HasXPath.hasXPath;
++import static org.junit.Assert.fail;
 +
 +public class DeploymentFactoryTest {
 +
 +  @Test( timeout = TestUtils.MEDIUM_TIMEOUT )
 +  public void testEmptyTopology() throws IOException, SAXException, ParserConfigurationException, TransformerException {
 +    GatewayConfig config = new GatewayConfigImpl();
 +
 +    Topology topology = new Topology();
 +    topology.setName( "test-topology" );
 +
 +    EnterpriseArchive archive = DeploymentFactory.createDeployment( config, topology );
 +
 +    Document xml = XmlUtils.readXml( archive.get( "/META-INF/topology.xml" ).getAsset().openStream() );
 +    assertThat( xml, hasXPath( "/topology/gateway" ) );
 +    assertThat( xml, hasXPath( "/topology/name", equalTo( "test-topology" ) ) );
 +  }
 +
 +  @Test( timeout = TestUtils.SHORT_TIMEOUT )
 +  public void test_validateNoAppsWithRootUrlsInServicesTopology() {
 +    DeploymentFactory.validateNoAppsWithRootUrlsInServicesTopology( null );
 +
 +    Topology topology = new Topology();
 +    topology.setName( "test-topology" );
 +    DeploymentFactory.validateNoAppsWithRootUrlsInServicesTopology( topology );
 +
 +    Service service;
 +    Application application;
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    service = new Service();
 +    service.setName( "test-service" );
 +    service.setRole( "test-service" );
 +    topology.addService( service );
 +    application = new Application();
 +    application.setName( "test-application" );
 +    topology.addApplication( application );
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    service = new Service();
 +    service.setName( "test-service" );
 +    service.setRole( "test-service" );
 +    topology.addService( service );
 +    application = new Application();
 +    application.setName( "test-application" );
 +    application.addUrl( "" );
 +    topology.addApplication( application );
 +    try {
 +      DeploymentFactory.validateNoAppsWithRootUrlsInServicesTopology( topology );
 +      fail( "Expected DeploymentException" );
 +    } catch ( DeploymentException e ) {
 +      // Expected.
 +    }
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    service = new Service();
 +    service.setName( "test-service" );
 +    service.setRole( "test-service" );
 +    topology.addService( service );
 +    application = new Application();
 +    application.setName( "test-application" );
 +    application.addUrl( "/" );
 +    topology.addApplication( application );
 +    try {
 +      DeploymentFactory.validateNoAppsWithRootUrlsInServicesTopology( topology );
 +      fail( "Expected DeploymentException" );
 +    } catch ( DeploymentException e ) {
 +      // Expected.
 +    }
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    service = new Service();
 +    service.setName( "test-service" );
 +    service.setRole( "test-service" );
 +    topology.addService( service );
 +    application = new Application();
 +    application.setName( "test-application" );
 +    application.addUrl( "/" );
 +    topology.addApplication( application );
 +    try {
 +      DeploymentFactory.validateNoAppsWithRootUrlsInServicesTopology( topology );
 +      fail( "Expected DeploymentException" );
 +    } catch ( DeploymentException e ) {
 +      // Expected.
 +    }
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    service = new Service();
 +    service.setName( "test-service" );
 +    service.setRole( "test-service" );
 +    topology.addService( service );
 +    application = new Application();
 +    application.setName( "test-application" );
 +    application.addUrl( "/test-application" );
 +    application.addUrl( "/" );
 +    topology.addApplication( application );
 +    try {
 +      DeploymentFactory.validateNoAppsWithRootUrlsInServicesTopology( topology );
 +      fail( "Expected DeploymentException" );
 +    } catch ( DeploymentException e ) {
 +      // Expected.
 +    }
 +
 +  }
 +
 +  @Test( timeout = TestUtils.SHORT_TIMEOUT )
 +  public void test_validateNoAppsWithDuplicateUrlsInTopology() {
 +    DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology( null );
 +
 +    Topology topology = new Topology();
 +    topology.setName( "test-topology" );
 +    DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology( topology );
 +
 +    Application application;
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    application = new Application();
 +    application.setName( "test-application-1" );
 +    topology.addApplication( application );
 +    DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology( topology );
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    application = new Application();
 +    application.setName( "test-application-1" );
 +    topology.addApplication( application );
 +    application = new Application();
 +    application.setName( "test-application-2" );
 +    topology.addApplication( application );
 +    DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology( topology );
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    application = new Application();
 +    application.setName( "test-application-1" );
 +    topology.addApplication( application );
 +    application = new Application();
 +    application.setName( "test-application-2" );
 +    application.addUrl( "/test-application-2" );
 +    topology.addApplication( application );
 +    DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology( topology );
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    application = new Application();
 +    application.setName( "test-application-1" );
 +    topology.addApplication( application );
 +    application = new Application();
 +    application.setName( "test-application-2" );
 +    application.addUrl( "/" );
 +    topology.addApplication( application );
 +    DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology( topology );
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    application = new Application();
 +    application.setName( "test-application-1" );
 +    topology.addApplication( application );
 +    application = new Application();
 +    application.setName( "test-application-2" );
 +    application.addUrl( "/" );
 +    topology.addApplication( application );
 +    DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology( topology );
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    application = new Application();
 +    application.setName( "test-application-1" );
 +    application.addUrl( "/test-application-1" );
 +    topology.addApplication( application );
 +    application = new Application();
 +    application.setName( "test-application-2" );
 +    application.addUrl( "/test-application-2" );
 +    topology.addApplication( application );
 +    DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology( topology );
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    application = new Application();
 +    application.setName( "test-application-1" );
 +    application.addUrl( "/test-application-dup" );
 +    topology.addApplication( application );
 +    application = new Application();
 +    application.setName( "test-application-2" );
 +    application.addUrl( "/test-application-dup" );
 +    topology.addApplication( application );
 +    try {
 +      DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology( topology );
 +      fail( "Expected DeploymentException" );
 +    } catch ( DeploymentException e ) {
 +      // Expected.
 +    }
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    application = new Application();
 +    application.setName( "test-application-1" );
 +    application.addUrl( "/" );
 +    topology.addApplication( application );
 +    application = new Application();
 +    application.setName( "test-application-2" );
 +    application.addUrl( "/" );
 +    topology.addApplication( application );
 +    try {
 +      DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology( topology );
 +      fail( "Expected DeploymentException" );
 +    } catch ( DeploymentException e ) {
 +      // Expected.
 +    }
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    application = new Application();
 +    application.setName( "test-application-1" );
 +    application.addUrl( "" );
 +    topology.addApplication( application );
 +    application = new Application();
 +    application.setName( "test-application-2" );
 +    application.addUrl( "/" );
 +    topology.addApplication( application );
 +    try {
 +      DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology( topology );
 +      fail( "Expected DeploymentException" );
 +    } catch ( DeploymentException e ) {
 +      // Expected.
 +    }
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    application = new Application();
 +    application.setName( "test-application-1" );
 +    topology.addApplication( application );
 +    application = new Application();
 +    application.setName( "test-application-2" );
 +    application.addUrl( "/test-application-1" );
 +    topology.addApplication( application );
 +    try {
 +      DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology( topology );
 +      fail( "Expected DeploymentException" );
 +    } catch ( DeploymentException e ) {
 +      // Expected.
 +    }
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    application = new Application();
 +    application.setName( "test-application-1" );
 +    topology.addApplication( application );
 +    application = new Application();
 +    application.setName( "test-application-1" );
 +    topology.addApplication( application );
 +    try {
 +      DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology( topology );
 +      fail( "Expected DeploymentException" );
 +    } catch ( DeploymentException e ) {
 +      // Expected.
 +    }
 +
 +    topology = new Topology();
 +    topology.setName( "test-topology" );
 +    application = new Application();
 +    application.setName( "test-application-1" );
 +    application.addUrl( "/test-application-1" );
 +    application.addUrl( "/test-application-3" );
 +    topology.addApplication( application );
 +    application = new Application();
 +    application.setName( "test-application-2" );
 +    application.addUrl( "/test-application-2" );
 +    application.addUrl( "/test-application-3" );
 +    topology.addApplication( application );
 +    try {
 +      DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology( topology );
 +      fail( "Expected DeploymentException" );
 +    } catch ( DeploymentException e ) {
 +      // Expected.
 +    }
 +
 +  }
 +
 +}

http://git-wip-us.apache.org/repos/asf/knox/blob/50f46e9e/gateway-service-admin/src/main/java/org/apache/knox/gateway/service/admin/TopologiesResource.java
----------------------------------------------------------------------
diff --cc gateway-service-admin/src/main/java/org/apache/knox/gateway/service/admin/TopologiesResource.java
index 60c566d,0000000..1861490
mode 100644,000000..100644
--- a/gateway-service-admin/src/main/java/org/apache/knox/gateway/service/admin/TopologiesResource.java
+++ b/gateway-service-admin/src/main/java/org/apache/knox/gateway/service/admin/TopologiesResource.java
@@@ -1,312 -1,0 +1,312 @@@
 +/**
 + * Licensed to the Apache Software Foundation (ASF) under one
 + * or more contributor license agreements.  See the NOTICE file
 + * distributed with this work for additional information
 + * regarding copyright ownership.  The ASF licenses this file
 + * to you under the Apache License, Version 2.0 (the
 + * "License"); you may not use this file except in compliance
 + * with the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.knox.gateway.service.admin;
 +
 +import org.apache.knox.gateway.service.admin.beans.BeanConverter;
 +import org.apache.knox.gateway.service.admin.beans.Topology;
 +import org.apache.knox.gateway.services.GatewayServices;
 +import org.apache.knox.gateway.config.GatewayConfig;
 +import org.apache.knox.gateway.services.topology.TopologyService;
 +
 +import javax.servlet.http.HttpServletRequest;
 +import javax.ws.rs.Consumes;
 +import javax.ws.rs.DELETE;
 +import javax.ws.rs.GET;
 +import javax.ws.rs.PUT;
 +import javax.ws.rs.Path;
 +import javax.ws.rs.PathParam;
 +import javax.ws.rs.Produces;
 +import javax.ws.rs.core.Context;
 +import javax.ws.rs.core.Response;
 +import javax.xml.bind.annotation.XmlAccessType;
 +import javax.xml.bind.annotation.XmlAccessorType;
 +import javax.xml.bind.annotation.XmlElement;
 +import javax.xml.bind.annotation.XmlElementWrapper;
 +import java.net.URI;
 +import java.net.URISyntaxException;
 +import java.util.ArrayList;
 +import java.util.Collections;
 +import java.util.Comparator;
 +import java.util.List;
 +
 +import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
 +import static javax.ws.rs.core.MediaType.APPLICATION_XML;
 +import static javax.ws.rs.core.Response.ok;
 +
 +@Path("/api/v1")
 +public class TopologiesResource {
 +  @Context
 +  private HttpServletRequest request;
 +
 +  @GET
 +  @Produces({APPLICATION_JSON, APPLICATION_XML})
 +  @Path("topologies/{id}")
 +  public Topology getTopology(@PathParam("id") String id) {
 +    GatewayServices services = (GatewayServices) request.getServletContext()
 +        .getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
 +    GatewayConfig config = (GatewayConfig) request.getServletContext().getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
 +
 +    TopologyService ts = services.getService(GatewayServices.TOPOLOGY_SERVICE);
 +
 +    for (org.apache.knox.gateway.topology.Topology t : ts.getTopologies()) {
 +      if(t.getName().equals(id)) {
 +        try {
 +          t.setUri(new URI( buildURI(t, config, request) ));
 +        } catch (URISyntaxException se) {
 +          t.setUri(null);
 +        }
 +        return BeanConverter.getTopology(t);
 +      }
 +    }
 +    return null;
 +  }
 +
 +  @GET
 +  @Produces({APPLICATION_JSON, APPLICATION_XML})
 +  @Path("topologies")
 +  public SimpleTopologyWrapper getTopologies() {
 +    GatewayServices services = (GatewayServices) request.getServletContext()
 +        .getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
 +
 +
 +    TopologyService ts = services.getService(GatewayServices.TOPOLOGY_SERVICE);
 +
 +    ArrayList<SimpleTopology> st = new ArrayList<SimpleTopology>();
 +    GatewayConfig conf = (GatewayConfig) request.getServletContext().getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
 +
 +    for (org.apache.knox.gateway.topology.Topology t : ts.getTopologies()) {
 +      st.add(getSimpleTopology(t, conf));
 +    }
 +
 +    Collections.sort(st, new TopologyComparator());
 +    SimpleTopologyWrapper stw = new SimpleTopologyWrapper();
 +
 +    for(SimpleTopology t : st){
 +      stw.topologies.add(t);
 +    }
 +
 +    return stw;
 +
 +  }
 +
 +  @PUT
 +  @Consumes({APPLICATION_JSON, APPLICATION_XML})
 +  @Path("topologies/{id}")
 +  public Topology uploadTopology(@PathParam("id") String id, Topology t) {
 +
 +    GatewayServices gs = (GatewayServices) request.getServletContext()
 +        .getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
 +
 +    t.setName(id);
 +    TopologyService ts = gs.getService(GatewayServices.TOPOLOGY_SERVICE);
 +
 +    ts.deployTopology(BeanConverter.getTopology(t));
 +
 +    return getTopology(id);
 +  }
 +
 +  @DELETE
 +  @Produces(APPLICATION_JSON)
 +  @Path("topologies/{id}")
 +  public Response deleteTopology(@PathParam("id") String id) {
 +    boolean deleted = false;
-     if(!id.equals("admin")) {
++    if(!"admin".equals(id)) {
 +      GatewayServices services = (GatewayServices) request.getServletContext()
 +          .getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
 +
 +      TopologyService ts = services.getService(GatewayServices.TOPOLOGY_SERVICE);
 +
 +      for (org.apache.knox.gateway.topology.Topology t : ts.getTopologies()) {
 +        if(t.getName().equals(id)) {
 +          ts.deleteTopology(t);
 +          deleted = true;
 +        }
 +      }
 +    }else{
 +      deleted = false;
 +    }
 +    return ok().entity("{ \"deleted\" : " + deleted + " }").build();
 +  }
 +
 +
 +  private static class TopologyComparator implements Comparator<SimpleTopology> {
 +    @Override
 +    public int compare(SimpleTopology t1, SimpleTopology t2) {
 +      return t1.getName().compareTo(t2.getName());
 +    }
 +  }
 +
 +   String buildURI(org.apache.knox.gateway.topology.Topology topology, GatewayConfig config, HttpServletRequest req){
 +    String uri = buildXForwardBaseURL(req);
 +
 +//    Strip extra context
 +    uri = uri.replace(req.getContextPath(), "");
 +
 +//    Add the gateway path
 +    String gatewayPath;
 +    if(config.getGatewayPath() != null){
 +      gatewayPath = config.getGatewayPath();
 +    }else{
 +      gatewayPath = "gateway";
 +    }
 +    uri += "/" + gatewayPath;
 +
 +    uri += "/" + topology.getName();
 +    return uri;
 +  }
 +
 +   String buildHref(org.apache.knox.gateway.topology.Topology t, HttpServletRequest req) {
 +    String href = buildXForwardBaseURL(req);
 +//    Make sure that the pathInfo doesn't have any '/' chars at the end.
 +    String pathInfo = req.getPathInfo();
 +    if(pathInfo.endsWith("/")) {
 +      while(pathInfo.endsWith("/")) {
 +        pathInfo = pathInfo.substring(0, pathInfo.length() - 1);
 +      }
 +    }
 +
 +    href += pathInfo + "/" + t.getName();
 +    return href;
 +  }
 +
 +  private SimpleTopology getSimpleTopology(
 +      org.apache.knox.gateway.topology.Topology t, GatewayConfig config) {
 +    String uri = buildURI(t, config, request);
 +    String href = buildHref(t, request);
 +    return new SimpleTopology(t, uri, href);
 +  }
 +
 +  private String buildXForwardBaseURL(HttpServletRequest req){
 +    final String X_Forwarded = "X-Forwarded-";
 +    final String X_Forwarded_Context = X_Forwarded + "Context";
 +    final String X_Forwarded_Proto = X_Forwarded + "Proto";
 +    final String X_Forwarded_Host = X_Forwarded + "Host";
 +    final String X_Forwarded_Port = X_Forwarded + "Port";
 +    final String X_Forwarded_Server = X_Forwarded + "Server";
 +
 +    String baseURL = "";
 +
 +//    Get Protocol
 +    if(req.getHeader(X_Forwarded_Proto) != null){
 +      baseURL += req.getHeader(X_Forwarded_Proto) + "://";
 +    } else {
 +      baseURL += req.getProtocol() + "://";
 +    }
 +
 +//    Handle Server/Host and Port Here
 +    if (req.getHeader(X_Forwarded_Host) != null && req.getHeader(X_Forwarded_Port) != null){
 +//        Double check to see if host has port
 +      if(req.getHeader(X_Forwarded_Host).contains(req.getHeader(X_Forwarded_Port))){
 +        baseURL += req.getHeader(X_Forwarded_Host);
 +      } else {
 +//        If there's no port, add the host and port together;
 +        baseURL += req.getHeader(X_Forwarded_Host) + ":" + req.getHeader(X_Forwarded_Port);
 +      }
 +    } else if(req.getHeader(X_Forwarded_Server) != null && req.getHeader(X_Forwarded_Port) != null){
 +//      Tack on the server and port if they're available. Try host if server not available
 +      baseURL += req.getHeader(X_Forwarded_Server) + ":" + req.getHeader(X_Forwarded_Port);
 +    } else if(req.getHeader(X_Forwarded_Port) != null) {
 +//      if we at least have a port, we can use it.
 +      baseURL += req.getServerName() + ":" + req.getHeader(X_Forwarded_Port);
 +    } else {
 +//      Resort to request members
 +      baseURL += req.getServerName() + ":" + req.getLocalPort();
 +    }
 +
 +//    Handle Server context
 +    if( req.getHeader(X_Forwarded_Context) != null ) {
 +      baseURL += req.getHeader( X_Forwarded_Context );
 +    } else {
 +      baseURL += req.getContextPath();
 +    }
 +
 +    return baseURL;
 +  }
 +
 +  @XmlAccessorType(XmlAccessType.NONE)
 +  public static class SimpleTopology {
 +
 +    @XmlElement
 +    private String name;
 +    @XmlElement
 +    private String timestamp;
 +    @XmlElement
 +    private String uri;
 +    @XmlElement
 +    private String href;
 +
 +    public SimpleTopology() {}
 +
 +    public SimpleTopology(org.apache.knox.gateway.topology.Topology t, String uri, String href) {
 +      this.name = t.getName();
 +      this.timestamp = Long.toString(t.getTimestamp());
 +      this.uri = uri;
 +      this.href = href;
 +    }
 +
 +    public String getName() {
 +      return name;
 +    }
 +
 +    public void setName(String n) {
 +      name = n;
 +    }
 +
 +    public String getTimestamp() {
 +      return timestamp;
 +    }
 +
 +    public void setTimestamp(String timestamp) {
 +      this.timestamp = timestamp;
 +    }
 +
 +    public String getUri() {
 +      return uri;
 +    }
 +
 +    public void setUri(String uri) {
 +      this.uri = uri;
 +    }
 +
 +    public String getHref() {
 +      return href;
 +    }
 +
 +    public void setHref(String href) {
 +      this.href = href;
 +    }
 +  }
 +
 +  @XmlAccessorType(XmlAccessType.FIELD)
 +  public static class SimpleTopologyWrapper{
 +
 +    @XmlElement(name="topology")
 +    @XmlElementWrapper(name="topologies")
 +    private List<SimpleTopology> topologies = new ArrayList<SimpleTopology>();
 +
 +    public List<SimpleTopology> getTopologies(){
 +      return topologies;
 +    }
 +
 +    public void setTopologies(List<SimpleTopology> ts){
 +      this.topologies = ts;
 +    }
 +
 +  }
 +}
 +

http://git-wip-us.apache.org/repos/asf/knox/blob/50f46e9e/gateway-service-rm/src/test/java/org/apache/knox/gateway/rm/dispatch/RMHaDispatchTest.java
----------------------------------------------------------------------
diff --cc gateway-service-rm/src/test/java/org/apache/knox/gateway/rm/dispatch/RMHaDispatchTest.java
index c0cf8d0,0000000..722fb1c
mode 100644,000000..100644
--- a/gateway-service-rm/src/test/java/org/apache/knox/gateway/rm/dispatch/RMHaDispatchTest.java
+++ b/gateway-service-rm/src/test/java/org/apache/knox/gateway/rm/dispatch/RMHaDispatchTest.java
@@@ -1,219 -1,0 +1,224 @@@
 +/**
 + * Licensed to the Apache Software Foundation (ASF) under one
 + * or more contributor license agreements.  See the NOTICE file
 + * distributed with this work for additional information
 + * regarding copyright ownership.  The ASF licenses this file
 + * to you under the Apache License, Version 2.0 (the
 + * "License"); you may not use this file except in compliance
 + * with the License.  You may obtain a copy of the License at
 + * <p>
 + * http://www.apache.org/licenses/LICENSE-2.0
 + * <p>
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.knox.gateway.rm.dispatch;
 +
 +import org.apache.knox.gateway.ha.provider.HaDescriptor;
 +import org.apache.knox.gateway.ha.provider.HaProvider;
 +import org.apache.knox.gateway.ha.provider.HaServletContextListener;
 +import org.apache.knox.gateway.ha.provider.impl.DefaultHaProvider;
 +import org.apache.knox.gateway.ha.provider.impl.HaDescriptorFactory;
 +import org.apache.http.client.methods.HttpRequestBase;
 +import org.apache.http.client.methods.HttpUriRequest;
- import org.apache.http.impl.client.DefaultHttpClient;
 +import org.apache.http.params.BasicHttpParams;
 +import org.apache.http.entity.StringEntity;
++import org.apache.http.impl.client.CloseableHttpClient;
++import org.apache.http.impl.client.HttpClientBuilder;
 +import org.apache.http.entity.ContentType;
 +import org.apache.http.Header;
 +import org.apache.http.message.BasicHttpResponse;
 +import org.apache.http.ProtocolVersion;
 +import org.apache.http.StatusLine;
 +import org.apache.http.message.BasicStatusLine;
 +import org.apache.http.message.BasicHeader;
 +import org.easymock.EasyMock;
 +import org.easymock.IAnswer;
 +import org.junit.Assert;
 +import org.junit.Test;
 +
 +import javax.servlet.FilterConfig;
 +import javax.servlet.ServletContext;
 +import javax.servlet.WriteListener;
 +import javax.servlet.ServletOutputStream;
 +import javax.servlet.http.HttpServletRequest;
 +import javax.servlet.http.HttpServletResponse;
 +import java.io.IOException;
 +import java.net.URI;
 +import java.util.ArrayList;
 +import java.util.concurrent.atomic.AtomicInteger;
 +
 +public class RMHaDispatchTest {
 +    private static final String LOCATION = "Location";
 +
 +    @Test
 +    public void testConnectivityFailure() throws Exception {
 +        String serviceName = "RESOURCEMANAGER";
 +        HaDescriptor descriptor = HaDescriptorFactory.createDescriptor();
 +        descriptor.addServiceConfig(HaDescriptorFactory.createServiceConfig(serviceName, "true", "1", "1000", "2", "1000", null, null));
 +        HaProvider provider = new DefaultHaProvider(descriptor);
 +        URI uri1 = new URI("http://unreachable-host");
 +        URI uri2 = new URI("http://reachable-host");
 +        ArrayList<String> urlList = new ArrayList<>();
 +        urlList.add(uri1.toString());
 +        urlList.add(uri2.toString());
 +        provider.addHaService(serviceName, urlList);
 +        FilterConfig filterConfig = EasyMock.createNiceMock(FilterConfig.class);
 +        ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);
 +
 +        EasyMock.expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes();
 +        EasyMock.expect(servletContext.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME)).andReturn(provider).anyTimes();
 +
 +        BasicHttpParams params = new BasicHttpParams();
 +
 +        HttpUriRequest outboundRequest = EasyMock.createNiceMock(HttpRequestBase.class);
 +        EasyMock.expect(outboundRequest.getMethod()).andReturn("GET").anyTimes();
 +        EasyMock.expect(outboundRequest.getURI()).andReturn(uri1).anyTimes();
 +        EasyMock.expect(outboundRequest.getParams()).andReturn(params).anyTimes();
 +
 +        HttpServletRequest inboundRequest = EasyMock.createNiceMock(HttpServletRequest.class);
 +        EasyMock.expect(inboundRequest.getRequestURL()).andReturn(new StringBuffer(uri2.toString())).once();
 +        EasyMock.expect(inboundRequest.getAttribute("dispatch.ha.failover.counter")).andReturn(new AtomicInteger(0)).once();
 +        EasyMock.expect(inboundRequest.getAttribute("dispatch.ha.failover.counter")).andReturn(new AtomicInteger(1)).once();
 +
 +        HttpServletResponse outboundResponse = EasyMock.createNiceMock(HttpServletResponse.class);
 +        EasyMock.expect(outboundResponse.getOutputStream()).andAnswer(new IAnswer<ServletOutputStream>() {
 +            @Override
 +            public ServletOutputStream answer() throws Throwable {
 +                return new ServletOutputStream() {
 +                    @Override
 +                    public void write(int b) throws IOException {
 +                        throw new IOException("unreachable-host");
 +                    }
 +
 +                    @Override
 +                    public void setWriteListener(WriteListener arg0) {
 +                    }
 +
 +                    @Override
 +                    public boolean isReady() {
 +                        return false;
 +                    }
 +                };
 +            }
 +        }).once();
 +        EasyMock.replay(filterConfig, servletContext, outboundRequest, inboundRequest, outboundResponse);
 +        Assert.assertEquals(uri1.toString(), provider.getActiveURL(serviceName));
 +        RMHaDispatch dispatch = new RMHaDispatch();
-         dispatch.setHttpClient(new DefaultHttpClient());
++        HttpClientBuilder builder = HttpClientBuilder.create();
++        CloseableHttpClient client = builder.build();
++        dispatch.setHttpClient(client);
 +        dispatch.setHaProvider(provider);
 +        dispatch.init();
 +        long startTime = System.currentTimeMillis();
 +        try {
 +            dispatch.executeRequest(outboundRequest, inboundRequest, outboundResponse);
 +        } catch (IOException e) {
 +            //this is expected after the failover limit is reached
 +        }
 +        long elapsedTime = System.currentTimeMillis() - startTime;
 +        Assert.assertEquals(uri2.toString(), provider.getActiveURL(serviceName));
 +        //test to make sure the sleep took place
 +        Assert.assertTrue(elapsedTime > 1000);
 +    }
 +
 +    @Test
 +    public void testConnectivityFailover() throws Exception {
 +        String serviceName = "RESOURCEMANAGER";
 +        HaDescriptor descriptor = HaDescriptorFactory.createDescriptor();
 +        descriptor.addServiceConfig(HaDescriptorFactory.createServiceConfig(serviceName, "true", "1", "1000", "2", "1000", null, null));
 +        HaProvider provider = new DefaultHaProvider(descriptor);
 +        URI uri1 = new URI("http://passive-host");
 +        URI uri2 = new URI("http://other-host");
 +        URI uri3 = new URI("http://active-host");
 +        ArrayList<String> urlList = new ArrayList<>();
 +        urlList.add(uri1.toString());
 +        urlList.add(uri2.toString());
 +        urlList.add(uri3.toString());
 +        provider.addHaService(serviceName, urlList);
 +        FilterConfig filterConfig = EasyMock.createNiceMock(FilterConfig.class);
 +        ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);
 +
 +        EasyMock.expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes();
 +        EasyMock.expect(servletContext.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME)).andReturn(provider).anyTimes();
 +
 +
 +        BasicHttpResponse inboundResponse = EasyMock.createNiceMock(BasicHttpResponse.class);
 +        EasyMock.expect(inboundResponse.getStatusLine()).andReturn(getStatusLine()).anyTimes();
 +        EasyMock.expect(inboundResponse.getEntity()).andReturn(getResponseEntity()).anyTimes();
 +        EasyMock.expect(inboundResponse.getFirstHeader(LOCATION)).andReturn(getFirstHeader(uri3.toString())).anyTimes();
 +
 +        BasicHttpParams params = new BasicHttpParams();
 +
 +        HttpUriRequest outboundRequest = EasyMock.createNiceMock(HttpRequestBase.class);
 +        EasyMock.expect(outboundRequest.getMethod()).andReturn("GET").anyTimes();
 +        EasyMock.expect(outboundRequest.getURI()).andReturn(uri1).anyTimes();
 +        EasyMock.expect(outboundRequest.getParams()).andReturn(params).anyTimes();
 +
 +        HttpServletRequest inboundRequest = EasyMock.createNiceMock(HttpServletRequest.class);
 +        EasyMock.expect(inboundRequest.getRequestURL()).andReturn(new StringBuffer(uri2.toString())).once();
 +        EasyMock.expect(inboundRequest.getAttribute("dispatch.ha.failover.counter")).andReturn(new AtomicInteger(0)).once();
 +        EasyMock.expect(inboundRequest.getAttribute("dispatch.ha.failover.counter")).andReturn(new AtomicInteger(1)).once();
 +
 +        HttpServletResponse outboundResponse = EasyMock.createNiceMock(HttpServletResponse.class);
 +        EasyMock.expect(outboundResponse.getOutputStream()).andAnswer(new IAnswer<ServletOutputStream>() {
 +            @Override
 +            public ServletOutputStream answer() throws Throwable {
 +                return new ServletOutputStream() {
 +                    @Override
 +                    public void write(int b) throws IOException {
 +                        throw new IOException("unreachable-host");
 +                    }
 +
 +                    @Override
 +                    public void setWriteListener(WriteListener arg0) {
 +                    }
 +
 +                    @Override
 +                    public boolean isReady() {
 +                        return false;
 +                    }
 +                };
 +            }
 +        }).once();
 +        Assert.assertEquals(uri1.toString(), provider.getActiveURL(serviceName));
 +        EasyMock.replay(filterConfig, servletContext, inboundResponse, outboundRequest, inboundRequest, outboundResponse);
 +
 +        RMHaDispatch dispatch = new RMHaDispatch();
-         dispatch.setHttpClient(new DefaultHttpClient());
++        HttpClientBuilder builder = HttpClientBuilder.create();
++        CloseableHttpClient client = builder.build();
++        dispatch.setHttpClient(client);
 +        dispatch.setHaProvider(provider);
 +        dispatch.init();
 +        long startTime = System.currentTimeMillis();
 +        try {
 +            dispatch.setInboundResponse(inboundResponse);
 +            dispatch.executeRequest(outboundRequest, inboundRequest, outboundResponse);
 +        } catch (IOException e) {
 +            //this is expected after the failover limit is reached
 +        }
 +        Assert.assertEquals(uri3.toString(), dispatch.getUriFromInbound(inboundRequest, inboundResponse, null).toString());
 +        long elapsedTime = System.currentTimeMillis() - startTime;
 +        Assert.assertEquals(uri3.toString(), provider.getActiveURL(serviceName));
 +        //test to make sure the sleep took place
 +        Assert.assertTrue(elapsedTime > 1000);
 +    }
 +
 +    private StringEntity getResponseEntity() {
 +        String body = "This is standby RM";
 +        return new StringEntity(body, ContentType.TEXT_HTML);
 +    }
 +
 +    private StatusLine getStatusLine() {
 +        ProtocolVersion p = new ProtocolVersion("HTTP", 1, 1);
 +        return new BasicStatusLine(p, 307, "Code" + 307);
 +    }
 +
 +    private Header getFirstHeader(String host) {
 +        return new BasicHeader(LOCATION, host);
 +    }
 +
 +}

http://git-wip-us.apache.org/repos/asf/knox/blob/50f46e9e/gateway-service-webhdfs/src/test/java/org/apache/knox/gateway/hdfs/dispatch/WebHdfsHaDispatchTest.java
----------------------------------------------------------------------
diff --cc gateway-service-webhdfs/src/test/java/org/apache/knox/gateway/hdfs/dispatch/WebHdfsHaDispatchTest.java
index 7c03d32,0000000..6b7260b
mode 100644,000000..100644
--- a/gateway-service-webhdfs/src/test/java/org/apache/knox/gateway/hdfs/dispatch/WebHdfsHaDispatchTest.java
+++ b/gateway-service-webhdfs/src/test/java/org/apache/knox/gateway/hdfs/dispatch/WebHdfsHaDispatchTest.java
@@@ -1,105 -1,0 +1,108 @@@
 +/**
 + * Licensed to the Apache Software Foundation (ASF) under one
 + * or more contributor license agreements.  See the NOTICE file
 + * distributed with this work for additional information
 + * regarding copyright ownership.  The ASF licenses this file
 + * to you under the Apache License, Version 2.0 (the
 + * "License"); you may not use this file except in compliance
 + * with the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.knox.gateway.hdfs.dispatch;
 +
 +import org.apache.knox.gateway.ha.provider.HaDescriptor;
 +import org.apache.knox.gateway.ha.provider.HaProvider;
 +import org.apache.knox.gateway.ha.provider.HaServletContextListener;
 +import org.apache.knox.gateway.ha.provider.impl.DefaultHaProvider;
 +import org.apache.knox.gateway.ha.provider.impl.HaDescriptorFactory;
 +import org.apache.knox.gateway.servlet.SynchronousServletOutputStreamAdapter;
 +import org.apache.http.client.methods.HttpRequestBase;
 +import org.apache.http.client.methods.HttpUriRequest;
- import org.apache.http.impl.client.DefaultHttpClient;
++import org.apache.http.impl.client.CloseableHttpClient;
++import org.apache.http.impl.client.HttpClientBuilder;
 +import org.apache.http.params.BasicHttpParams;
 +import org.easymock.EasyMock;
 +import org.easymock.IAnswer;
 +import org.junit.Assert;
 +import org.junit.Test;
 +
 +import javax.servlet.FilterConfig;
 +import javax.servlet.ServletContext;
 +import javax.servlet.http.HttpServletRequest;
 +import javax.servlet.http.HttpServletResponse;
 +import java.io.IOException;
 +import java.net.URI;
 +import java.util.ArrayList;
 +import java.util.concurrent.atomic.AtomicInteger;
 +
 +public class WebHdfsHaDispatchTest {
 +
 +   @Test
 +   public void testConnectivityFailover() throws Exception {
 +      String serviceName = "WEBHDFS";
 +      HaDescriptor descriptor = HaDescriptorFactory.createDescriptor();
 +      descriptor.addServiceConfig(HaDescriptorFactory.createServiceConfig(serviceName, "true", "1", "1000", "2", "1000", null, null));
 +      HaProvider provider = new DefaultHaProvider(descriptor);
 +      URI uri1 = new URI( "http://unreachable-host" );
 +      URI uri2 = new URI( "http://reachable-host" );
 +      ArrayList<String> urlList = new ArrayList<String>();
 +      urlList.add(uri1.toString());
 +      urlList.add(uri2.toString());
 +      provider.addHaService(serviceName, urlList);
 +      FilterConfig filterConfig = EasyMock.createNiceMock(FilterConfig.class);
 +      ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);
 +
 +      EasyMock.expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes();
 +      EasyMock.expect(servletContext.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME)).andReturn(provider).anyTimes();
 +
 +      BasicHttpParams params = new BasicHttpParams();
 +
 +      HttpUriRequest outboundRequest = EasyMock.createNiceMock(HttpRequestBase.class);
 +      EasyMock.expect(outboundRequest.getMethod()).andReturn( "GET" ).anyTimes();
 +      EasyMock.expect(outboundRequest.getURI()).andReturn( uri1  ).anyTimes();
 +      EasyMock.expect(outboundRequest.getParams()).andReturn( params ).anyTimes();
 +
 +      HttpServletRequest inboundRequest = EasyMock.createNiceMock(HttpServletRequest.class);
 +      EasyMock.expect(inboundRequest.getRequestURL()).andReturn( new StringBuffer(uri2.toString()) ).once();
 +      EasyMock.expect(inboundRequest.getAttribute("dispatch.ha.failover.counter")).andReturn(new AtomicInteger(0)).once();
 +      EasyMock.expect(inboundRequest.getAttribute("dispatch.ha.failover.counter")).andReturn(new AtomicInteger(1)).once();
 +
 +      HttpServletResponse outboundResponse = EasyMock.createNiceMock(HttpServletResponse.class);
 +      EasyMock.expect(outboundResponse.getOutputStream()).andAnswer( new IAnswer<SynchronousServletOutputStreamAdapter>() {
 +         @Override
 +         public SynchronousServletOutputStreamAdapter answer() throws Throwable {
 +            return new SynchronousServletOutputStreamAdapter() {
 +               @Override
 +               public void write( int b ) throws IOException {
 +                  throw new IOException( "unreachable-host" );
 +               }
 +            };
 +         }
 +      }).once();
 +      EasyMock.replay(filterConfig, servletContext, outboundRequest, inboundRequest, outboundResponse);
 +      Assert.assertEquals(uri1.toString(), provider.getActiveURL(serviceName));
 +      WebHdfsHaDispatch dispatch = new WebHdfsHaDispatch();
-       dispatch.setHttpClient(new DefaultHttpClient());
++      HttpClientBuilder builder = HttpClientBuilder.create();
++      CloseableHttpClient client = builder.build();
++      dispatch.setHttpClient(client);
 +      dispatch.setHaProvider(provider);
 +      dispatch.init();
 +      long startTime = System.currentTimeMillis();
 +      try {
 +         dispatch.executeRequest(outboundRequest, inboundRequest, outboundResponse);
 +      } catch (IOException e) {
 +        //this is expected after the failover limit is reached
 +      }
 +      long elapsedTime = System.currentTimeMillis() - startTime;
 +      Assert.assertEquals(uri2.toString(), provider.getActiveURL(serviceName));
 +      //test to make sure the sleep took place
 +      Assert.assertTrue(elapsedTime > 1000);
 +   }
 +}

http://git-wip-us.apache.org/repos/asf/knox/blob/50f46e9e/gateway-spi/src/main/java/org/apache/knox/gateway/security/SubjectUtils.java
----------------------------------------------------------------------
diff --cc gateway-spi/src/main/java/org/apache/knox/gateway/security/SubjectUtils.java
index b630750,0000000..3fc51ee
mode 100644,000000..100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/security/SubjectUtils.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/security/SubjectUtils.java
@@@ -1,96 -1,0 +1,96 @@@
 +/**
 + * Licensed to the Apache Software Foundation (ASF) under one
 + * or more contributor license agreements.  See the NOTICE file
 + * distributed with this work for additional information
 + * regarding copyright ownership.  The ASF licenses this file
 + * to you under the Apache License, Version 2.0 (the
 + * "License"); you may not use this file except in compliance
 + * with the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.knox.gateway.security;
 +
 +import javax.security.auth.Subject;
 +import java.security.AccessController;
 +import java.security.Principal;
 +import java.util.Set;
 +
 +/**
 + * General utility methods for interrogating the standard java Subject
 + */
 +public class SubjectUtils {
 +  
 +  public static Subject getCurrentSubject() {
 +    return Subject.getSubject( AccessController.getContext() );
 +  }
 +
 +  public static String getPrimaryPrincipalName(Subject subject) {
 +    String name = null;
 +
 +    Set<PrimaryPrincipal> primaryPrincipals = subject.getPrincipals(PrimaryPrincipal.class);
-     if (primaryPrincipals.size() > 0) {
++    if (!primaryPrincipals.isEmpty()) {
 +      return ((PrimaryPrincipal)primaryPrincipals.toArray()[0]).getName();
 +    }
 +
 +    // LJM TODO: this implementation assumes the first one found.
 +    // We should configure through context param based on knowledge
 +    // of the authentication provider in use
 +    Set<Principal> principals = subject.getPrincipals();
 +    for (Principal p : principals) {
 +      name = p.getName();
 +      break;
 +    }
 +    
 +    return name;
 +  }
 +  
 +  public static boolean isImpersonating(Subject subject) {
 +    boolean impersonating = false;
 +    
 +    impersonating = (subject.getPrincipals(ImpersonatedPrincipal.class).size() > 0);
 +    
 +    return impersonating;
 +  }
 +
 +  public static String getImpersonatedPrincipalName(Subject subject) {
 +    String name = null;
 +
 +    Set<ImpersonatedPrincipal> impPrincipals = subject.getPrincipals(ImpersonatedPrincipal.class);
-     if (impPrincipals.size() > 0) {
++    if (!impPrincipals.isEmpty()) {
 +      return ((Principal)impPrincipals.toArray()[0]).getName();
 +    }
 +    
 +    return name;
 +  }
 +  
 +  public static String getEffectivePrincipalName(Subject subject) {
 +    String name = null;
 +    
 +    name = getImpersonatedPrincipalName(subject);
 +    if (name == null) {
 +      name = getPrimaryPrincipalName(subject);
 +    }
 +    
 +    return name;
 +  }
 +
 +  public static String getCurrentEffectivePrincipalName() {
 +    String name = null;
 +    Subject subject = getCurrentSubject();
 +    if( subject != null ) {
 +      name = getImpersonatedPrincipalName( subject );
 +      if (name == null) {
 +        name = getPrimaryPrincipalName(subject);
 +      }
 +    }
 +    return name;
 +  }
 +
 +}

http://git-wip-us.apache.org/repos/asf/knox/blob/50f46e9e/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/DefaultDispatchTest.java
----------------------------------------------------------------------
diff --cc gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/DefaultDispatchTest.java
index 4c71abb,0000000..99e3a33
mode 100644,000000..100644
--- a/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/DefaultDispatchTest.java
+++ b/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/DefaultDispatchTest.java
@@@ -1,234 -1,0 +1,244 @@@
 +/**
 + * Licensed to the Apache Software Foundation (ASF) under one
 + * or more contributor license agreements.  See the NOTICE file
 + * distributed with this work for additional information
 + * regarding copyright ownership.  The ASF licenses this file
 + * to you under the Apache License, Version 2.0 (the
 + * "License"); you may not use this file except in compliance
 + * with the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.knox.gateway.dispatch;
 +
 +import static org.hamcrest.CoreMatchers.is;
 +import static org.hamcrest.Matchers.containsString;
 +import static org.hamcrest.Matchers.greaterThan;
 +import static org.hamcrest.Matchers.instanceOf;
 +import static org.hamcrest.Matchers.not;
 +import static org.junit.Assert.assertFalse;
 +import static org.junit.Assert.assertTrue;
 +import static org.junit.Assert.assertEquals;
 +import static org.junit.Assert.assertThat;
 +import static org.junit.Assert.fail;
 +
 +import java.io.IOException;
 +import java.net.URI;
 +import java.net.URISyntaxException;
 +import java.net.UnknownHostException;
 +
 +import javax.servlet.ServletContext;
 +import javax.servlet.ServletInputStream;
 +import javax.servlet.http.HttpServletRequest;
 +import javax.servlet.http.HttpServletResponse;
 +
 +import org.apache.knox.gateway.config.GatewayConfig;
 +import org.apache.knox.gateway.servlet.SynchronousServletOutputStreamAdapter;
 +import org.apache.hadoop.test.TestUtils;
 +import org.apache.hadoop.test.category.FastTests;
 +import org.apache.hadoop.test.category.UnitTests;
 +import org.apache.http.HttpEntity;
++import org.apache.http.HttpVersion;
++import org.apache.http.RequestLine;
 +import org.apache.http.client.methods.HttpUriRequest;
- import org.apache.http.impl.client.DefaultHttpClient;
++import org.apache.http.impl.client.CloseableHttpClient;
++import org.apache.http.impl.client.HttpClientBuilder;
 +import org.apache.http.params.BasicHttpParams;
 +import org.easymock.EasyMock;
 +import org.easymock.IAnswer;
 +import org.junit.Test;
 +import org.junit.experimental.categories.Category;
 +
 +@Category( { UnitTests.class, FastTests.class } )
 +public class DefaultDispatchTest {
 +
 +  // Make sure Hadoop cluster topology isn't exposed to client when there is a connectivity issue.
 +  @Test
 +  public void testJiraKnox58() throws URISyntaxException, IOException {
 +
 +    URI uri = new URI( "http://unreachable-host" );
 +    BasicHttpParams params = new BasicHttpParams();
 +
 +    HttpUriRequest outboundRequest = EasyMock.createNiceMock( HttpUriRequest.class );
 +    EasyMock.expect( outboundRequest.getMethod() ).andReturn( "GET" ).anyTimes();
 +    EasyMock.expect( outboundRequest.getURI() ).andReturn( uri  ).anyTimes();
++
++    RequestLine requestLine = EasyMock.createNiceMock( RequestLine.class );
++    EasyMock.expect( requestLine.getMethod() ).andReturn( "GET" ).anyTimes();
++    EasyMock.expect( requestLine.getProtocolVersion() ).andReturn( HttpVersion.HTTP_1_1 ).anyTimes();
++    EasyMock.expect( outboundRequest.getRequestLine() ).andReturn( requestLine ).anyTimes();
 +    EasyMock.expect( outboundRequest.getParams() ).andReturn( params ).anyTimes();
 +
 +    HttpServletRequest inboundRequest = EasyMock.createNiceMock( HttpServletRequest.class );
 +
 +    HttpServletResponse outboundResponse = EasyMock.createNiceMock( HttpServletResponse.class );
 +    EasyMock.expect( outboundResponse.getOutputStream() ).andAnswer( new IAnswer<SynchronousServletOutputStreamAdapter>() {
 +      @Override
 +      public SynchronousServletOutputStreamAdapter answer() throws Throwable {
 +        return new SynchronousServletOutputStreamAdapter() {
 +          @Override
 +          public void write( int b ) throws IOException {
 +            throw new IOException( "unreachable-host" );
 +          }
 +        };
 +      }
 +    });
 +
-     EasyMock.replay( outboundRequest, inboundRequest, outboundResponse );
++    EasyMock.replay( outboundRequest, inboundRequest, outboundResponse, requestLine );
 +
 +    DefaultDispatch dispatch = new DefaultDispatch();
-     dispatch.setHttpClient(new DefaultHttpClient());
++    HttpClientBuilder builder = HttpClientBuilder.create();
++    CloseableHttpClient client = builder.build();
++    dispatch.setHttpClient(client);
 +    try {
 +      dispatch.executeRequest( outboundRequest, inboundRequest, outboundResponse );
 +      fail( "Should have thrown IOException" );
 +    } catch( IOException e ) {
 +      assertThat( e.getMessage(), not( containsString( "unreachable-host" ) ) );
 +      assertThat( e, not( instanceOf( UnknownHostException.class ) ) ) ;
 +      assertThat( "Message needs meaningful content.", e.getMessage().trim().length(), greaterThan( 12 ) );
 +    }
 +  }
 +
 +  @Test
 +  public void testCallToSecureClusterWithDelegationToken() throws URISyntaxException, IOException {
 +    DefaultDispatch defaultDispatch = new DefaultDispatch();
 +    ServletContext servletContext = EasyMock.createNiceMock( ServletContext.class );
 +    GatewayConfig gatewayConfig = EasyMock.createNiceMock( GatewayConfig.class );
 +    EasyMock.expect(gatewayConfig.isHadoopKerberosSecured()).andReturn(true).anyTimes();
 +    EasyMock.expect( servletContext.getAttribute( GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE ) ).andReturn( gatewayConfig ).anyTimes();
 +    ServletInputStream inputStream = EasyMock.createNiceMock( ServletInputStream.class );
 +    HttpServletRequest inboundRequest = EasyMock.createNiceMock( HttpServletRequest.class );
 +    EasyMock.expect(inboundRequest.getQueryString()).andReturn( "delegation=123").anyTimes();
 +    EasyMock.expect(inboundRequest.getInputStream()).andReturn( inputStream).anyTimes();
 +    EasyMock.expect(inboundRequest.getServletContext()).andReturn( servletContext ).anyTimes();
 +    EasyMock.replay( gatewayConfig, servletContext, inboundRequest );
 +    HttpEntity httpEntity = defaultDispatch.createRequestEntity(inboundRequest);
 +    assertFalse("buffering in the presence of delegation token",
 +        (httpEntity instanceof PartiallyRepeatableHttpEntity));
 +  }
 +
 +  @Test
 +  public void testCallToNonSecureClusterWithoutDelegationToken() throws URISyntaxException, IOException {
 +    DefaultDispatch defaultDispatch = new DefaultDispatch();
 +    ServletContext servletContext = EasyMock.createNiceMock( ServletContext.class );
 +    GatewayConfig gatewayConfig = EasyMock.createNiceMock( GatewayConfig.class );
 +    EasyMock.expect(gatewayConfig.isHadoopKerberosSecured()).andReturn(false).anyTimes();
 +    EasyMock.expect( servletContext.getAttribute( GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE ) ).andReturn( gatewayConfig ).anyTimes();
 +    ServletInputStream inputStream = EasyMock.createNiceMock( ServletInputStream.class );
 +    HttpServletRequest inboundRequest = EasyMock.createNiceMock( HttpServletRequest.class );
 +    EasyMock.expect(inboundRequest.getInputStream()).andReturn( inputStream).anyTimes();
 +    EasyMock.expect(inboundRequest.getQueryString()).andReturn( "a=123").anyTimes();
 +    EasyMock.expect(inboundRequest.getServletContext()).andReturn( servletContext ).anyTimes();
 +    EasyMock.replay( gatewayConfig, servletContext, inboundRequest );
 +    HttpEntity httpEntity = defaultDispatch.createRequestEntity(inboundRequest);
 +    assertFalse("buffering in non secure cluster",
 +        (httpEntity instanceof PartiallyRepeatableHttpEntity));
 +  }
 +
 +  @Test
 +  public void testCallToSecureClusterWithoutDelegationToken() throws URISyntaxException, IOException {
 +    DefaultDispatch defaultDispatch = new DefaultDispatch();
 +    defaultDispatch.setReplayBufferSize(10);
 +    ServletContext servletContext = EasyMock.createNiceMock( ServletContext.class );
 +    GatewayConfig gatewayConfig = EasyMock.createNiceMock( GatewayConfig.class );
 +    EasyMock.expect(gatewayConfig.isHadoopKerberosSecured()).andReturn( Boolean.TRUE ).anyTimes();
 +    EasyMock.expect( servletContext.getAttribute( GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE ) ).andReturn( gatewayConfig ).anyTimes();
 +    ServletInputStream inputStream = EasyMock.createNiceMock( ServletInputStream.class );
 +    HttpServletRequest inboundRequest = EasyMock.createNiceMock( HttpServletRequest.class );
 +    EasyMock.expect(inboundRequest.getQueryString()).andReturn( "a=123").anyTimes();
 +    EasyMock.expect(inboundRequest.getInputStream()).andReturn( inputStream).anyTimes();
 +    EasyMock.expect(inboundRequest.getServletContext()).andReturn( servletContext ).anyTimes();
 +    EasyMock.replay( gatewayConfig, servletContext, inboundRequest );
 +    HttpEntity httpEntity = defaultDispatch.createRequestEntity(inboundRequest);
 +    assertTrue("not buffering in the absence of delegation token",
 +        (httpEntity instanceof PartiallyRepeatableHttpEntity));
 +  }
 +
 +  @Test
 +  public void testUsingDefaultBufferSize() throws URISyntaxException, IOException {
 +    DefaultDispatch defaultDispatch = new DefaultDispatch();
 +    ServletContext servletContext = EasyMock.createNiceMock( ServletContext.class );
 +    GatewayConfig gatewayConfig = EasyMock.createNiceMock( GatewayConfig.class );
 +    EasyMock.expect(gatewayConfig.isHadoopKerberosSecured()).andReturn( Boolean.TRUE ).anyTimes();
 +    EasyMock.expect(gatewayConfig.getHttpServerRequestBuffer()).andReturn( 16384 ).anyTimes();
 +    EasyMock.expect( servletContext.getAttribute( GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE ) ).andReturn( gatewayConfig ).anyTimes();
 +    ServletInputStream inputStream = EasyMock.createNiceMock( ServletInputStream.class );
 +    HttpServletRequest inboundRequest = EasyMock.createNiceMock( HttpServletRequest.class );
 +    EasyMock.expect(inboundRequest.getQueryString()).andReturn( "a=123").anyTimes();
 +    EasyMock.expect(inboundRequest.getInputStream()).andReturn( inputStream).anyTimes();
 +    EasyMock.expect(inboundRequest.getServletContext()).andReturn( servletContext ).anyTimes();
 +    EasyMock.replay( gatewayConfig, servletContext, inboundRequest );
 +    HttpEntity httpEntity = defaultDispatch.createRequestEntity(inboundRequest);
 +    assertTrue("not buffering in the absence of delegation token",
 +        (httpEntity instanceof PartiallyRepeatableHttpEntity));
 +    assertEquals(defaultDispatch.getReplayBufferSize(), 16);
 +    assertEquals(defaultDispatch.getReplayBufferSizeInBytes(), 16384);
 +
 +    //also test normal setter and getters
 +    defaultDispatch.setReplayBufferSize(-1);
 +    assertEquals(defaultDispatch.getReplayBufferSizeInBytes(), -1);
 +    assertEquals(defaultDispatch.getReplayBufferSize(), -1);
 +
 +    defaultDispatch.setReplayBufferSize(16);
 +    assertEquals(defaultDispatch.getReplayBufferSizeInBytes(), 16384);
 +    assertEquals(defaultDispatch.getReplayBufferSize(), 16);
 +
 +  }
 +
 +  @Test( timeout = TestUtils.SHORT_TIMEOUT )
 +  public void testGetDispatchUrl() throws Exception {
 +    HttpServletRequest request;
 +    Dispatch dispatch;
 +    String path;
 +    String query;
 +    URI uri;
 +
 +    dispatch = new DefaultDispatch();
 +
 +    path = "http://test-host:42/test-path";
 +    request = EasyMock.createNiceMock( HttpServletRequest.class );
 +    EasyMock.expect( request.getRequestURI() ).andReturn( path ).anyTimes();
 +    EasyMock.expect( request.getRequestURL() ).andReturn( new StringBuffer( path ) ).anyTimes();
 +    EasyMock.expect( request.getQueryString() ).andReturn( null ).anyTimes();
 +    EasyMock.replay( request );
 +    uri = dispatch.getDispatchUrl( request );
 +    assertThat( uri.toASCIIString(), is( "http://test-host:42/test-path" ) );
 +
 +    path = "http://test-host:42/test,path";
 +    request = EasyMock.createNiceMock( HttpServletRequest.class );
 +    EasyMock.expect( request.getRequestURI() ).andReturn( path ).anyTimes();
 +    EasyMock.expect( request.getRequestURL() ).andReturn( new StringBuffer( path ) ).anyTimes();
 +    EasyMock.expect( request.getQueryString() ).andReturn( null ).anyTimes();
 +    EasyMock.replay( request );
 +    uri = dispatch.getDispatchUrl( request );
 +    assertThat( uri.toASCIIString(), is( "http://test-host:42/test,path" ) );
 +
 +    path = "http://test-host:42/test%2Cpath";
 +    request = EasyMock.createNiceMock( HttpServletRequest.class );
 +    EasyMock.expect( request.getRequestURI() ).andReturn( path ).anyTimes();
 +    EasyMock.expect( request.getRequestURL() ).andReturn( new StringBuffer( path ) ).anyTimes();
 +    EasyMock.expect( request.getQueryString() ).andReturn( null ).anyTimes();
 +    EasyMock.replay( request );
 +    uri = dispatch.getDispatchUrl( request );
 +    assertThat( uri.toASCIIString(), is( "http://test-host:42/test%2Cpath" ) );
 +
 +    path = "http://test-host:42/test%2Cpath";
 +    query = "test%26name=test%3Dvalue";
 +    request = EasyMock.createNiceMock( HttpServletRequest.class );
 +    EasyMock.expect( request.getRequestURI() ).andReturn( path ).anyTimes();
 +    EasyMock.expect( request.getRequestURL() ).andReturn( new StringBuffer( path ) ).anyTimes();
 +    EasyMock.expect( request.getQueryString() ).andReturn( query ).anyTimes();
 +    EasyMock.replay( request );
 +    uri = dispatch.getDispatchUrl( request );
 +    assertThat( uri.toASCIIString(), is( "http://test-host:42/test%2Cpath?test%26name=test%3Dvalue" ) );
 +
 +  }
 +
 +}

http://git-wip-us.apache.org/repos/asf/knox/blob/50f46e9e/gateway-spi/src/test/java/org/apache/knox/gateway/security/principal/PrincipalMapperTest.java
----------------------------------------------------------------------
diff --cc gateway-spi/src/test/java/org/apache/knox/gateway/security/principal/PrincipalMapperTest.java
index 1be93c3,0000000..cba7f1c
mode 100644,000000..100644
--- a/gateway-spi/src/test/java/org/apache/knox/gateway/security/principal/PrincipalMapperTest.java
+++ b/gateway-spi/src/test/java/org/apache/knox/gateway/security/principal/PrincipalMapperTest.java
@@@ -1,232 -1,0 +1,232 @@@
 +/**
 + * Licensed to the Apache Software Foundation (ASF) under one
 + * or more contributor license agreements.  See the NOTICE file
 + * distributed with this work for additional information
 + * regarding copyright ownership.  The ASF licenses this file
 + * to you under the Apache License, Version 2.0 (the
 + * "License"); you may not use this file except in compliance
 + * with the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.knox.gateway.security.principal;
 +
 +import org.apache.hadoop.test.category.FastTests;
 +import org.apache.hadoop.test.category.UnitTests;
 +import org.junit.Before;
 +import org.junit.Test;
 +import org.junit.experimental.categories.Category;
 +
 +import static org.junit.Assert.assertTrue;
 +import static org.junit.Assert.fail;
 +
 +/**
 +*
 +*/
 +@Category( { UnitTests.class, FastTests.class } )
 +public class PrincipalMapperTest {
 +  PrincipalMapper mapper;
 +
 +  @Before
 +  public void setup() {
 +    mapper = new SimplePrincipalMapper();
 +  }
 +
 +  @Test
 +  public void testSimplePrincipalMappingWithWildcardGroups() {
 +    String principalMapping = "";
 +    String groupMapping = "*=users";
 +    try {
 +      mapper.loadMappingTable(principalMapping, groupMapping);
 +    }
 +    catch (PrincipalMappingException pme) {
 +      pme.printStackTrace();
 +      fail();
 +    }
 +    
 +    assertTrue(mapper.mapUserPrincipal("lmccay").equals("lmccay"));
 +    assertTrue(mapper.mapGroupPrincipal("hdfs")[0].equals("users"));
 +    assertTrue(mapper.mapGroupPrincipal("lmccay")[0].equals("users"));
 +  }
 +  
 +  @Test
 +  public void testSimplePrincipalMappingWithWildcardAndExplicitGroups() {
 +    String principalMapping = "";
 +    String groupMapping = "*=users;lmccay=mrgroup";
 +    try {
 +      mapper.loadMappingTable(principalMapping, groupMapping);
 +    }
 +    catch (PrincipalMappingException pme) {
 +      pme.printStackTrace();
 +      fail();
 +    }
 +    
 +    assertTrue(mapper.mapUserPrincipal("lmccay").equals("lmccay"));
 +    assertTrue(mapper.mapGroupPrincipal("hdfs")[0].equals("users"));
 +    String group = mapper.mapGroupPrincipal("lmccay")[0];
-     assertTrue(group.equals("users") || group.equals("mrgroup"));
++    assertTrue("users".equals(group) || "mrgroup".equals(group));
 +    group = mapper.mapGroupPrincipal("lmccay")[1];
-     assertTrue(group.equals("users") || group.equals("mrgroup"));
++    assertTrue("users".equals(group) || "mrgroup".equals(group));
 +  }
 +
 +  @Test
 +  public void testSimplePrincipalMappingWithUserAndWildcardAndExplicitGroups() {
 +    String principalMapping = "guest=lmccay";
 +    String groupMapping = "*=users;lmccay=mrgroup";
 +    try {
 +      mapper.loadMappingTable(principalMapping, groupMapping);
 +    }
 +    catch (PrincipalMappingException pme) {
 +      pme.printStackTrace();
 +      fail();
 +    }
 +    
 +    assertTrue(mapper.mapUserPrincipal("guest").equals("lmccay"));
 +    assertTrue(mapper.mapGroupPrincipal("hdfs").length == 1);
 +    assertTrue(mapper.mapGroupPrincipal("hdfs")[0].equals("users"));
 +    assertTrue(mapper.mapGroupPrincipal("lmccay").length == 2);
 +    String group = mapper.mapGroupPrincipal("lmccay")[0];
-     assertTrue(group.equals("users") || group.equals("mrgroup"));
++    assertTrue("users".equals(group) || "mrgroup".equals(group));
 +    group = mapper.mapGroupPrincipal("lmccay")[1];
-     assertTrue(group.equals("users") || group.equals("mrgroup"));
++    assertTrue("users".equals(group) || "mrgroup".equals(group));
 +  }
 +
 +  @Test
 +  public void testNonNullSimplePrincipalMappingWithGroups() {
 +    String principalMapping = "lmccay,kminder=hdfs;newuser=mapred";
 +    String groupMapping = "hdfs=group1;mapred=mrgroup,mrducks";
 +    try {
 +      mapper.loadMappingTable(principalMapping, groupMapping);
 +    }
 +    catch (PrincipalMappingException pme) {
 +      pme.printStackTrace();
 +      fail();
 +    }
 +    
 +    assertTrue(mapper.mapUserPrincipal("lmccay").equals("hdfs"));
 +    assertTrue(mapper.mapGroupPrincipal("hdfs")[0].equals("group1"));
 +
 +    assertTrue(mapper.mapUserPrincipal("kminder").equals("hdfs"));
 +    
 +    assertTrue(mapper.mapUserPrincipal("newuser").equals("mapred"));
 +    assertTrue(mapper.mapGroupPrincipal("mapred")[0].equals("mrgroup"));
 +    assertTrue(mapper.mapGroupPrincipal("mapred")[1].equals("mrducks"));
 +
 +    assertTrue(mapper.mapUserPrincipal("hdfs").equals("hdfs"));
 +    assertTrue(mapper.mapUserPrincipal("mapred").equals("mapred"));
 +
 +    assertTrue(mapper.mapUserPrincipal("stink").equals("stink"));
 +  }
 +
 +  @Test
 +  public void testNonNullSimplePrincipalMapping() {
 +    String principalMapping = "lmccay,kminder=hdfs;newuser=mapred";
 +    try {
 +      mapper.loadMappingTable(principalMapping, null);
 +    }
 +    catch (PrincipalMappingException pme) {
 +      pme.printStackTrace();
 +      fail();
 +    }
 +    
 +    assertTrue(mapper.mapUserPrincipal("lmccay").equals("hdfs"));
 +    assertTrue(mapper.mapUserPrincipal("kminder").equals("hdfs"));
 +    
 +    assertTrue(mapper.mapUserPrincipal("newuser").equals("mapred"));
 +
 +    assertTrue(mapper.mapUserPrincipal("hdfs").equals("hdfs"));
 +    assertTrue(mapper.mapUserPrincipal("mapred").equals("mapred"));
 +
 +    assertTrue(mapper.mapUserPrincipal("stink").equals("stink"));
 +  }
 +
 +  @Test
 +  public void testNonNullEndingSemiColonSimplePrincipalMapping() {
 +    String principalMapping = "lmccay,kminder=hdfs;newuser=mapred;";
 +    try {
 +      mapper.loadMappingTable(principalMapping, null);
 +    }
 +    catch (PrincipalMappingException pme) {
 +      fail();
 +    }
 +    
 +    assertTrue(mapper.mapUserPrincipal("lmccay").equals("hdfs"));
 +    assertTrue(mapper.mapUserPrincipal("kminder").equals("hdfs"));
 +    
 +    assertTrue(mapper.mapUserPrincipal("newuser").equals("mapred"));
 +
 +    assertTrue(mapper.mapUserPrincipal("hdfs").equals("hdfs"));
 +    assertTrue(mapper.mapUserPrincipal("mapred").equals("mapred"));
 +
 +    assertTrue(mapper.mapUserPrincipal("stink").equals("stink"));
 +  }
 +
 +  @Test
 +  public void testNullSimplePrincipalMapping() {
 +    String principalMapping = null;
 +    try {
 +      mapper.loadMappingTable(principalMapping, null);
 +    }
 +    catch (PrincipalMappingException pme) {
 +      fail();
 +    }
 +    
 +    assertTrue(mapper.mapUserPrincipal("lmccay").equals("lmccay"));
 +    assertTrue(mapper.mapUserPrincipal("kminder").equals("kminder"));
 +    
 +    assertTrue(mapper.mapUserPrincipal("newuser").equals("newuser"));
 +
 +    assertTrue(mapper.mapUserPrincipal("hdfs").equals("hdfs"));
 +    assertTrue(mapper.mapUserPrincipal("mapred").equals("mapred"));
 +
 +    assertTrue(mapper.mapUserPrincipal("stink").equals("stink"));
 +  }
 +
 +  @Test
 +  public void testInvalidSimplePrincipalMapping() {
 +    String principalMapping = "ksdlhfjkdshf;kjdshf";
 +    try {
 +      mapper.loadMappingTable(principalMapping, null);
 +    }
 +    catch (PrincipalMappingException pme) {
 +      // expected
 +    }
 +    
 +    assertTrue(mapper.mapUserPrincipal("lmccay").equals("lmccay"));
 +    assertTrue(mapper.mapUserPrincipal("kminder").equals("kminder"));
 +    
 +    assertTrue(mapper.mapUserPrincipal("newuser").equals("newuser"));
 +
 +    assertTrue(mapper.mapUserPrincipal("hdfs").equals("hdfs"));
 +    assertTrue(mapper.mapUserPrincipal("mapred").equals("mapred"));
 +
 +    assertTrue(mapper.mapUserPrincipal("stink").equals("stink"));
 +  }
 +
 +  @Test
 +  public void testPartiallyInvalidSimplePrincipalMapping() {
 +    String principalMapping = "lmccay=hdfs;kjdshf";
 +    try {
 +      mapper.loadMappingTable(principalMapping, null);
 +    }
 +    catch (PrincipalMappingException pme) {
 +      // expected
 +    }
 +    
 +    assertTrue(mapper.mapUserPrincipal("lmccay").equals("lmccay"));
 +    assertTrue(mapper.mapUserPrincipal("kminder").equals("kminder"));
 +    
 +    assertTrue(mapper.mapUserPrincipal("newuser").equals("newuser"));
 +
 +    assertTrue(mapper.mapUserPrincipal("hdfs").equals("hdfs"));
 +    assertTrue(mapper.mapUserPrincipal("mapred").equals("mapred"));
 +
 +    assertTrue(mapper.mapUserPrincipal("stink").equals("stink"));
 +  }
 +}

http://git-wip-us.apache.org/repos/asf/knox/blob/50f46e9e/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
----------------------------------------------------------------------
diff --cc gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
index 49d697b,0000000..e7512b3
mode 100644,000000..100644
--- a/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
+++ b/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
@@@ -1,610 -1,0 +1,612 @@@
 +/**
 + * Licensed to the Apache Software Foundation (ASF) under one
 + * or more contributor license agreements.  See the NOTICE file
 + * distributed with this work for additional information
 + * regarding copyright ownership.  The ASF licenses this file
 + * to you under the Apache License, Version 2.0 (the
 + * "License"); you may not use this file except in compliance
 + * with the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.knox.gateway;
 +
 +import org.apache.commons.lang.StringUtils;
 +import org.apache.hadoop.conf.Configuration;
 +import org.apache.knox.gateway.config.GatewayConfig;
 +
++import java.io.File;
 +import java.net.InetSocketAddress;
 +import java.net.UnknownHostException;
 +import java.util.ArrayList;
 +import java.util.List;
 +import java.util.Map;
 +import java.util.concurrent.ConcurrentHashMap;
 +
 +public class GatewayTestConfig extends Configuration implements GatewayConfig {
 +
 +  /* Websocket defaults */
 +  public static final boolean DEFAULT_WEBSOCKET_FEATURE_ENABLED = false;
 +  public static final int DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_SIZE = Integer.MAX_VALUE;;
 +  public static final int DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_SIZE = Integer.MAX_VALUE;;
 +  public static final int DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_BUFFER_SIZE = 32768;
 +  public static final int DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_BUFFER_SIZE = 32768;
 +  public static final int DEFAULT_WEBSOCKET_INPUT_BUFFER_SIZE = 4096;
 +  public static final int DEFAULT_WEBSOCKET_ASYNC_WRITE_TIMEOUT = 60000;
 +  public static final int DEFAULT_WEBSOCKET_IDLE_TIMEOUT = 300000;
 +
 +  private String gatewayHomeDir = "gateway-home";
 +  private String hadoopConfDir = "hadoop";
 +  private String gatewayHost = "localhost";
 +  private int gatewayPort = 0;
 +  private String gatewayPath = "gateway";
 +  private boolean hadoopKerberosSecured = false;
 +  private String kerberosConfig = "/etc/knox/conf/krb5.conf";
 +  private boolean kerberosDebugEnabled = false;
 +  private String kerberosLoginConfig = "/etc/knox/conf/krb5JAASLogin.conf";
 +  private String frontendUrl = null;
 +  private boolean xForwardedEnabled = true;
 +  private String gatewayApplicationsDir = null;
 +  private String gatewayServicesDir;
 +  private String defaultTopologyName = "default";
 +  private List<String> includedSSLCiphers = null;
 +  private List<String> excludedSSLCiphers = null;
 +  private boolean sslEnabled = false;
 +  private String truststoreType = "jks";
 +  private String keystoreType = "jks";
 +  private boolean isTopologyPortMappingEnabled = true;
 +  private ConcurrentHashMap<String, Integer> topologyPortMapping = new ConcurrentHashMap<>();
 +  private int backupVersionLimit = -1;
 +  private long backupAgeLimit = -1;
 +
 +  public void setGatewayHomeDir( String gatewayHomeDir ) {
 +    this.gatewayHomeDir = gatewayHomeDir;
 +  }
 +
 +  public String getGatewayHomeDir() {
 +    return this.gatewayHomeDir;
 +  }
 +
 +  @Override
 +  public String getGatewayConfDir() {
 +    return gatewayHomeDir;
 +  }
 +
 +  @Override
 +  public String getGatewayDataDir() {
 +    return gatewayHomeDir;
 +  }
 +
 +  @Override
 +  public String getGatewaySecurityDir() {
 +    return gatewayHomeDir + "/security";
 +  }
 +
 +  @Override
 +  public String getGatewayTopologyDir() {
 +    return gatewayHomeDir + "/topologies";
 +  }
 +
 +  @Override
 +  public String getGatewayDeploymentDir() {
 +    return gatewayHomeDir + "/deployments";
 +  }
 +
 +//  public void setDeploymentDir( String clusterConfDir ) {
 +//    this.deployDir = clusterConfDir;
 +//  }
 +
 +  @Override
 +  public String getHadoopConfDir() {
 +    return hadoopConfDir;
 +  }
 +
 +//  public void setHadoopConfDir( String hadoopConfDir ) {
 +//    this.hadoopConfDir = hadoopConfDir;
 +//  }
 +
 +  @Override
 +  public String getGatewayHost() {
 +    return gatewayHost;
 +  }
 +
 +//  public void setGatewayHost( String gatewayHost ) {
 +//    this.gatewayHost = gatewayHost;
 +//  }
 +
 +  @Override
 +  public int getGatewayPort() {
 +    return gatewayPort;
 +  }
 +
 +//  public void setGatewayPort( int gatewayPort ) {
 +//    this.gatewayPort = gatewayPort;
 +//  }
 +
 +  @Override
 +  public String getGatewayPath() {
 +    return gatewayPath;
 +  }
 +
 +  public void setGatewayPath( String gatewayPath ) {
 +    this.gatewayPath = gatewayPath;
 +  }
 +
 +  @Override
 +  public InetSocketAddress getGatewayAddress() throws UnknownHostException {
 +    return new InetSocketAddress( getGatewayHost(), getGatewayPort() );
 +  }
 +
 +
 +  public long getGatewayIdleTimeout() {
 +    return 0l;
 +  }
 +
 +  @Override
 +  public boolean isSSLEnabled() {
 +    return sslEnabled;
 +  }
 +
 +  public void setSSLEnabled( boolean sslEnabled ) {
 +    this.sslEnabled = sslEnabled;
 +  }
 +
 +  @Override
 +  public boolean isHadoopKerberosSecured() {
 +    return hadoopKerberosSecured;
 +  }
 +
 +  public void setHadoopKerberosSecured(boolean hadoopKerberosSecured) {
 +    this.hadoopKerberosSecured = hadoopKerberosSecured;
 +  }
-   
++
 +  @Override
 +  public String getKerberosConfig() {
 +    return kerberosConfig;
 +  }
-   
++
 +  public void setKerberosConfig(String kerberosConfig) {
 +    this.kerberosConfig = kerberosConfig;
 +  }
 +
 +  @Override
 +  public boolean isKerberosDebugEnabled() {
 +    return kerberosDebugEnabled;
 +  }
-   
++
 +  public void setKerberosDebugEnabled(boolean kerberosDebugEnabled) {
 +    this.kerberosDebugEnabled = kerberosDebugEnabled;
 +  }
-   
++
 +  @Override
 +  public String getKerberosLoginConfig() {
 +    return kerberosLoginConfig;
 +  }
 +
 +  @Override
 +  public String getDefaultTopologyName() {
 +    return defaultTopologyName;
 +  }
 +
 +  public void setDefaultTopologyName( String defaultTopologyName ) {
 +    this.defaultTopologyName = defaultTopologyName;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getDefaultAppRedirectPath()
 +   */
 +  @Override
 +  public String getDefaultAppRedirectPath() {
 +
 +    if(StringUtils.isBlank(this.defaultTopologyName)) {
 +      return "/gateway/sandbox";
 +    } else {
 +      return "/gateway/"+this.defaultTopologyName;
 +    }
 +
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getFrontendUrl()
 +   */
 +  @Override
 +  public String getFrontendUrl() { return frontendUrl; }
 +
 +  public void setFrontendUrl( String frontendUrl ) {
 +    this.frontendUrl = frontendUrl;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getExcludedSSLProtocols()
 +   */
 +  @Override
 +  public List getExcludedSSLProtocols() {
 +    List<String> protocols = new ArrayList<String>();
 +    protocols.add("SSLv3");
 +    return protocols;
 +  }
 +
 +  @Override
 +  public List getIncludedSSLCiphers() {
 +    return includedSSLCiphers;
 +  }
 +
 +  public void setIncludedSSLCiphers( List<String> list ) {
 +    includedSSLCiphers = list;
 +  }
 +
 +  @Override
 +  public List getExcludedSSLCiphers() {
 +    return excludedSSLCiphers;
 +  }
 +
 +  public void setExcludedSSLCiphers( List<String> list ) {
 +    excludedSSLCiphers = list;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#isClientAuthNeeded()
 +   */
 +  @Override
 +  public boolean isClientAuthNeeded() {
 +    // TODO Auto-generated method stub
 +    return false;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getTruststorePath()
 +   */
 +  @Override
 +  public String getTruststorePath() {
 +    // TODO Auto-generated method stub
 +    return null;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getTrustAllCerts()
 +   */
 +  @Override
 +  public boolean getTrustAllCerts() {
 +    // TODO Auto-generated method stub
 +    return false;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getTruststoreType()
 +   */
 +  @Override
 +  public String getTruststoreType() {
 +    return truststoreType;
 +  }
 +
 +  public void setTruststoreType( String truststoreType ) {
 +    this.truststoreType = truststoreType;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getKeystoreType()
 +   */
 +  @Override
 +  public String getKeystoreType() {
 +    return keystoreType;
 +  }
 +
 +  public void setKeystoreType( String keystoreType ) {
 +    this.keystoreType = keystoreType;
 +  }
 +
 +  public void setKerberosLoginConfig(String kerberosLoginConfig) {
 +   this.kerberosLoginConfig = kerberosLoginConfig;
 +  }
 +
 +   @Override
 +   public String getGatewayServicesDir() {
 +    if( gatewayServicesDir != null ) {
 +      return gatewayServicesDir;
 +    } else {
-       return getGatewayDataDir() + "/services";
++      File targetDir = new File( System.getProperty( "user.dir" ), "target/services" );
++      return targetDir.getPath();
 +    }
 +  }
 +
 +  public void setGatewayServicesDir( String gatewayServicesDir ) {
 +    this.gatewayServicesDir = gatewayServicesDir;
 +  }
 +
 +  @Override
 +  public String getGatewayApplicationsDir() {
 +    if( gatewayApplicationsDir != null ) {
 +      return gatewayApplicationsDir;
 +    } else {
 +      return getGatewayConfDir() + "/applications";
 +    }
 +  }
 +
 +  public void setGatewayApplicationsDir( String gatewayApplicationsDir ) {
 +    this.gatewayApplicationsDir = gatewayApplicationsDir;
 +   }
 +
 +  @Override
 +  public boolean isXForwardedEnabled() {
 +    return xForwardedEnabled;
 +  }
 +
 +  public void setXForwardedEnabled(boolean enabled) {
 +    xForwardedEnabled = enabled;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getEphemeralDHKeySize()
 +   */
 +  @Override
 +  public String getEphemeralDHKeySize() {
 +    return "2048";
 +  }
 +
 +  @Override
 +  public int getHttpClientMaxConnections() {
 +    return 16;
 +  }
 +
 +  @Override
 +  public int getHttpClientConnectionTimeout() {
 +    return -1;
 +  }
 +
 +  @Override
 +  public int getHttpClientSocketTimeout() {
 +    return -1;
 +  }
 +
 +  @Override
 +  public int getThreadPoolMax() {
 +    return 16;
 +  }
 +
 +  @Override
 +  public int getHttpServerRequestBuffer() {
 +    return 16*1024;
 +  }
 +
 +  @Override
 +  public int getHttpServerRequestHeaderBuffer() {
 +    return 8*1024;
 +  }
 +
 +  @Override
 +  public int getHttpServerResponseBuffer() {
 +    return 32*1024;
 +  }
 +
 +  @Override
 +  public int getHttpServerResponseHeaderBuffer() {
 +    return 8*1024;
 +  }
 +
 +  public void setGatewayDeploymentsBackupVersionLimit( int newBackupVersionLimit ) {
 +    backupVersionLimit = newBackupVersionLimit;
 +  }
 +
 +  public int getGatewayDeploymentsBackupVersionLimit() {
 +    return backupVersionLimit;
 +  }
 +
 +  public void setTopologyPortMapping(ConcurrentHashMap<String, Integer> topologyPortMapping) {
 +    this.topologyPortMapping = topologyPortMapping;
 +  }
 +
 +  public void setGatewayPortMappingEnabled(
 +      boolean topologyPortMappingEnabled) {
 +    isTopologyPortMappingEnabled = topologyPortMappingEnabled;
 +  }
 +
 +  @Override
 +  public long getGatewayDeploymentsBackupAgeLimit() {
 +    return backupAgeLimit;
 +  }
 +
 +  public void setGatewayDeploymentsBackupAgeLimit( long newBackupAgeLimit ) {
 +    backupAgeLimit = newBackupAgeLimit;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getSigningKeystoreName()
 +   */
 +  @Override
 +  public String getSigningKeystoreName() {
 +    return null;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getSigningKeyAlias()
 +   */
 +  @Override
 +  public String getSigningKeyAlias() {
 +    return null;
 +  }
 +
 +  @Override
 +  public List<String> getGlobalRulesServices() {
 +    ArrayList<String> services = new ArrayList<>();
 +    services.add("WEBHDFS");
 +    services.add("HBASE");
 +    services.add("HIVE");
 +    services.add("OOZIE");
 +    services.add("RESOURCEMANAGER");
 +    services.add("STORM");
 +    return services;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#isWebsocketEnabled()
 +   */
 +  @Override
 +  public boolean isWebsocketEnabled() {
 +    return DEFAULT_WEBSOCKET_FEATURE_ENABLED;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getWebsocketMaxTextMessageSize()
 +   */
 +  @Override
 +  public int getWebsocketMaxTextMessageSize() {
 +    return DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_SIZE;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getWebsocketMaxBinaryMessageSize()
 +   */
 +  @Override
 +  public int getWebsocketMaxBinaryMessageSize() {
 +    return DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_SIZE;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getWebsocketMaxTextMessageBufferSize()
 +   */
 +  @Override
 +  public int getWebsocketMaxTextMessageBufferSize() {
 +    return DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_BUFFER_SIZE;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getWebsocketMaxBinaryMessageBufferSize()
 +   */
 +  @Override
 +  public int getWebsocketMaxBinaryMessageBufferSize() {
 +    return DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_BUFFER_SIZE;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getWebsocketInputBufferSize()
 +   */
 +  @Override
 +  public int getWebsocketInputBufferSize() {
 +    return DEFAULT_WEBSOCKET_INPUT_BUFFER_SIZE;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getWebsocketAsyncWriteTimeout()
 +   */
 +  @Override
 +  public int getWebsocketAsyncWriteTimeout() {
 +    return DEFAULT_WEBSOCKET_ASYNC_WRITE_TIMEOUT;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getWebsocketIdleTimeout()
 +   */
 +  @Override
 +  public int getWebsocketIdleTimeout() {
 +    return DEFAULT_WEBSOCKET_IDLE_TIMEOUT;
 +  }
 +
 +  @Override
 +  public boolean isMetricsEnabled() {
 +    return false;
 +  }
 +
 +  @Override
 +  public boolean isJmxMetricsReportingEnabled() {
 +    return false;
 +  }
 +
 +  @Override
 +  public boolean isGraphiteMetricsReportingEnabled() {
 +    return false;
 +  }
 +
 +  @Override
 +  public String getGraphiteHost() {
 +    return null;
 +  }
 +
 +  @Override
 +  public int getGraphitePort() {
 +    return 0;
 +  }
 +
 +  @Override
 +  public int getGraphiteReportingFrequency() {
 +    return 0;
 +  }
 +
 +  /* (non-Javadoc)
 +   * @see GatewayConfig#getMimeTypesToCompress()
 +   */
 +  @Override
 +  public List<String> getMimeTypesToCompress() {
 +    return new ArrayList<String>();
 +  }
 +
 +  @Override
 +  public  boolean isCookieScopingToPathEnabled() {
 +    return false;
 +  }
 +
 +  @Override
 +  public String getHeaderNameForRemoteAddress() {
 +    return "X-Forwarded-For";
 +  }
 +
 +  @Override
 +  public String getAlgorithm() {
 +    return null;
 +  }
 +
 +  @Override
 +  public String getPBEAlgorithm() {
 +    return null;
 +  }
 +
 +  @Override
 +  public String getTransformation() {
 +    return null;
 +  }
 +
 +  @Override
 +  public String getSaltSize() {
 +    return null;
 +  }
 +
 +  @Override
 +  public String getIterationCount() {
 +    return null;
 +  }
 +
 +  @Override
 +  public String getKeyLength() {
 +    return null;
 +  }
 +
 +  /**
 +   * Map of Topology names and their ports.
 +   *
 +   * @return
 +   */
 +  @Override
 +  public Map<String, Integer> getGatewayPortMappings() {
 +    return topologyPortMapping;
 +  }
 +
 +  /**
 +   * Is the Port Mapping feature on ?
 +   *
 +   * @return
 +   */
 +  @Override
 +  public boolean isGatewayPortMappingEnabled() {
 +    return isTopologyPortMappingEnabled;
 +  }
 +
 +  @Override
 +  public boolean isGatewayServerHeaderEnabled() {
 +	return false;
 +  }
 +}


Mime
View raw message