diff --git a/core/src/main/java/fixio/handlers/CompositeFixApplicationAdapter.java b/core/src/main/java/fixio/handlers/CompositeFixApplicationAdapter.java index 65c4216..e02f025 100644 --- a/core/src/main/java/fixio/handlers/CompositeFixApplicationAdapter.java +++ b/core/src/main/java/fixio/handlers/CompositeFixApplicationAdapter.java @@ -17,6 +17,7 @@ import fixio.fixprotocol.FixMessage; import fixio.fixprotocol.FixMessageBuilder; +import fixio.validator.BusinessRejectException; import fixio.validator.FixMessageValidator; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; @@ -41,16 +42,14 @@ public CompositeFixApplicationAdapter(List validators, List } @Override - public void onMessage(ChannelHandlerContext ctx, FixMessage msg, List out) throws Exception { + public void onMessage(ChannelHandlerContext ctx, FixMessage msg, List out) throws BusinessRejectException { assert (msg != null) : "Message can't be null"; LOGGER.info("Received : {}", msg); //Validate - if (validators != null) { for (FixMessageValidator validator : validators) { validator.validate(ctx, msg); } - } //Business handler if (handlers != null) { @@ -71,7 +70,7 @@ public void onMessage(ChannelHandlerContext ctx, FixMessage msg, List ou } @Override - public void beforeSendMessage(ChannelHandlerContext ctx, FixMessageBuilder msg) throws Exception { + public void beforeSendMessage(ChannelHandlerContext ctx, FixMessageBuilder msg) { for (FixMessageHandler handler : handlers) { handler.beforeSendMessage(ctx, msg); } diff --git a/core/src/main/java/fixio/handlers/FixApplication.java b/core/src/main/java/fixio/handlers/FixApplication.java index 0701a5e..d98251a 100644 --- a/core/src/main/java/fixio/handlers/FixApplication.java +++ b/core/src/main/java/fixio/handlers/FixApplication.java @@ -19,6 +19,7 @@ import fixio.events.LogoutEvent; import fixio.fixprotocol.FixMessage; import fixio.fixprotocol.FixMessageBuilder; +import fixio.validator.BusinessRejectException; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; @@ -48,14 +49,17 @@ public interface FixApplication extends ChannelHandler { * @param ctx current {@link ChannelHandlerContext} * @param msg a {@link FixMessage} to handle * @param out a {@link List} where decoded messages should be added - * + * @throws BusinessRejectException when message can't be accepted + * @throws InterruptedException if interrupted while processing a message */ - void onMessage(ChannelHandlerContext ctx, FixMessage msg, List out) throws Exception; + void onMessage(ChannelHandlerContext ctx, FixMessage msg, List out) + throws BusinessRejectException, InterruptedException; /** * Invoked before {@link FixMessageBuilder} is sent. * - * @param ctx current {@link ChannelHandlerContext} + * @param ctx current {@link ChannelHandlerContext} + * @param messageBuilder a message builder */ - void beforeSendMessage(ChannelHandlerContext ctx, FixMessageBuilder messageBuilder) throws Exception; + void beforeSendMessage(ChannelHandlerContext ctx, FixMessageBuilder messageBuilder); } diff --git a/core/src/main/java/fixio/handlers/FixApplicationAdapter.java b/core/src/main/java/fixio/handlers/FixApplicationAdapter.java index 4f1835a..609c39e 100644 --- a/core/src/main/java/fixio/handlers/FixApplicationAdapter.java +++ b/core/src/main/java/fixio/handlers/FixApplicationAdapter.java @@ -19,6 +19,7 @@ import fixio.events.LogoutEvent; import fixio.fixprotocol.FixMessage; import fixio.fixprotocol.FixMessageBuilder; +import fixio.validator.BusinessRejectException; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageDecoder; @@ -57,16 +58,21 @@ public void onLogout(ChannelHandlerContext ctx, LogoutEvent msg) { } @Override - public void onMessage(ChannelHandlerContext ctx, FixMessage msg, List out) throws Exception { + public void onMessage(ChannelHandlerContext ctx, FixMessage msg, List out) throws BusinessRejectException, InterruptedException { } @Override - public void beforeSendMessage(ChannelHandlerContext ctx, FixMessageBuilder msg) throws Exception { + public void beforeSendMessage(ChannelHandlerContext ctx, FixMessageBuilder msg) { } @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { LOGGER.error("Uncaught application exception.", cause); - ctx.close().sync(); + try { + ctx.close().sync(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new RuntimeException("Interrupted while closing channel", e); + } } } diff --git a/core/src/test/java/fixio/FixConversationIT.java b/core/src/test/java/fixio/FixConversationIT.java index 84a1391..0c6181a 100644 --- a/core/src/test/java/fixio/FixConversationIT.java +++ b/core/src/test/java/fixio/FixConversationIT.java @@ -113,7 +113,7 @@ public void testBusinessMessage() throws InterruptedException { private static class ServerLogicHandler extends FixApplicationAdapter { @Override - public void onMessage(ChannelHandlerContext ctx, FixMessage msg, List out) throws Exception { + public void onMessage(ChannelHandlerContext ctx, FixMessage msg, List out) { if (MessageTypes.USER_REQUEST.equals(msg.getMessageType())) { conversation.add(msg); ctx.writeAndFlush(createUserStatusReport()); diff --git a/examples/pom.xml b/examples/pom.xml index a1764fc..4487fd5 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -25,7 +25,7 @@ examples - 1.5.3 + 1.6.3 @@ -44,33 +44,23 @@ - quickfixj + org.quickfixj quickfixj-all ${quickfix.version} - quickfixj - quickfixj-msg-fix44 + org.quickfixj + quickfixj-messages-fix44 ${quickfix.version} - - org.apache.mina - mina-core - 1.1.0 - runtime - + + + + + + - - - MarketceteraRepo - http://repo.marketcetera.org/maven - - true - - - - \ No newline at end of file diff --git a/examples/src/main/java/fixio/examples/priceclient/PriceReadingApp.java b/examples/src/main/java/fixio/examples/priceclient/PriceReadingApp.java index 79536a0..0e5c64a 100644 --- a/examples/src/main/java/fixio/examples/priceclient/PriceReadingApp.java +++ b/examples/src/main/java/fixio/examples/priceclient/PriceReadingApp.java @@ -16,7 +16,12 @@ package fixio.examples.priceclient; import fixio.events.LogonEvent; -import fixio.fixprotocol.*; +import fixio.fixprotocol.FieldType; +import fixio.fixprotocol.FixMessage; +import fixio.fixprotocol.FixMessageBuilder; +import fixio.fixprotocol.FixMessageBuilderImpl; +import fixio.fixprotocol.Group; +import fixio.fixprotocol.MessageTypes; import fixio.handlers.FixApplicationAdapter; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; @@ -41,7 +46,7 @@ public void onLogon(ChannelHandlerContext ctx, LogonEvent msg) { } @Override - public void onMessage(ChannelHandlerContext ctx, FixMessage msg, List out) throws Exception { + public void onMessage(ChannelHandlerContext ctx, FixMessage msg, List out) { assert (msg != null) : "Message can't be null"; switch (msg.getMessageType()) { case MessageTypes.QUOTE: diff --git a/examples/src/main/java/fixio/examples/priceserver/PriceStreamingApp.java b/examples/src/main/java/fixio/examples/priceserver/PriceStreamingApp.java index 5bf6599..77d22e0 100644 --- a/examples/src/main/java/fixio/examples/priceserver/PriceStreamingApp.java +++ b/examples/src/main/java/fixio/examples/priceserver/PriceStreamingApp.java @@ -64,7 +64,7 @@ public void onLogout(ChannelHandlerContext ctx, LogoutEvent msg) { } @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { stopStreaming(ctx); super.exceptionCaught(ctx, cause); } @@ -77,7 +77,7 @@ private void stopStreaming(ChannelHandlerContext ctx) { } @Override - public void onMessage(ChannelHandlerContext ctx, FixMessage msg, List out) throws Exception { + public void onMessage(ChannelHandlerContext ctx, FixMessage msg, List out) { String reqId; final String messageType = msg.getMessageType(); switch (messageType) {