use of org.jocean.http.rosa.SignalClient in project jocean-http by isdom.
the class DefaultSignalClientTestCase method testSignalClientWithoutSignalBeanForPostWithJSONContentAndDecodeResponseAs.
@Test
public void testSignalClientWithoutSignalBeanForPostWithJSONContentAndDecodeResponseAs() throws Exception {
final TestResponse respToSendback = new TestResponse("0", "OK");
final AtomicReference<HttpMethod> reqMethodReceivedRef = new AtomicReference<>();
final AtomicReference<String> reqpathReceivedRef = new AtomicReference<>();
final AtomicReference<TestRequestByPost> reqbeanReceivedRef = new AtomicReference<>();
final Action2<FullHttpRequest, HttpTrade> requestAndTradeAwareWhenCompleted = new Action2<FullHttpRequest, HttpTrade>() {
@Override
public void call(final FullHttpRequest req, final HttpTrade trade) {
try {
reqMethodReceivedRef.set(req.method());
reqpathReceivedRef.set(req.uri());
reqbeanReceivedRef.set((TestRequestByPost) JSON.parseObject(Nettys.dumpByteBufAsBytes(req.content()), TestRequestByPost.class));
} catch (IOException e) {
LOG.warn("exception when Nettys.dumpByteBufAsBytes, detail: {}", ExceptionUtils.exception2detail(e));
}
trade.outbound(buildResponse(respToSendback, trade.onTerminate()));
}
};
final String testAddr = UUID.randomUUID().toString();
final Subscription server = TestHttpUtil.createTestServerWith(testAddr, requestAndTradeAwareWhenCompleted, Feature.ENABLE_LOGGING, Feature.ENABLE_COMPRESSOR);
try {
final TestChannelCreator creator = new TestChannelCreator();
final TestChannelPool pool = new TestChannelPool(1);
final DefaultHttpClient httpclient = new DefaultHttpClient(creator, pool, Feature.ENABLE_LOGGING);
final DefaultSignalClient signalClient = new DefaultSignalClient(buildUri2Addr(testAddr), httpclient);
final TestResponse respReceived = ((SignalClient) signalClient).interaction().request(new Object()).feature(new SignalClient.UsingUri(new URI("http://test")), new SignalClient.UsingPath("/test/raw"), new SignalClient.UsingMethod(POST.class), new SignalClient.JSONContent("{\"code\": \"added\"}"), new SignalClient.DecodeResponseBodyAs(TestResponse.class)).<TestResponse>build().timeout(1, TimeUnit.SECONDS).toBlocking().single();
assertEquals(HttpMethod.POST, reqMethodReceivedRef.get());
assertEquals("/test/raw", reqpathReceivedRef.get());
assertEquals(new TestRequestByPost(null, "added"), reqbeanReceivedRef.get());
assertEquals(respToSendback, respReceived);
pool.awaitRecycleChannels();
} finally {
server.unsubscribe();
}
}
use of org.jocean.http.rosa.SignalClient in project jocean-http by isdom.
the class JolokiaApiDemo method main.
public static void main(String[] args) throws Exception {
final SignalClient signal = new DefaultSignalClient(new DefaultHttpClient());
final URI uri = new URI("http://192.168.8.8/jolokia/");
queryAttrValue(signal, uri, "java.lang:type=Threading");
Thread.sleep(100);
queryAttrValue(signal, uri, "java.lang:type=Threading");
Thread.sleep(100);
System.exit(0);
}
Aggregations