-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4d3b001
Showing
42 changed files
with
1,671 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.iml | ||
.idea | ||
gradle | ||
logs |
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,58 @@ | ||
apply plugin: 'java' | ||
apply plugin: 'maven' | ||
|
||
group = 'org.grizzly.samples' | ||
version = '1.0-SNAPSHOT' | ||
|
||
description = """jersey1-grizzly2-spring""" | ||
|
||
sourceCompatibility = 1.8 | ||
targetCompatibility = 1.8 | ||
|
||
|
||
|
||
repositories { | ||
|
||
mavenCentral() | ||
} | ||
dependencies { | ||
|
||
|
||
compile 'com.rethinkdb:rethink-java-driver:0.3' | ||
compile 'org.apache.logging.log4j:log4j-api:2.0.2' | ||
compile 'org.apache.logging.log4j:log4j-core:2.0' | ||
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13', | ||
'org.json:json:20141113' | ||
|
||
compile 'org.glassfish.jersey.containers:jersey-container-servlet-core:2.16' | ||
compile 'org.glassfish.grizzly:grizzly-websockets-server:2.3.18' | ||
compile 'javax.websocket:javax.websocket-api:1.1' | ||
|
||
compile 'org.glassfish.grizzly:grizzly-http-client:1.8' | ||
compile 'org.glassfish.grizzly:grizzly-http-all:2.3.18' | ||
|
||
|
||
|
||
|
||
compile 'org.glassfish.tyrus:tyrus-server:1.9' | ||
compile 'org.glassfish.tyrus:tyrus-container-grizzly-server:1.9' | ||
|
||
// compile 'org.glassfish.grizzly:grizzly-comet-server:2.3.18' | ||
|
||
|
||
|
||
compile(group: 'com.sun.jersey.contribs', name: 'jersey-spring', version: '1.17') { | ||
exclude(module: 'spring') | ||
exclude(module: 'spring-core') | ||
exclude(module: 'spring-web') | ||
exclude(module: 'spring-beans') | ||
exclude(module: 'spring-context') | ||
exclude(module: 'spring-aop') | ||
} | ||
compile group: 'org.springframework', name: 'spring-core', version: '4.1.2.RELEASE' | ||
compile group: 'org.springframework', name: 'spring-context', version: '4.1.2.RELEASE' | ||
compile group: 'org.springframework', name: 'spring-web', version: '4.1.2.RELEASE' | ||
compile group: 'org.springframework', name: 'spring-beans', version: '4.1.2.RELEASE' | ||
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0' | ||
testCompile group: 'junit', name: 'junit', version: '3.8.1' | ||
} |
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,13 @@ | ||
package org.egreen.plantation; | ||
|
||
/** | ||
* Created by dewmal on 3/4/15. | ||
*/ | ||
public interface Options { | ||
|
||
String getDBName(); | ||
|
||
String getDBHost(); | ||
|
||
int getPort(); | ||
} |
35 changes: 35 additions & 0 deletions
35
basic/src/main/java/org/egreen/plantation/SubscriberPool.java
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,35 @@ | ||
package org.egreen.plantation; | ||
|
||
import org.egreen.plantation.socket.Subscribe; | ||
import org.egreen.plantation.socket.SubscribeFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Scope; | ||
import org.springframework.context.annotation.ScopedProxyMode; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by dewmal on 3/3/15. | ||
*/ | ||
@Component | ||
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) | ||
public class SubscriberPool { | ||
|
||
private Map<String, Subscribe> subscribeMap = new HashMap<>(); | ||
|
||
|
||
@Autowired | ||
private SubscribeFactory subscribeFactory; | ||
|
||
public Subscribe get(String path) { | ||
Subscribe subscribe = subscribeMap.get(path); | ||
if (subscribe == null) { | ||
subscribe = subscribeFactory.generate(path); | ||
subscribeMap.put(path, subscribe); | ||
} | ||
return subscribe; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
basic/src/main/java/org/egreen/plantation/socket/Subscribe.java
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,18 @@ | ||
package org.egreen.plantation.socket; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
/** | ||
* Created by dewmal on 3/3/15. | ||
*/ | ||
public interface Subscribe { | ||
|
||
void init(); | ||
|
||
String getPath(); | ||
|
||
void onUpdate(Object message); | ||
|
||
void sendMessage(Object message) throws IOException, ExecutionException, InterruptedException; | ||
} |
8 changes: 8 additions & 0 deletions
8
basic/src/main/java/org/egreen/plantation/socket/SubscribeFactory.java
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,8 @@ | ||
package org.egreen.plantation.socket; | ||
|
||
/** | ||
* Created by dewmal on 3/3/15. | ||
*/ | ||
public interface SubscribeFactory { | ||
Subscribe generate(String path); | ||
} |
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,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration status="WARN"> | ||
<Properties> | ||
<Property name="log-path">logs</Property> | ||
</Properties> | ||
<Appenders> | ||
<Console name="console-log" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"/> | ||
</Console> | ||
<RollingFile name="trace-log" fileName="${log-path}/mycuteblog-trace.log" | ||
filePattern="${log-path}/mycuteblog-trace-%d{yyyy-MM-dd}.log"> | ||
<PatternLayout> | ||
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern> | ||
</PatternLayout> | ||
<Policies> | ||
<TimeBasedTriggeringPolicy interval="1" modulate="true"/> | ||
</Policies> | ||
</RollingFile> | ||
<RollingFile name="error-log" fileName="${log-path}/mycuteblog-error.log" | ||
filePattern="${log-path}/mycuteblog-error-%d{yyyy-MM-dd}.log"> | ||
<PatternLayout> | ||
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern> | ||
</PatternLayout> | ||
<Policies> | ||
<TimeBasedTriggeringPolicy interval="1" modulate="true"/> | ||
</Policies> | ||
</RollingFile> | ||
</Appenders> | ||
<Loggers> | ||
<Logger name="com.mycuteblog.log4j2" level="debug" additivity="false"> | ||
<appender-ref ref="trace-log" level="debug"/> | ||
<appender-ref ref="error-log" level="error"/> | ||
<appender-ref ref="console-log" level="debug"/> | ||
</Logger> | ||
<Root level="info" additivity="false"> | ||
<AppenderRef ref="console-log"/> | ||
</Root> | ||
</Loggers> | ||
</Configuration> |
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,12 @@ | ||
apply plugin: 'java' | ||
|
||
sourceCompatibility = 1.8 | ||
version = '1.0' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testCompile group: 'junit', name: 'junit', version: '4.11' | ||
} |
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,18 @@ | ||
apply plugin: 'java' | ||
|
||
sourceCompatibility = 1.8 | ||
version = '1.0' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testCompile group: 'junit', name: 'junit', version: '4.11' | ||
|
||
compile 'org.glassfish:javax.json:1.0.4' | ||
compile 'org.glassfish:javax.annotation:3.1-b09' | ||
|
||
compile project(':basic') | ||
compile project(':dbcore') | ||
} |
124 changes: 124 additions & 0 deletions
124
core/src/main/java/org/egreen/plantation/api/DBControllerRestAPI.java
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,124 @@ | ||
package org.egreen.plantation.api; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.egreen.plantation.socket.DataBroker; | ||
import org.egreen.plantation.utils.JsonMapperUtill; | ||
import org.json.JSONObject; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.MediaType; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.Serializable; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
/** | ||
* Created by dewmal on 2/24/15. | ||
*/ | ||
@Component | ||
@Path("/") | ||
public class DBControllerRestAPI implements Serializable { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(DBControllerRestAPI.class); | ||
|
||
@Autowired | ||
private DataBroker dataBroker; | ||
|
||
@Autowired | ||
private JsonMapperUtill js; | ||
|
||
|
||
@Autowired | ||
private DBController dbController; | ||
|
||
@Context | ||
private HttpServletRequest request; | ||
|
||
public DBControllerRestAPI() { | ||
|
||
// | ||
|
||
} | ||
|
||
|
||
/** | ||
* GEt ALL | ||
* | ||
* @param limit | ||
* @param offset | ||
* @return | ||
*/ | ||
@GET | ||
@Path("all/{limit}/{offset}") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public String all(@PathParam("limit") String limit, @PathParam("offset") String offset) { | ||
DataPacket packet = null;//dbController.get(dataPacket); | ||
return packet.getRow() + ""; | ||
} | ||
|
||
|
||
/** | ||
* Get Selected Object | ||
* | ||
* @param child | ||
* @param id | ||
* @return | ||
*/ | ||
@GET | ||
@Path("get/{child}/{id}") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public String get(@PathParam("child") String child, @PathParam("id") String id) { | ||
Map<String, Object> dataMap = new HashMap<>(); | ||
dataMap.put("id", id); | ||
DataPacket dataPacket = new DataPacket(child, dataMap); | ||
dataPacket.setRow(dataMap); | ||
DataPacket packet = dbController.get(dataPacket); | ||
return packet.getRow() + ""; | ||
} | ||
|
||
|
||
/** | ||
* Push Object | ||
* | ||
* @param child | ||
* @param inputStream | ||
* @return | ||
*/ | ||
@POST | ||
@Path("/push/{child}") | ||
@Produces("application/json") | ||
public String getClichedMessage(@PathParam("child") String child, InputStream inputStream) { | ||
Map<String, Object> dataMap = null; | ||
try { | ||
dataMap = js.getDataMap(inputStream); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
DataPacket dataPacket = new DataPacket(child, dataMap); | ||
Object process = dbController.saveUpdateDataPacket(dataPacket); | ||
dataPacket.getRow().put("id", process); | ||
|
||
try { | ||
JSONObject jsonObject = new JSONObject(dataPacket.getRow());// Send Object | ||
dataBroker.update(jsonObject.toString(), child); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} catch (ExecutionException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return dataPacket.getRow() + ""; | ||
} | ||
|
||
|
||
} |
30 changes: 30 additions & 0 deletions
30
core/src/main/java/org/egreen/plantation/api/SetupProject.java
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,30 @@ | ||
package org.egreen.plantation.api; | ||
|
||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import java.io.InputStream; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* Created by dewmal on 2/26/15. | ||
*/ | ||
@Component | ||
@Path("/setup") | ||
public class SetupProject implements Serializable { | ||
|
||
@Autowired | ||
protected DBController dbController; | ||
|
||
|
||
@POST | ||
@Produces("application/json") | ||
public String getClichedMessage(InputStream inputStream) { | ||
Object setupDB = dbController.setupDB(); | ||
return " " + setupDB; | ||
} | ||
} |
Oops, something went wrong.