I am having an issue with embedded Jetty that I can't resolve. I am getting a redirect after login, but only on the test server, not on my local box. It happens when the user logs in; the next page gets served with a 302 redirect header with the location
of itself (over and over, so there is a redirect loop).
However, when I am running the app *locally*, after the user logs in the next page gets served with a 200 header (no redirect). I've done some initial searching online to see if anyone's had this behavior with embedded jetty, but so far haven't found anything.
The exact same code gives a 302 on va-mexp-devci-www101 that gives a 200 on my local.
I read that ContextServer can give this type of behavior if there's no slash at the end of the URL, but it doesn't look like it would turn into a redirect loop. The URL that my user goes to after login is "http://servername:8080/admin/index.do?multisiteId=merchant&redirected=y&lastFormName=loginForm",
and the URL that they are getting redirected to infinitely is the exact same URL, not added slash at the end.
public static void main(String[] args) throws Exception {
Server server = new Server();
// PARSE JSON INPUT
MEXPJsonProps mexpJsonProps = ConfigurationManager.parseJsonInput(args[1]);
// CREATE CONNECTORS
Map<String, Object> httpProps = mexpJsonProps.getHttp();
HttpConfiguration httpConfiguration = new HttpConfiguration();
httpConfiguration.setSecureScheme("https");
httpConfiguration.setSecurePort(8443);
int outputBufferSize = httpProps.get("outputBufferSize") instanceof Double
? Double.class.cast(httpProps.get("outputBufferSize")).intValue()
: (Integer) httpProps.get("outputBufferSize");
httpConfiguration.setOutputBufferSize(outputBufferSize);
// port = 8080
ServerConnector http = new ServerConnector(server,new HttpConnectionFactory(httpConfiguration));
int port = httpProps.get("port") instanceof Double
? Double.class.cast(httpProps.get("port")).intValue()
: (Integer) httpProps.get("port");
http.setPort(port);
int idleTimeout = httpProps.get("idleTimeout") instanceof Double
? Double.class.cast(httpProps.get("idleTimeout")).intValue()
: (Integer) httpProps.get("idleTimeout");
http.setIdleTimeout(idleTimeout);
// adminPort = 8081
ServerConnector httpAdmin = new ServerConnector(server,new HttpConnectionFactory(httpConfiguration));
int adminPort = httpProps.get("adminPort") instanceof Double
? Double.class.cast(httpProps.get("adminPort")).intValue()
: (Integer) httpProps.get("adminPort");
httpAdmin.setPort(adminPort);
httpAdmin.setIdleTimeout(idleTimeout);
// set the connectors
server.setConnectors(new Connector[] { http, httpAdmin });
Map<String, String> localConfiguration = mexpJsonProps.getLocalConfiguration();
// CREATE CONTEXT
WebAppContext context = new WebAppContext();
context.setContextPath("/");
ProtectionDomain domain = JettyWebApp.class.getProtectionDomain();
URL location = domain.getCodeSource().getLocation();
context.setWar(location.toExternalForm());
context.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
// SET UP JSP CONFIGS
File scratchDir = new File(localConfiguration.get("resourceRoot"));
context.setTempDirectory(scratchDir);
context.setPersistTempDirectory(true);
// Set JSP to use Standard JavaC always
System.setProperty("org.apache.jasper.compiler.disablejsr199", "false");
// Set the handler
server.setHandler(context);
server.start();
server.join();
}