protected void remoteServeResource( ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); OAuthRequest oAuthRequest = new OAuthRequest(Verb.GET, getServerPortletURL()); setRequestParameters(resourceRequest, resourceResponse, oAuthRequest); addOAuthParameter(oAuthRequest, "p_p_lifecycle", "2"); addOAuthParameter(oAuthRequest, "p_p_resource_id", resourceRequest.getResourceID()); Response response = getResponse(themeDisplay.getUser(), oAuthRequest); String contentType = response.getHeader(HttpHeaders.CONTENT_TYPE); if (contentType.startsWith(ContentTypes.APPLICATION_OCTET_STREAM)) { String contentDisposition = response.getHeader(HttpHeaders.CONTENT_DISPOSITION); int contentLength = GetterUtil.getInteger(response.getHeader(HttpHeaders.CONTENT_LENGTH)); PortletResponseUtil.sendFile( resourceRequest, resourceResponse, getFileName(contentDisposition), response.getStream(), contentLength, contentType, HttpHeaders.CONTENT_DISPOSITION_ATTACHMENT); } else { PortletResponseUtil.write(resourceResponse, response.getStream()); } }
protected void downloadApp( PortletRequest portletRequest, PortletResponse portletResponse, long appPackageId, boolean unlicensed, File file) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); OAuthRequest oAuthRequest = new OAuthRequest(Verb.GET, getServerPortletURL()); setBaseRequestParameters(portletRequest, portletResponse, oAuthRequest); String serverNamespace = getServerNamespace(); addOAuthParameter( oAuthRequest, serverNamespace.concat("appPackageId"), String.valueOf(appPackageId)); addOAuthParameter(oAuthRequest, "p_p_lifecycle", "2"); if (unlicensed) { addOAuthParameter(oAuthRequest, "p_p_resource_id", "serveUnlicensedApp"); } else { addOAuthParameter(oAuthRequest, "p_p_resource_id", "serveApp"); } Response response = getResponse(themeDisplay.getUser(), oAuthRequest); FileUtil.write(file, response.getStream()); }
protected void remoteProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); OAuthRequest oAuthRequest = new OAuthRequest(Verb.POST, getServerPortletURL()); setRequestParameters(actionRequest, actionResponse, oAuthRequest); addOAuthParameter(oAuthRequest, "p_p_lifecycle", "1"); addOAuthParameter(oAuthRequest, "p_p_state", WindowState.NORMAL.toString()); Response response = getResponse(themeDisplay.getUser(), oAuthRequest); if (response.getCode() == HttpServletResponse.SC_FOUND) { String redirectLocation = response.getHeader(HttpHeaders.LOCATION); actionResponse.sendRedirect(redirectLocation); } else { HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(actionResponse); httpServletResponse.setContentType(response.getHeader(HttpHeaders.CONTENT_TYPE)); ServletResponseUtil.write(httpServletResponse, response.getStream()); } }
public static void main(String[] args) throws Exception { OAuthService service = new ServiceBuilder().provider(TwitterApi.class).apiKey(apiKey).apiSecret(apiSecret).build(); OAuthRequest request = new OAuthRequest(Verb.POST, URL); request.addBodyParameter("track", "wsop"); Token t = new Token(token, tokenSecret); service.signRequest(t, request); Response response = request.send(); JSONTokener jsonTokener = new JSONTokener(new InputStreamReader(response.getStream(), "UTF-8")); int i = 0; StringBuilder sb = new StringBuilder(); while (i++ < 2) { try { JSONObject jsonObject = new JSONObject(jsonTokener); sb.append(new Tweet(jsonObject).getHTML() + "\n"); } catch (JSONException ex) { throw new IOException("Got JSONException: " + ex.getMessage()); } } System.out.println(HTMLCreator.createHTML(sb)); }
public void run() { try { System.out.println("Starting Twitter public stream consumer thread."); // Enter your consumer key and secret below OAuthService service = new ServiceBuilder() .provider(TwitterApi.class) .apiKey("qFiiPwXFjaiRsFAq5OSYHFT0f") .apiSecret("V9t7qXkbjglS76TKy6Xw9U2fukb1Nh1xmtKKR30kXR6noap9Qe") .build(); // Set your access token Token accessToken = new Token( "66266917-XNT9WqkdFO8TQz6VQeCQtYEZIBdgpp82tUxCrIcIW", "2v4EMHESOz4yeajmjj8788mkGa2UOLAeUR1nrJ27tlSek"); // Let's generate the request System.out.println("Connecting to Twitter Public Stream"); OAuthRequest request = new OAuthRequest(Verb.POST, STREAM_URI); request.addHeader("version", "HTTP/1.1"); request.addHeader("host", "stream.twitter.com"); request.setConnectionKeepAlive(true); request.addHeader("user-agent", "Twitter Stream Reader"); request.addBodyParameter( "track", "Bank of America, bofa, bofa_news, bofa_help, ROLB, BMB, Pingit, Ping-it, BarclaysMobileBanking, Barclays Live, Feature Store, Barclays, Barclaycard, BCS, BarclaysWealth, john mcfarlane, @Barclays, @Barclaysuk, hsbc, hsbc_press, citi, Citigroup Inc, RBS, Royal Bank Of Scotland, LLyods Bank, STAN, @StanChart, Santander, NatWest, Halifax, Tesco Bank"); // Set keywords you'd like to track here service.signRequest(accessToken, request); Response response = request.send(); // Create a reader to read Twitter's stream BufferedReader reader = new BufferedReader(new InputStreamReader(response.getStream())); // Create a new file for raw tweets File file = new File("C:\\Users\\Striker\\Desktop\\Tweet Data\\raw_tweet.txt"); FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); String line; while ((line = reader.readLine()) != null) { latestTweet = line; bw.write(line); bw.newLine(); tweetCount++; System.out.println(line); } bw.close(); } catch (IOException ioe) { ioe.printStackTrace(); } }
public void run() { try { System.out.println("Starting Twitter public stream consumer thread."); // Enter your consumer key and secret below OAuthService service = new ServiceBuilder() .provider(TwitterApi.class) .apiKey("0GglmCJSWdauygE0dPYVhRoYN") .apiSecret("aikSSCPcX1AOayVw98MKuPvalUKvPZhaESEJMawVGK9a9bfG0I") .build(); // Set your access token Token accessToken = new Token( "863517241-dba29VzM7RaYMOvwFv03KOdkki6SVluRiRLqc1Ks", "cB8WS8duMCy4I30ZawZJFuv743jLdTWKLKkniMKfZOEQi"); // Let's generate the request System.out.println("Connecting to Twitter Public Stream"); OAuthRequest request = new OAuthRequest(Verb.POST, STREAM_URI); request.addHeader("version", "HTTP/1.1"); request.addHeader("host", "stream.twitter.com"); request.setConnectionKeepAlive(true); request.addHeader("user-agent", "Twitter Stream Reader"); // request.addBodyParameter("track", "java,heroku,twitter"); // Set keywords you'd like to // track here request.addBodyParameter("follow", "4884271164"); // Set keywords you'd like to track here service.signRequest(accessToken, request); Response response = request.send(); // Create a reader to read Twitter's stream BufferedReader reader = new BufferedReader(new InputStreamReader(response.getStream())); String line; while ((line = reader.readLine()) != null) { System.out.println(line); } } catch (IOException ioe) { ioe.printStackTrace(); } }