Search in sources :

Example 1 with Attachment

use of org.jocean.http.rosa.SignalClient.Attachment in project jocean-http by isdom.

the class SignalTest method main.

/**
 * @param args
 * @throws Exception
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    final TestChannelPool pool = new TestChannelPool(1);
    final HttpClient httpClient = new DefaultHttpClient(new AbstractChannelCreator() {

        @Override
        protected void initializeBootstrap(final Bootstrap bootstrap) {
            bootstrap.group(new NioEventLoopGroup(1)).channel(NioSocketChannel.class);
        }
    }, pool, ENABLE_LOGGING, ENABLE_COMPRESSOR);
    final DefaultSignalClient client = new DefaultSignalClient(httpClient);
    client.registerRequestType(FetchPatientsRequest.class, FetchPatientsResponse.class, new URI("http://jumpbox.medtap.cn:8888"));
    client.registerRequestType(QueryMyPatientsForDoctorRequest.class, QueryMyPatientsForDoctorResponse.class, new URI("http://api.iplusmed.com"));
    client.registerRequestType(AddMultiMediasToJourneyRequest.class, AddMultiMediasToJourneyResponse.class, new URI("http://jumpbox.medtap.cn:8888"));
    {
        final QueryMyPatientsForDoctorRequest req = new QueryMyPatientsForDoctorRequest();
        req.setDoctorId("8510");
        ((SignalClient) client).interaction().request(req).<QueryMyPatientsForDoctorResponse>build().subscribe(new Subscriber<QueryMyPatientsForDoctorResponse>() {

            @Override
            public void onCompleted() {
                LOG.debug("FetchPatientsRequest: onCompleted.");
            }

            @Override
            public void onError(Throwable e) {
                LOG.debug("FetchPatientsRequest: onError: {}", ExceptionUtils.exception2detail(e));
            }

            @Override
            public void onNext(final QueryMyPatientsForDoctorResponse response) {
                LOG.debug("QueryMyPatientsForDoctorRequest: onNext: {}", response);
            }
        });
    }
    /*
        final CountDownLatch latch = new CountDownLatch(1);
        
        {
            final FetchPatientsRequest req = new FetchPatientsRequest();
            req.setAccountId("2");
            
            client.defineInteraction(req)
                .compose(RxNettys.<FetchPatientsResponse>filterProgress())
                .subscribe(new Subscriber<FetchPatientsResponse>() {
    
                @Override
                public void onCompleted() {
                    latch.countDown();
                    LOG.debug("FetchPatientsRequest: onCompleted.");
                }
    
                @Override
                public void onError(Throwable e) {
                    latch.countDown();
                    LOG.debug("FetchPatientsRequest: onError: {}", ExceptionUtils.exception2detail(e));
                }
    
                @Override
                public void onNext(final FetchPatientsResponse response) {
                    LOG.debug("FetchPatientsRequest: onNext: {}", response);
                }});
        }
        latch.await();
        pool.awaitRecycleChannels();
        */
    {
        final HttpUtil.TrafficCounterFeature trafficCounter = HttpUtil.buildTrafficCounterFeature();
        final HttpUtil.PayloadCounterFeature payloadCounter = HttpUtil.buildPayloadCounterFeature();
        final AddMultiMediasToJourneyRequest req = new AddMultiMediasToJourneyRequest();
        req.setCaseId("120");
        req.setJourneyId("1");
        final Subscription subscription = client.interaction().request(req).feature(// new Attachment("/Users/isdom/Desktop/997df3df73797e91dea4853c228fcbdee36ceb8a38cc8-1vxyhE_fw236.jpeg", "image/jpeg"))
        ENABLE_LOGGING, trafficCounter, payloadCounter, new Attachment("/Users/isdom/Pictures/IMG_3492.JPG", "image/jpeg")).<AddMultiMediasToJourneyResponse>build().subscribe(new Subscriber<AddMultiMediasToJourneyResponse>() {

            @Override
            public void onCompleted() {
                LOG.debug("AddMultiMediasToJourneyRequest: onCompleted.");
                LOG.debug("traffic: upload: {}/download: {}", trafficCounter.outboundBytes(), trafficCounter.inboundBytes());
                LOG.debug("payload: totalUpload: {}/totalDownload: {}", payloadCounter.totalUploadBytes(), payloadCounter.totalDownloadBytes());
            }

            @Override
            public void onError(Throwable e) {
                LOG.debug("AddMultiMediasToJourneyRequest: onError: {}", ExceptionUtils.exception2detail(e));
            }

            @Override
            public void onNext(final AddMultiMediasToJourneyResponse resp) {
                LOG.debug("AddMultiMediasToJourneyRequest: onNext: {}", resp);
            }
        });
        // subscription.unsubscribe();
        // TODO, why invoke onCompleted Event? not onError, check
        // TO BE CONTINUE, 2015-05-13
        LOG.debug("traffic: upload: {}/download: {}", trafficCounter.outboundBytes(), trafficCounter.inboundBytes());
        LOG.debug("payload: totalUpload: {}/totalDownload: {}", payloadCounter.totalUploadBytes(), payloadCounter.totalDownloadBytes());
    }
}
Also used : AbstractChannelCreator(org.jocean.http.client.impl.AbstractChannelCreator) Attachment(org.jocean.http.rosa.SignalClient.Attachment) URI(java.net.URI) DefaultHttpClient(org.jocean.http.client.impl.DefaultHttpClient) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) TestChannelPool(org.jocean.http.client.impl.TestChannelPool) DefaultSignalClient(org.jocean.http.rosa.impl.DefaultSignalClient) Subscriber(rx.Subscriber) SignalClient(org.jocean.http.rosa.SignalClient) DefaultSignalClient(org.jocean.http.rosa.impl.DefaultSignalClient) HttpClient(org.jocean.http.client.HttpClient) DefaultHttpClient(org.jocean.http.client.impl.DefaultHttpClient) Bootstrap(io.netty.bootstrap.Bootstrap) Subscription(rx.Subscription) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

Bootstrap (io.netty.bootstrap.Bootstrap)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 URI (java.net.URI)1 HttpClient (org.jocean.http.client.HttpClient)1 AbstractChannelCreator (org.jocean.http.client.impl.AbstractChannelCreator)1 DefaultHttpClient (org.jocean.http.client.impl.DefaultHttpClient)1 TestChannelPool (org.jocean.http.client.impl.TestChannelPool)1 SignalClient (org.jocean.http.rosa.SignalClient)1 Attachment (org.jocean.http.rosa.SignalClient.Attachment)1 DefaultSignalClient (org.jocean.http.rosa.impl.DefaultSignalClient)1 Subscriber (rx.Subscriber)1 Subscription (rx.Subscription)1