Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ecf-dev] POST ECF Rest call

On 8/9/2011 7:33 AM, Атанас Тодоров wrote:
Hi All,

Can somebody tell me how to make a post request with  ECF Rest API.

My code looks like this:

IContainer container = ContainerFactory.getDefault().createContainer(REST_CONTAINER_TYPE, "");
IRemoteServiceClientContainerAdapter adapter = (IRemoteServiceClientContainerAdapter) container .getAdapter(IRemoteServiceClientContainerAdapter.class);
adapter.setResponseDeserializer(deserializer);
IRemoteCallParameter [] defaultParams = RemoteCallParameterFactory.createParameters("default","My Default Value");
HttpPostRequestType postRequest = new HttpPostRequestType();
IRemoteCallable callable = RestCallableFactory.createCallable(url, url,
   defaultParams, postRequest, IRestCall.DEFAULT_TIMEOUT);
IRemoteServiceRegistration registration = adapter.registerCallables(
new IRemoteCallable[] { callable }, null);
IRemoteService restClientService = adapter
.getRemoteService(registration.getReference());
return (T) restClientService.callSync(RestCallFactory.createRestCall(url));

I expected that data to be in the body of the request?

HttpPostRequestType postRequest = new HttpPostRequestType(<Map with params>); --> this line here puts the data that i want to transfer through the wire in the Request attributes  but its not safe operation i guess?
On the server i am using Restlet api to expose resltets.What is the generic way to make POST REST call.

Short Explanation

It's by having the parameter passed to callSync be an InputStream...e.g.

restClientService.callSync(RestCallFactory.createRestCall(methodName,new Object[] { inputStream}));

Longer explanation:

In RestClientService this method is responsible for preparing a post call (HttpPostRequestType) at actual call time:

org.eclipse.ecf.remoteservice.rest.client.RestClientService.preparePostMethod(String, IRemoteCall, IRemoteCallable)

To construct the HttpClient RequestEntity, this method is called:

org.eclipse.ecf.remoteservice.rest.client.AbstractEntityRequestType.generateRequestEntity(String, IRemoteCall, IRemoteCallable, IRemoteCallParameter, Object)

And the implementation of this method looks at the requestEntityType, and for the given parameter...if it's an InputStream it creates an InputStreamRequestEntity for post requests.

It's regrettable that we don't yet have an example and/or test code...the main reason for this is that such an example depends upon having a regularly running service (that takes post requests) in order to test.  If you are willing, it would be great to help produce such an example (and perhaps the service upon which it depends).  I would be willing to work with you on that if you like.


Now...one further thing to mention since you say that you are using Restlet.  I (Scott) have recently created a Restlet-based provider...along with a Restlet topology manager, which makes it possible to use Restlet annotation and OSGi remote services *only*...and makes it unnecessary to use the ECF REST API to make rest-based calls to Restlet-provided services.  If you are interested in using this, please contact me directly at slewis at composent.com.  Thanks.

Scott


Back to the top