Skip to content

Commit

Permalink
Added 'content' property (optially stores content in Context)
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Aug 30, 2018
1 parent 471d552 commit 5b3f718
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion modules/qrest/src/dist/deploy/30_qrest_txnmgr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<participant class="org.jpos.qrest.participant.Router">
<route path="/q2**" method="GET" name="q2"/>
<route path="/q2**" method="POST" name="q2"/>
</participant>

<group name="q2">
Expand All @@ -15,4 +16,3 @@
<!--<property name="content-type" value="application/json" />-->
</participant>
</txnmgr>

1 change: 1 addition & 0 deletions modules/qrest/src/dist/deploy/50_qrest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<qrest class='org.jpos.qrest.RestServer' logger='Q2'>
<property name='port' value='8081' />
<property name='queue' value='TXNMGR' />
<property name='content' value='JSON_REQUEST' />

<!--
<property name="TLS" value="true" />
Expand Down
5 changes: 5 additions & 0 deletions modules/qrest/src/main/java/org/jpos/qrest/RestSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.netty.handler.codec.http.*;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.util.CharsetUtil;
import org.jpos.transaction.Context;
import org.jpos.util.LogEvent;
import org.jpos.util.Logger;
Expand All @@ -31,9 +32,11 @@

public class RestSession extends ChannelInboundHandlerAdapter {
private RestServer server;
private String contentKey;

RestSession(RestServer server) {
this.server = server;
contentKey = server.getConfiguration().get("content", null);
}

@Override
Expand All @@ -43,6 +46,8 @@ public void channelRead(ChannelHandlerContext ch, Object msg) throws Exception {
final FullHttpRequest request = (FullHttpRequest) msg;
ctx.put(Constants.SESSION, ch);
ctx.put(Constants.REQUEST, request);
if (contentKey != null)
ctx.put(contentKey, request.content().toString(CharsetUtil.UTF_8));
server.queue(ctx);
} else {
super.channelRead(ch, msg);
Expand Down
14 changes: 12 additions & 2 deletions modules/qrest/src/test/java/org/jpos/qrest/RestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static com.jayway.restassured.RestAssured.given;
import static io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_JSON;

import static com.jayway.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;

public class RestTest {
Expand Down Expand Up @@ -76,5 +75,16 @@ public void testAll() {
)
));
}
}

@Test
public void testPost() {
given().and().body("{ \"test\": \"Test JSON\" }")
.log().all().post("q2")
.then().statusCode(200).assertThat()
.body("version", equalTo(
String.format("jPOS %s %s/%s (%s)",
Q2.getVersion(), Q2.getBranch(), Q2.getRevision(), Q2.getBuildTimestamp()
)
));
}
}

0 comments on commit 5b3f718

Please # to comment.