forked from TradeMatch/it-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Dmytro Podyachiy
committed
Nov 9, 2014
0 parents
commit bf9625c
Showing
13 changed files
with
853 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,9 @@ | ||
*.DS_Store | ||
bin | ||
target | ||
.classpath | ||
.project | ||
.settings | ||
src/main/webapp/META-INF | ||
.idea | ||
*.iml |
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,119 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.itrade</groupId> | ||
<artifactId>it-spring-app</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>it-commons</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
<name>IT Commons</name> | ||
|
||
<dependencies> | ||
<!-- Spring --> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-webmvc</artifactId> | ||
</dependency> | ||
|
||
<!-- JMS --> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-jms</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.hornetq</groupId> | ||
<artifactId>hornetq-core-client</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.hornetq</groupId> | ||
<artifactId>hornetq-spring-integration</artifactId> | ||
</dependency> | ||
|
||
<!-- Logging --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>jcl-over-slf4j</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-core</artifactId> | ||
</dependency> | ||
|
||
<!-- Jackson JSON Processor --> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.4.1</version> | ||
</dependency> | ||
|
||
<!-- JSR 303 with Hibernate Validator --> | ||
<dependency> | ||
<groupId>javax.validation</groupId> | ||
<artifactId>validation-api</artifactId> | ||
<version>1.0.0.GA</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-validator</artifactId> | ||
<version>4.1.0.Final</version> | ||
</dependency> | ||
|
||
<!-- Guava --> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
|
||
<!-- Test --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-all</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-library</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
90 changes: 90 additions & 0 deletions
90
commons/src/main/java/org/itrade/commons/jms/ITradeJmsMessage.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,90 @@ | ||
package org.itrade.commons.jms; | ||
|
||
public class ITradeJmsMessage { | ||
|
||
private String id; | ||
private String category; | ||
private ITradeMessageType type; | ||
private String content; | ||
private ITradeMessageStatus status; | ||
|
||
private String jmsMessageId; | ||
private String jmsCorrelationId; | ||
|
||
public ITradeJmsMessage() { | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public ITradeJmsMessage setId(String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public String getCategory() { | ||
return category; | ||
} | ||
|
||
public ITradeJmsMessage setCategory(String category) { | ||
this.category = category; | ||
return this; | ||
} | ||
|
||
public ITradeMessageType getType() { | ||
return type; | ||
} | ||
|
||
public ITradeJmsMessage setType(ITradeMessageType type) { | ||
this.type = type; | ||
return this; | ||
} | ||
|
||
public ITradeMessageStatus getStatus() { | ||
return status; | ||
} | ||
|
||
public ITradeJmsMessage setStatus(ITradeMessageStatus status) { | ||
this.status = status; | ||
return this; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
|
||
public ITradeJmsMessage setContent(String content) { | ||
this.content = content; | ||
return this; | ||
} | ||
|
||
public String getJmsMessageId() { | ||
return jmsMessageId; | ||
} | ||
|
||
public ITradeJmsMessage setJmsMessageId(final String jmsMessageId) { | ||
this.jmsMessageId = jmsMessageId; | ||
return this; | ||
} | ||
|
||
public String getJmsCorrelationId() { | ||
return jmsCorrelationId; | ||
} | ||
|
||
public ITradeJmsMessage setJmsCorrelationId(String jmsCorrelationId) { | ||
this.jmsCorrelationId = jmsCorrelationId; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ITradeJmsMessage{" + | ||
"type='" + type + '\'' + | ||
", status='" + status + '\'' + | ||
", content='" + content + '\'' + | ||
", jmsMessageId='" + jmsMessageId + '\'' + | ||
", jmsCorrelationId='" + jmsCorrelationId + '\'' + | ||
'}'; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
commons/src/main/java/org/itrade/commons/jms/ITradeMessageConverter.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,71 @@ | ||
package org.itrade.commons.jms; | ||
|
||
import com.google.common.base.Preconditions; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.jms.support.converter.MessageConversionException; | ||
import org.springframework.jms.support.converter.MessageConverter; | ||
|
||
import javax.jms.JMSException; | ||
import javax.jms.MapMessage; | ||
import javax.jms.Message; | ||
import javax.jms.Session; | ||
|
||
public class ITradeMessageConverter implements MessageConverter { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
public final static String MSG_ID = "MSG_ID"; | ||
public final static String MSG_CATEGORY = "MSG_CATEGORY"; | ||
public final static String MSG_TYPE = "MSG_TYPE"; | ||
public final static String MSG_STATUS = "MSG_STATUS"; | ||
public final static String MSG_CONTENT = "MSG_CONTENT"; | ||
|
||
@Override | ||
public Message toMessage(final Object object, final Session session) throws JMSException, MessageConversionException { | ||
Preconditions.checkArgument((object instanceof ITradeJmsMessage), "Object is not an instance of ITradeJmsMessage: {}", object); | ||
ITradeJmsMessage iTradeJmsMessage = (ITradeJmsMessage) object; | ||
return toMessage(iTradeJmsMessage, session); | ||
} | ||
|
||
public Message toMessage(final ITradeJmsMessage itradeJmsMessage, final Session session) throws JMSException { | ||
MapMessage message = session.createMapMessage(); | ||
|
||
message.setStringProperty(MSG_ID, itradeJmsMessage.getId()); | ||
message.setString(MSG_ID, itradeJmsMessage.getId()); | ||
message.setStringProperty(MSG_CATEGORY, itradeJmsMessage.getCategory()); | ||
message.setString(MSG_CATEGORY, itradeJmsMessage.getCategory()); | ||
if (itradeJmsMessage.getType() != null) { | ||
message.setStringProperty(MSG_TYPE, itradeJmsMessage.getType().name()); | ||
message.setString(MSG_TYPE, itradeJmsMessage.getType().name()); | ||
} | ||
if (itradeJmsMessage.getStatus() != null) { | ||
message.setStringProperty(MSG_STATUS, itradeJmsMessage.getStatus().name()); | ||
message.setString(MSG_STATUS, itradeJmsMessage.getStatus().name()); | ||
} | ||
message.setStringProperty(MSG_CONTENT, itradeJmsMessage.getContent()); | ||
message.setString(MSG_CONTENT, itradeJmsMessage.getContent()); | ||
|
||
return message; | ||
} | ||
|
||
@Override | ||
public ITradeJmsMessage fromMessage(final Message message) throws JMSException, MessageConversionException { | ||
return fromMessage(message, new ITradeJmsMessage()); | ||
} | ||
|
||
public <T extends ITradeJmsMessage>T fromMessage(final Message message, T iTradeJmsMessage) throws JMSException, MessageConversionException { | ||
// Correlation | ||
iTradeJmsMessage.setJmsMessageId(message.getJMSMessageID()); | ||
iTradeJmsMessage.setJmsCorrelationId(iTradeJmsMessage.getJmsCorrelationId()); | ||
|
||
// Mapping | ||
iTradeJmsMessage.setId(message.getStringProperty(MSG_ID)); | ||
iTradeJmsMessage.setCategory(message.getStringProperty(MSG_CATEGORY)); | ||
iTradeJmsMessage.setType(ITradeMessageType.valueOf(message.getStringProperty(MSG_TYPE))); | ||
iTradeJmsMessage.setStatus(ITradeMessageStatus.valueOf(message.getStringProperty(MSG_STATUS))); | ||
iTradeJmsMessage.setContent(message.getStringProperty(MSG_CONTENT)); | ||
|
||
return iTradeJmsMessage; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
commons/src/main/java/org/itrade/commons/jms/ITradeMessageStatus.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,5 @@ | ||
package org.itrade.commons.jms; | ||
|
||
public enum ITradeMessageStatus { | ||
TO_PROCESS, PROCESSED | ||
} |
5 changes: 5 additions & 0 deletions
5
commons/src/main/java/org/itrade/commons/jms/ITradeMessageType.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,5 @@ | ||
package org.itrade.commons.jms; | ||
|
||
public enum ITradeMessageType { | ||
URL, HTML, TEXT, REF, RSS, XML | ||
} |
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,14 @@ | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<logger name="org.itrade" level="DEBUG"/> | ||
|
||
<root level="WARN"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</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,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans | ||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> | ||
|
||
<bean id="iTradeMessageConverter" class="org.itrade.commons.jms.ITradeMessageConverter"/> | ||
|
||
<bean id="hornetConnectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory"> | ||
<constructor-arg name="ha" value="false"/> | ||
<constructor-arg> | ||
<bean class="org.hornetq.api.core.TransportConfiguration"> | ||
<constructor-arg | ||
value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory"/> | ||
<constructor-arg> | ||
<map key-type="java.lang.String" value-type="java.lang.Object"> | ||
<!-- HornetQ standalone instance details --> | ||
<entry key="host" value="localhost"></entry> | ||
<entry key="port" value="5445"></entry> | ||
</map> | ||
</constructor-arg> | ||
</bean> | ||
</constructor-arg> | ||
</bean> | ||
|
||
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"> | ||
<constructor-arg ref="hornetConnectionFactory"/> | ||
</bean> | ||
|
||
</beans> | ||
|
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,14 @@ | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- encoders are assigned the type | ||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="debug"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |
Oops, something went wrong.