Java remote access and manipulations [Development]

Discussion of the Web Interface for Transmission, formerly known as Clutch. This applies to all version of Transmission
Post Reply
meir
Posts: 12
Joined: Mon Aug 16, 2010 6:05 pm

Java remote access and manipulations [Development]

Post by meir »

Hello, I am fairly new to java development and I need help.
I would like to write Java application that access TransmissionBT remotely and does some basic manipulations with torrents, like read statistics ( what is the share ratio for particular torrent ) and starts/stops torrents. I read some stuff about it, but still unable to write anything that would at least connect to app and requests anything. I looked online for examples and such but didn't find anything usable.

Can anyone help me with java examples?

P.S: Please note, I am NOT planning to write "head" for the Transmission, I just need to be able to read stats, make decision based on the information and stop or start torrents as needed. Thank you.
elmotheelk
Posts: 14
Joined: Sat Apr 11, 2009 12:40 am

Re: Java remote access and manipulations [Development]

Post by elmotheelk »

I'm the developer of Transdroid, an Android application that connects to Transmission. Since this is written in Java, you might be just fine with using my code to connect. It is available online: http://code.google.com/p/transdroid and http://code.google.com/p/transdroid/sou ... apter.java for the class that actually connects to Transmission.

I you have any specific questions, feel free to ask me in a private message or post it here.
meir
Posts: 12
Joined: Mon Aug 16, 2010 6:05 pm

Re: Java remote access and manipulations [Development]

Post by meir »

Thank you, I'll take a better look at it later ( after work ), can u tell me if I need 'import org.transdroid.daemon.*" libraries?
Since I don't write it for the Android, I would not need it, right?
elmotheelk
Posts: 14
Joined: Sat Apr 11, 2009 12:40 am

Re: Java remote access and manipulations [Development]

Post by elmotheelk »

Yes, some, like the callback interface and the tasks. Take a look at it and if you want some sample code on how too call Transmission functions, let me know.
meir
Posts: 12
Joined: Mon Aug 16, 2010 6:05 pm

Re: Java remote access and manipulations [Development]

Post by meir »

I was looking at: private JSONObject makeRequest(JSONObject data) throws DaemonException { ... }
method but I can't replicate it, probably because I am missing Apache libraries: ( org.apache.http.* ).
Can you tell me if there is a way to implement the same method but with standard java libraries? If I can't, where can I get apache libs?
Thank you.

P.S: Examples of Transmission methods would be awesome, thank you!
elmotheelk
Posts: 14
Joined: Sat Apr 11, 2009 12:40 am

Re: Java remote access and manipulations [Development]

Post by elmotheelk »

You need the Apache Http client to make http calls to the Transmission server. That's available from apache.org. I'm not stating that you can use my class without removing some code our dependencies, but it shouldn't be too much. You'll at least need the Task classes.

A task can be executed with, for example, new RetrieveTask().execute(); This will be synchronous. You may use the TaskQueue class as well, but you will definitely need to rewrite this as it uses the Android-specific Handler class.
meir
Posts: 12
Joined: Mon Aug 16, 2010 6:05 pm

Re: Java remote access and manipulations [Development]

Post by meir »

man... so much code... can't it be simplified? :D
Anyways, I think I got it to work. It makes a connection and doesn't complain about anything BUT JSON Object...
Can you give me examples to how create data, ( for requests and stuff ).

Now, if I understand it properly ( reading from your code )
First we make a HTTP stuff, creating object, setting with options and stuff.
Second we are creating JSONObject in order to talk to Transmission
Third we open connection and sending JSONObject into it
Forth we read answer as JSON Object and then print it or do whatever we need with it.
Am I correct?

PS: Show me some example on how to create JSONObject for the Transmission requests.
Thanks!


PSS: Forgot to show my error:
org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]

Here is JSONObject:
{"arguments":{"fields":["files","fileStats"]},"tag":0,"method":"torrent-get"}
meir
Posts: 12
Joined: Mon Aug 16, 2010 6:05 pm

Re: Java remote access and manipulations [Development]

Post by meir »

Okay, I figured the error, I forgot to convert Stream into String and I was trying to create JSONObject :D ops...
Still can you help me with Requests to Transmission ( asking for stuff from Trans. )? Thanks.
Post Reply