[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
| Re: [ecf-dev] POST ECF Rest call | 
Hi Scott,
I have tried what you suggested.I also set the requestEntityType to 0 
HttpPostRequestType postRequest = new HttpPostRequestType(0); so the code on client side looks like that :
IRemoteCallParameter [] defaultParams = RemoteCallParameterFactory.createParameters("default","my Default Value");		
		HttpPostRequestType postRequest = new HttpPostRequestType(0);
		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());
		InputStream inputStream = new ByteArrayInputStream("My Test value".getBytes(Charset.defaultCharset()));
		return (T) restClientService.callSync(RestCallFactory.createRestCall(url, new Object[]{inputStream}));
I guess you are familiar with Restlet Framework.On server side i have a restlet that expose a web resource.Making a remote rest call via ECF i actually invoke this method below.
@POST
public void getResource(){
org.restlet.Request ---> how take the send inputStream from that request
}
I am also  willing to provide some example if we make it work of course.
Thanks
Atanas Todorov
2011/8/9 Scott Lewis 
<slewis@xxxxxxxxxxxxx>
  
    
  
  
    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
    
  
_______________________________________________
ecf-dev mailing list
ecf-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ecf-dev