forked from pcdavies/TwitterFeed
-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified code to support the Static Tweets in the SampleStream, pom,
etc.
- Loading branch information
oracle
committed
Aug 16, 2016
1 parent
54889c7
commit 2dcc059
Showing
7 changed files
with
13,408 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.example; | ||
|
||
|
||
import java.io.IOException; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.glassfish.jersey.server.ChunkedOutput; | ||
|
||
/** | ||
* Root resource (exposed at "statictweets" path) | ||
*/ | ||
@Path("statictweets") | ||
public class StaticTweets { | ||
|
||
private static SampleStreamExample example = new SampleStreamExample(); | ||
|
||
/** | ||
* Method handling HTTP GET requests. The returned object will be sent | ||
* to the client as "text/plain" media type. | ||
* | ||
* @return String that will be returned as an application/json response. | ||
*/ | ||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getIt() { | ||
|
||
final ChunkedOutput<String> output = new ChunkedOutput<String>(String.class); | ||
|
||
runTask(output); | ||
return Response.ok() | ||
.entity(output) | ||
.header("Access-Control-Allow-Origin", "*") | ||
.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT") | ||
.build(); | ||
} | ||
|
||
// private final ScriptEngine engine; | ||
//private final ChunkedOutput<String> output; | ||
|
||
|
||
private void runTask(ChunkedOutput<String> output) { | ||
new Thread(() -> { | ||
try { | ||
System.out.println("!!!!! Calling runStaticTwitter !!!!!!!!!!!!!!!!!"); | ||
example.runStaticTwitterStream(output, null); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} finally { | ||
if (output != null) { | ||
try { | ||
output.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
}).start(); | ||
// the output will be probably returned even before | ||
// a first chunk is written by the new thread | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters