Hello experts,

I have Configuration class like below;

public class MyConfiguration extends Configuration {

  public final static String USER_ROOT_PATH = "/my-server/api/1.0";
  public final static String ADMIN_ROOT_PATH = "/";
  
  public MyConfiguration() {
    super();
    setContextPath();
    setServerPorts();
  }

  private void setContextPath() {
    DefaultServerFactory defaultServerFactory = (DefaultServerFactory) 
getServerFactory();
    defaultServerFactory.setApplicationContextPath(USER_ROOT_PATH);
    defaultServerFactory.setAdminContextPath(ADMIN_ROOT_PATH);
  }
  
  private void setServerPorts() {
    
    DefaultServerFactory defaultServerFactory = (DefaultServerFactory) 
getServerFactory();

    //User server
    HttpConnectorFactory applicationHttpConnectorFactory = (
HttpConnectorFactory) defaultServerFactory.getApplicationConnectors().get(0
);
    final InetSocketAddress userServerAddress = BootstrapServices.
getSingleton().getBindService().getUserServerBindSocket();
    applicationHttpConnectorFactory.setPort(userServerAddress.getPort());
    applicationHttpConnectorFactory.setBindHost(userServerAddress.
getHostString());

    //Admin server
    HttpConnectorFactory adminHttpConnectorFactory = (HttpConnectorFactory) 
defaultServerFactory.getAdminConnectors().get(0);
    final InetSocketAddress adminServerAddress = BootstrapServices.
getSingleton().getBindService().getAdminServerBindSocket();
    adminHttpConnectorFactory.setPort(adminServerAddress.getPort());
    adminHttpConnectorFactory.setBindHost(adminServerAddress.getHostString
());
  }
}

When used in my Application, In logs i can see below;

INFO  [2019-07-04 10:15:10,348] org.eclipse.jetty.setuid.SetUIDListener: 
Opened application@24043ec5{HTTP/1.1,[http/1.1]}{0.0.0.0:80}
INFO  [2019-07-04 10:15:10,349] org.eclipse.jetty.setuid.SetUIDListener: 
Opened admin@3e33b52e{HTTP/1.1,[http/1.1]}{0.0.0.0:10080}



I did add AdminResourse bundle as said below;

public class AdminResourceBundle implements ConfiguredBundle<MyConfiguration
> {

    private static final String BASE_PATH = "/*";
    
    private JerseyEnvironment jerseyEnvironment;

    @Override
    public void initialize(final Bootstrap<?> bootstrap) {
    }

    @Override
    public void run(final MyConfiguration configuration, final Environment 
environment) throws Exception {
        this.jerseyEnvironment = this.setupAdminEnvironment(environment);
    }

    private JerseyEnvironment setupAdminEnvironment(final Environment 
environment) {
        final DropwizardResourceConfig jerseyConfig = new 
DropwizardResourceConfig(environment.metrics());
        
        //Add all Admin related REST resources.
        customizeAdminRouting(jerseyConfig);

        final JerseyContainerHolder servletContainer = new 
JerseyContainerHolder(new ServletContainer(jerseyConfig));
        final JerseyEnvironment jerseyEnvironment = new JerseyEnvironment(
servletContainer, jerseyConfig);

        environment.admin().addServlet("admin resources", servletContainer.
getContainer()).addMapping(BASE_PATH);

        // These are needed to hook up Timed, CircuitBreaker, etc.
        jerseyEnvironment.register(new 
InstrumentedResourceMethodApplicationListener(environment.metrics()));
        jerseyEnvironment.register(new RolesAllowedDynamicFeature());
        return jerseyEnvironment;
    }
}


*This fails saying multiple servlets are mapped to the same path which is 
correct.*

My use case is to access some of the REST resource via admin port only. 
Basically health checks and other admin functions.

Can someone explain what is the behavior for my questions?

1. With out adding AdminResourceBundle into my dropwizzard application, 
does it create two servlet and map to USER_ROOT_PATH and ADMIN_ROOT_PATH?  
If yes, then how can I access some of the REST resource via admin port only?

2. By adding AdminResourceBundle to my application, does it create third 
servlet and map it to same ADMIN_ROOT_PATH("/") path? 

3. what does environment.admin().addServlet(....)  in AdminResourceBundle 
indicate? Does it mean it is accessible only via admin port and host which 
is configured in DefaultServerFactory application/admin connectors ?

What is the right approach to solve this?

thanks,
Robin Kuttaiah

-- 
You received this message because you are subscribed to the Google Groups 
"dropwizard-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dropwizard-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dropwizard-dev/30598e84-eaf5-4745-a861-63380a8f9d8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to