Skip to Content
0

How to connect Twitter Streaming API with Java on SAP Cloud Platform?

Aug 22, 2017 at 01:44 PM

145

avatar image
Former Member

Hi,

I developed an java application which can be executed on SAP Cloud Platform. In application, I am using twitter streaming api to connect and get twitter data. The related twitter library is hbc-twitter java library.

Connection is build in hbc java library. Therefore, I am not able to use destination on the server. Because the related java library can access the twitter apis.

I tried creating destinations and getting the HttpURLConnection object from java but I could not use the related http connection object to twitter hbc library.

How can I solve this issue on SAP Cloud Platform? In my localhost the application works fine. Any solutions?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Vladimir Pavlov
Aug 23, 2017 at 05:27 PM
0

Have you looked at the ConnectivityConfiguration API?

What does the twitter library expect as input?

Show 6 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hello Vladimir,

I checked ConnectivityConfiguration API but it is again based on destination object. Twitter streaming API which is HBC(Hosebird), just accepted host as a string type variable. There is a constant host variable which has "https://stream.twitter.com/" in twitter library. Therefore, we cannot pass the related destination object or HttpURLConnection object to twitter library.

I debugged the destinaiton object in SCP runtime. It creates almost 120 different certificate in destination in trust attributes. However, we cannot pass the related destination object to twitter library. How can we find a solution for this external library usage in terms of accessing external apis in SCP?

I think about that we need to allow application to access some external sources. Not only based on destination objects but also in application level.

0

You can just get the destination properties as Map<String, String> and work with whatever you need:

// get all destination properties

Map<String,String> allDestinationPropeties = destConfiguration.getAllProperties();
0
Former Member
Vladimir Pavlov

I tried to read all properties, there was no problem about reading properties. However, I can just pass the url parameter which is just string to twitter hbc streaming api. There is no difference to pass string directly hardcode to twitter library or reading from it destination properties.

Here is the code that creates a client to Twitter;

this.client = new ClientBuilder().hosts(Constants.STREAM_HOST)
                                 .endpoint(this.endpoint)
                                 .authentication(this.auth)
                                 .processor(new StringDelimitedProcessor(this.queue))
                                 .build();<br>

Constants.STREAM_HOST value is "https://stream.twitter.com" which can be derived from destination but there is no difference.

And here is the screenshot for destionation properties.


How can we solve the issue?

0

Sorry, I really don't understand what's the issue here?!

0
Former Member
Vladimir Pavlov

My java application cannot connect to "https://stream.twitter.com" on SAP Cloud Platform because I cannot pass the destination object to twitter hbc library which is built by twitter. Therefore, The Java application on SAP Cloud Platform cannot access the "https://stream.twitter.com". This is the issue. Is there anyway to allow the application to connect external systems without destinations? And another question is, sometimes we cannot repair external libraries which is used by our application and what if the library tries to connect some external IP, how can we allow this library to connect related IP?

0

Well, as explained, you don't need to pass a destination object, just take the destination properties and use whatever you need.

0