package org.openspaces.servicegrid.kvstore;

import javax.servlet.Servlet;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

import com.google.common.base.Throwables;
import com.sun.jersey.spi.container.servlet.ServletContainer;

public class KVStoreServer {

	private static Server server;
	private static ServletContainer servletContainer;
	
	public void start(int port) {

		server = new Server(port);
	    servletContainer = new ServletContainer(new KVStoreResourceConfig());
		server.setHandler(createWebAppContext(servletContainer));
		try {
			server.start();
		}
		catch (Exception e) {
			throw Throwables.propagate(e);
		}
	}
	
	public void reload() {
		servletContainer.reload();
	}
	
	public void stop() {
		try {
			server.stop();
		}
		catch (Exception e) {
			throw Throwables.propagate(e);
		}
	}
	
	private static ServletContextHandler createWebAppContext(Servlet servlet) {
		ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
		handler.setContextPath("/");
		ServletHolder servletHolder = new ServletHolder(servlet);
		servletHolder.setInitParameter("com.sun.jersey.config.property.packages", KVStoreServlet.class.getPackage().getName());
		handler.addServlet(servletHolder, "/*");
		return handler;
	}
}

@@ -464,17 +464,16 @@
 port) %7B%0A
-%0A
 %09%09server
@@ -1286,16 +1286,85 @@
 ame());%0A
+%09%09servletHolder.setInitParameter(%22cacheControl%22,%22max-age=0,public%22);%0A
 %09%09handle

Disable any chance of caching