Search in sources :

Example 6 with DBHelper

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);
}
Also used : T2WUser(h2weibo.model.T2WUser) HttpSession(javax.servlet.http.HttpSession) DBHelper(h2weibo.model.DBHelper)

Example 7 with DBHelper

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);
}
Also used : T2WUser(h2weibo.model.T2WUser) HttpSession(javax.servlet.http.HttpSession) DBHelper(h2weibo.model.DBHelper) AccessToken(twitter4j.auth.AccessToken)

Example 8 with DBHelper

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) DBHelper(h2weibo.model.DBHelper)

Aggregations

DBHelper (h2weibo.model.DBHelper)8 T2WUser (h2weibo.model.T2WUser)6 HttpSession (javax.servlet.http.HttpSession)5 HttpServletRouter (h2weibo.HttpServletRouter)2 AccessToken (twitter4j.auth.AccessToken)2 WeiboException (weibo4j.model.WeiboException)2 Scheduler (it.sauronsoftware.cron4j.Scheduler)1 PrintWriter (java.io.PrintWriter)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 JedisPool (redis.clients.jedis.JedisPool)1 twitter4j (twitter4j)1 Twitter (twitter4j.Twitter)1 TwitterException (twitter4j.TwitterException)1 TwitterFactory (twitter4j.TwitterFactory)1 RequestToken (twitter4j.auth.RequestToken)1 Account (weibo4j.Account)1 Oauth (weibo4j.Oauth)1 Users (weibo4j.Users)1 Weibo (weibo4j.Weibo)1 AccessToken (weibo4j.http.AccessToken)1