Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse Communications Framework (ECF) » HTTP POST via ECF
HTTP POST via ECF [message #662549] Thu, 31 March 2011 04:59 Go to next message
Dirk Olmes is currently offline Dirk OlmesFriend
Messages: 26
Registered: July 2009
Junior Member
Hi,

I'm trying to integrate an Eclipse plugin with a REST service. I figured
that this should be possible using ECF but google does not come up with
anything useable. This is what I have so far:

IContainer container = ContainerFactory.getDefault().createContainer
("ecf.base");
ISendFileTransferContainerAdapter adapter =
(ISendFileTransferContainerAdapter)container.getAdapter
(ISendFileTransferContainerAdapter.class);
if (adapter != null) {
Namespace namespace = adapter.getOutgoingNamespace();
URL url = new URL("http://posttestserver.com/post.php");
IFileID fileId = FileIDFactory.getDefault().createFileID(namespace,
url);

File localFile = new File("/tmp/test.txt");

IFileTransferListener listener = new IFileTransferListener() {
public void handleTransferEvent(IFileTransferEvent event) {
System.out.println(event);
}
};
adapter.sendOutgoingRequest(fileId, localFile, listener, null);
}

But the code fails with "No protocol handler for FileTransferID
[ ecf.provider.filetransfer:http://posttestserver.com/post.php]"

My plugin.xml references org.eclipse.ecf, org.eclipse.ecf.filetransfer
and org.eclipse.ecf.provider.filetransfer.httpclient.

Am I using the right approach? What am I missing here?

-dirk
Re: HTTP POST via ECF [message #663088 is a reply to message #662549] Sun, 03 April 2011 13:20 Go to previous messageGo to next message
Scott Lewis is currently offline Scott LewisFriend
Messages: 1038
Registered: July 2009
Senior Member
Dirk Olmes wrote on Thu, 31 March 2011 00:59
Hi,

I'm trying to integrate an Eclipse plugin with a REST service. I figured
that this should be possible using ECF but google does not come up with
anything useable. This is what I have so far:

IContainer container = ContainerFactory.getDefault().createContainer
("ecf.base");
ISendFileTransferContainerAdapter adapter =
(ISendFileTransferContainerAdapter)container.getAdapter
(ISendFileTransferContainerAdapter.class);
if (adapter != null) {
Namespace namespace = adapter.getOutgoingNamespace();
URL url = new URL("http://posttestserver.com/post.php");
IFileID fileId = FileIDFactory.getDefault().createFileID(namespace,
url);

File localFile = new File("/tmp/test.txt");

IFileTransferListener listener = new IFileTransferListener() {
public void handleTransferEvent(IFileTransferEvent event) {
System.out.println(event);
}
};
adapter.sendOutgoingRequest(fileId, localFile, listener, null);
}

But the code fails with "No protocol handler for FileTransferID
[ ecf.provider.filetransfer:http://posttestserver.com/post.php]"

My plugin.xml references org.eclipse.ecf, org.eclipse.ecf.filetransfer
and org.eclipse.ecf.provider.filetransfer.httpclient.

Am I using the right approach? What am I missing here?




ECF has a number of APIs...the one you are trying to use with the code above is the ECF filetransfer API. There is currently no http post-based send file transfer provider, and that's why the above does not work. It would be quite possible to create an http-post-based filetransfer provider for a particular file-upload service, but it hasn't been done yet for http post (it has for ssh file upload/send, however).

I think that given that you are accessing a REST-based service, you probably would be better off using the ECF REST API...which is intended for creating clients for REST-based services. This is another API, specifically for creating remote services based upon REST/http methods (get, post, put, delete).

There's an example of using the ECF rest API, using the post method to interact with the Twitter service in this test code:

http://git.eclipse.org/c/ecf/org.eclipse.ecf.git/tree/tests/ bundles/org.eclipse.ecf.tests.remoteservice.rest/src/org/ecl ipse/ecf/tests/remoteservice/rest/twitter/TwitterRemoteServi ceTest.java

See particularly the setUp() method, which sets up the client for accessing the rest-based remote service.

In that same test plugin project, you will find other examples of using the rest API.

There are also some further examples of using the rest API here https://github.com/ECF/ECF-Examples
Re: HTTP POST via ECF [message #663139 is a reply to message #663088] Mon, 04 April 2011 01:53 Go to previous messageGo to next message
Dirk Olmes is currently offline Dirk OlmesFriend
Messages: 26
Registered: July 2009
Junior Member
On Sun, 03 Apr 2011 09:20:15 -0400, Scott Lewis wrote:

> Dirk Olmes wrote on Thu, 31 March 2011 00:59
>> Hi,
>>
>> I'm trying to integrate an Eclipse plugin with a REST service. I
>> figured that this should be possible using ECF but google does not come
>> up with anything useable. This is what I have so far:
[...]
>>
>> Am I using the right approach? What am I missing here?
>
> ECF has a number of APIs...the one you are trying to use with the code
> above is the ECF filetransfer API. There is currently no http
> post-based send file transfer provider, and that's why the above does
> not work. It would be quite possible to create an http-post-based
> filetransfer provider for a particular file-upload service, but it
> hasn't been done yet for http post (it has for ssh file upload/send,
> however).
>
> I think that given that you are accessing a REST-based service, you
> probably would be better off using the ECF REST API...which is intended
> for creating clients for REST-based services. This is another API,
> specifically for creating remote services based upon REST/http methods
> (get, post, put, delete).
>
> There's an example of using the ECF rest API, using the post method to
> interact with the Twitter service in this test code:
>
> http://git.eclipse.org/c/ecf/org.eclipse.ecf.git/tree/tests/ bundles/
org.eclipse.ecf.tests.remoteservice.rest/src/org/eclipse/ecf /tests/
remoteservice/rest/twitter/TwitterRemoteServiceTest.java
[...]

Thanks for your reply. Looking at the TwitterRemoteServiceTest I was able
to put together a simple test using my local CouchDB. I did not test
agains the REST service I'm going to integrate yet.

One thing that I stumbled over is the handling of HTTP response codes in
RestClientService. The PUT request returns a 201 response code but
RestClientService throws an exception on anything else than a 200. This
may or may not be an issue once I start testing my REST service. I'll
report back once I did a test - this may take a while, though as I'm
travelling this week.

-dirk
Re: HTTP POST via ECF [message #663486 is a reply to message #663139] Tue, 05 April 2011 10:07 Go to previous messageGo to next message
Dirk Olmes is currently offline Dirk OlmesFriend
Messages: 26
Registered: July 2009
Junior Member
>> There's an example of using the ECF rest API, using the post method to
>> interact with the Twitter service in this test code:
>>
>> http://git.eclipse.org/c/ecf/org.eclipse.ecf.git/tree/tests/ bundles/
> org.eclipse.ecf.tests.remoteservice.rest/src/org/eclipse/ecf /tests/
> remoteservice/rest/twitter/TwitterRemoteServiceTest.java [...]
>
> Thanks for your reply. Looking at the TwitterRemoteServiceTest I was
> able to put together a simple test using my local CouchDB. I did not
> test agains the REST service I'm going to integrate yet.
>
> One thing that I stumbled over is the handling of HTTP response codes in
> RestClientService. The PUT request returns a 201 response code but
> RestClientService throws an exception on anything else than a 200. This
> may or may not be an issue once I start testing my REST service. I'll
> report back once I did a test - this may take a while, though as I'm
> travelling this week.

I did a test with the real REST service I'm trying to integrate meanwhile
and I'm hitting the same road block: the service creates a 201 on
successful completion, not a 200.

I have no idea how to work around this properly? Fork my own ECF
RestClientService? I'd better not.

Any other ideas?

-dirk
Re: HTTP POST via ECF [message #663493 is a reply to message #663486] Tue, 05 April 2011 11:04 Go to previous messageGo to next message
Markus Kuppe is currently offline Markus KuppeFriend
Messages: 177
Registered: July 2009
Senior Member
On 04/05/2011 12:07 PM, Dirk Olmes wrote:

> I did a test with the real REST service I'm trying to integrate meanwhile
> and I'm hitting the same road block: the service creates a 201 on
> successful completion, not a 200.
>
> I have no idea how to work around this properly? Fork my own ECF
> RestClientService? I'd better not.
>
> Any other ideas?
>
> -dirk

First I would start with an enhancement request [0].

Markus

[0] https://bugs.eclipse.org
Re: HTTP POST via ECF [message #663747 is a reply to message #663493] Wed, 06 April 2011 11:25 Go to previous message
Dirk Olmes is currently offline Dirk OlmesFriend
Messages: 26
Registered: July 2009
Junior Member
On Tue, 05 Apr 2011 13:04:37 +0200, Markus Alexander Kuppe wrote:

> On 04/05/2011 12:07 PM, Dirk Olmes wrote:
>
>> I did a test with the real REST service I'm trying to integrate
>> meanwhile and I'm hitting the same road block: the service creates a
>> 201 on successful completion, not a 200.
>>
>> I have no idea how to work around this properly? Fork my own ECF
>> RestClientService? I'd better not.
>>
>> Any other ideas?
>>
>> -dirk
>
> First I would start with an enhancement request [0].

Ok, done: https://bugs.eclipse.org/bugs/show_bug.cgi?id=342002

-dirk
Previous Topic:EDEF xml Multiple endpoint problem
Next Topic:Getting all participants of all open IRC channels
Goto Forum:
  


Current Time: Thu Apr 25 16:04:08 GMT 2024

Powered by FUDForum. Page generated in 0.03314 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top