3

I using java-stellar-sdk version 0.2.0 from this: https://github.com/stellar/java-stellar-sdk/releases I did as tutorial example:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getTransaction();
}


private void getTransaction(){
    Server server = new Server("https://horizon-testnet.stellar.org");
    KeyPair  account = KeyPair.fromAccountId(myPublicKey");

    PaymentsRequestBuilder paymentsRequest = server.payments().forAccount(account);

    String lastToken = null;
    if (lastToken != null) {
        paymentsRequest.cursor(lastToken);
    }

    paymentsRequest.stream(new org.stellar.sdk.requests.EventListener<OperationResponse>() {
        @Override
        public void onEvent(OperationResponse payment) {
            Log.d("tag","last token:"+payment.getPagingToken());
            //savePagingToken(payment.getPagingToken());

            if (payment instanceof PaymentOperationResponse) {
                String amount = ((PaymentOperationResponse) payment).getAmount();
                Asset asset = ((PaymentOperationResponse) payment).getAsset();
                String assetName;
                if (asset.equals(new AssetTypeNative())) {
                    assetName = "lumens";
                } else {
                    StringBuilder assetNameBuilder = new StringBuilder();
                    assetNameBuilder.append(((AssetTypeCreditAlphaNum) asset).getCode());
                    assetNameBuilder.append(":");
                    assetNameBuilder.append(((AssetTypeCreditAlphaNum) asset).getIssuer().getAccountId());
                    assetName = assetNameBuilder.toString();
                }

                StringBuilder output = new StringBuilder();
                output.append(amount);
                output.append(" ");
                output.append(assetName);
                output.append(" from ");
                output.append(((PaymentOperationResponse) payment).getFrom().getAccountId());
                Log.d("tag",output.toString());
            }

        }
    });

}

When it start streaming data, I got this exception, but the streaming continue getting data to the end

> 06-08 13:27:31.130 13894-14001/com.mypackage.testcreatestellaraccount
> W/Errors: The following warnings have been detected: WARNING: HK2
> service reification failed for
> [org.glassfish.jersey.message.internal.DataSourceProvider] with an
> exception:
>     MultiException stack 1 of 4
>     java.lang.RuntimeException: java.util.concurrent.ExecutionException:
> java.lang.NoClassDefFoundError: javax.activation.DataSource
>         at org.glassfish.hk2.utilities.cache.LRUHybridCache.compute(LRUHybridCache.java:315)
>         at org.glassfish.hk2.utilities.reflection.internal.ClassReflectionHelperImpl.getAllMethods(ClassReflectionHelperImpl.java:108)
>         at org.jvnet.hk2.internal.Utilities.findInitializerMethods(Utilities.java:1344)
>         at org.jvnet.hk2.internal.DefaultClassAnalyzer.getInitializerMethods(DefaultClassAnalyzer.java:107)
>         at org.glassfish.jersey.internal.inject.JerseyClassAnalyzer.getInitializerMethods(JerseyClassAnalyzer.java:242)
>         at org.jvnet.hk2.internal.Utilities.getInitMethods(Utilities.java:219)
>         at org.jvnet.hk2.internal.ClazzCreator.initialize(ClazzCreator.java:144)
>         at org.jvnet.hk2.internal.ClazzCreator.initialize(ClazzCreator.java:179)
>         at org.jvnet.hk2.internal.SystemDescriptor.internalReify(SystemDescriptor.java:723)
>         at org.jvnet.hk2.internal.SystemDescriptor.reify(SystemDescriptor.java:678)
>         at org.jvnet.hk2.internal.ServiceLocatorImpl.reifyDescriptor(ServiceLocatorImpl.java:463)
>         at org.jvnet.hk2.internal.ServiceLocatorImpl.narrow(ServiceLocatorImpl.java:2187)
>         at org.jvnet.hk2.internal.ServiceLocatorImpl.access$1200(ServiceLocatorImpl.java:121)
>         at org.jvnet.hk2.internal.ServiceLocatorImpl$10.compute(ServiceLocatorImpl.java:1331)
>         at org.jvnet.hk2.internal.ServiceLocatorImpl$10.compute(ServiceLocatorImpl.java:1326)
>         at org.glassfish.hk2.utilities.cache.LRUHybridCache$OriginThreadAwareFuture$1.call(LRUHybridCache.java:115)
>         at org.glassfish.hk2.utilities.cache.LRUHybridCache$OriginThreadAwareFuture$1.call(LRUHybridCache.java:111)
>         at java.util.concurrent.FutureTask.run(FutureTask.java:237)
>         at org.glassfish.hk2.utilities.cache.LRUHybridCache$OriginThreadAwareFuture.run(LRUHybridCache.java:173)
>         at org.glassfish.hk2.utilities.cache.LRUHybridCache.compute(LRUHybridCache.java:292)
>         at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetAllServiceHandles(ServiceLocatorImpl.java:1388)
>         at org.jvnet.hk2.internal.ServiceLocatorImpl.getAllServiceHandles(ServiceLocatorImpl.java:1313)
>         at org.jvnet.hk2.internal.ServiceLocatorImpl.getAllServiceHandles(ServiceLocatorImpl.java:1302)
>         at org.glassfish.jersey.internal.inject.Providers.getServiceHandles(Providers.java:354)
>         at org.glassfish.jersey.internal.inject.Providers.getCustomProviders(Providers.java:201)
>         at org.glassfish.jersey.message.internal.MessageBodyFactory.<init>(MessageBodyFactory.java:221)
>         at java.lang.reflect.Constructor.newInstance0(Native Method)
>         at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
>         at org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1350)
>         at org.jvnet.hk2.internal.ClazzCreator.createMe(ClazzCreator.java:271)
>         at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:365)
>         at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471)
>         at org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:83)
>         at org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:71)
>         at org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture$1.call(Cache.java:97)
>         at java.util.concurrent.FutureTask.run(FutureTask.java:237)
>         at org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture.run(Cache.java:154)
>         at org.glassfish.hk2.utilities.cache.Cache.compute(Cache.java:199)
>         at org.jvnet.hk2.internal.SingletonContext.findOrCreate(SingletonContext.java:122)
>         at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2072)
>         at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:767)
>         at org.jvnet.hk2.internal.ServiceLocatorImpl.getUnqualifiedService(ServiceLocatorImpl.java:774)
>         at org.jvnet.hk2.internal.IterableProviderImpl.get(IterableProviderImpl.java:111)
>       at org.glassfish.jerse 06-08 13:27:31.150 1343-1349/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build
> property

**My question is: After finish getting all payments, wait for a few minutes, I made another new payment, but streaming seem does not work anymore, it does not go to onEvent() to process to get my new payment (both send/receive payment)

Anyone has any solutions or suggestions, please Help!**

1 Answer 1

1

after long time digging, I found the problem:

it's because library org.glassfish.jersey's bug at: https://github.com/eclipse-ee4j/jersey/issues/3537

the http close after 60s the throw exception:

javax.ws.rs.ServerErrorException: HTTP 504 Gateway Time-out

My solution is working around:

check when eventSource.isOpen=false, I will call stream again with timer

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    EventSource eventSource = getTransaction();

    new Timer().scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            if(!eventSource.isOpen()){
                eventSource= getTransaction();
            }
        }
    }, 10000,10000);
}

private EventSource getTransaction(){
    //.... same code above

    EventSource eventSource = paymentsRequest.stream(new org.stellar.sdk.requests.EventListener<OperationResponse>() {
        @Override
        public void onEvent(OperationResponse payment) {
            //.... same code above
            }

        }
    });
    return eventSource;

}

Hope in the future, stellar and org.glassfish.jersey will fix this problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.