Basic Session Restoration Method
package com.nxstinc.nest.servlet.api;
import java.io.IOException;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.nxstinc.nest.servlet.IProcess;
import com.nxstinc.nest.servlet.NEST;
import com.nxstinc.nest.servlet.Result;
@WebServlet(description = "MyView", urlPatterns = { "/MyView" })
public class MyView extends NEST implements IProcess {
private static final long serialVersionUID = 1L;
@Override
public void process(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
String accessToken = getAccessToken(request);
if (accessToken != null) {
String decoded = new String(SimpleRsaToolSingleton.getSimpleRsaTool().decryptFromBase64String(accessToken));
Gson gson = new GsonBuilder().create();
User user = gson.fromJson(decoded, User.class);
System.out.println("user.id : " + user.id);
System.out.println("user.name : " + user.name);
System.out.println("user.timeStamp : " + new Date(user.timeStamp));
// session varificaiton and service logic added
} else {
// empty session
}
replyResult(new Result(), request, response);
} catch (Throwable th) {
// th.printStackTrace();
System.err.println("[E] " + getClass().getCanonicalName() + " " + th.getMessage());
replyResult(new Result(Result.SERVICE_UNAVAILABLE, "Sorry, Service Un-available"), request, response);
}
}
@Override
public Class<?> getInputSpec() {
return null;
}
@Override
public Class<?> getOutputSpec() {
return null;
}
}