package com.arcbees.gwtpwebsite.server.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.arcbees.gwtpwebsite.server.util.ClientConfig;
import com.arcbees.gwtpwebsite.server.util.Configuration;
import com.arcbees.gwtpwebsite.server.velocity.VelocityWrapper;
import com.arcbees.gwtpwebsite.server.velocity.VelocityWrapperFactory;
import com.google.gson.Gson;
@Singleton
public class RootServlet extends HttpServlet {
private static final String TEMPLATE_LOCATION =
"com/arcbees/gwtpwebsite/server/resource/velocitytemplates/hostpage.vm";
private final VelocityWrapper velocityWrapper;
private final Configuration configuration;
@Inject
RootServlet(VelocityWrapperFactory velocityWrapperFactory,
Configuration configuration) {
this.configuration = configuration;
this.velocityWrapper = velocityWrapperFactory.create(TEMPLATE_LOCATION);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PrintWriter printWriter = resp.getWriter();
ClientConfig configs = new ClientConfig(configuration.getStripePublicKey());
String configString = "var configs = " + new Gson().toJson(configs);
velocityWrapper.put("configs", configString);
String generated = velocityWrapper.generate();
printWriter.append(generated);
}
}