use of h2weibo.model.DBHelper in project twitter-2-weibo by rjyo.
the class SaveOptionsServlet method doPost.
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(false);
String loginUser = (String) session.getAttribute(Keys.SESSION_LOGIN_USER);
log.info("Saving options for @" + loginUser);
DBHelper helper = (DBHelper) request.getAttribute(Keys.REQUEST_DB_HELPER);
T2WUser user = helper.findOneByUser(loginUser);
String[] values = request.getParameterValues("options");
if (values != null) {
List<String> list = Arrays.asList(values);
user.setOptions(new HashSet<String>(list));
} else {
user.setOptions(null);
}
helper.saveUser(user);
session.setAttribute(Keys.SESSION_MESSAGE, "User Options Saved.");
response.setStatus(200);
}
use of h2weibo.model.DBHelper in project twitter-2-weibo by rjyo.
the class TweetServlet method doGet.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(false);
String loginUser = (String) session.getAttribute(Keys.SESSION_LOGIN_USER);
DBHelper helper = (DBHelper) request.getAttribute(Keys.REQUEST_DB_HELPER);
T2WUser t2wUser = helper.findOneByUser(loginUser);
TwitterFactory factory = new TwitterFactory();
Twitter t = factory.getInstance();
t.setOAuthAccessToken(new AccessToken(t2wUser.getTwitterToken(), t2wUser.getTwitterTokenSecret()));
try {
t.updateStatus("Twitter, say hello to Weibo! Now syncing Twitter 2 Weibo using http://h2weibo.cloudfoundry.com #t2w_sync");
} catch (TwitterException e) {
log.error("Failed to send tweets", e);
}
response.setStatus(200);
}
use of h2weibo.model.DBHelper in project twitter-2-weibo by rjyo.
the class DBFilter method doFilter.
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
log.debug("In DBFilter");
DBHelper helper = DBHelperFactory.createHelper((JedisPool) context.getAttribute(Keys.CONTEXT_JEDIS_POOL));
request.setAttribute(Keys.REQUEST_DB_HELPER, helper);
chain.doFilter(req, res);
request.removeAttribute(Keys.REQUEST_DB_HELPER);
}
Aggregations