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

Hi Atanas,

On 8/9/2011 11:17 AM, Атанас Тодоров wrote:
Hi Scott,

No, no it's a problem of the e-mail.As i said it works for GET/POST request but what actually i do not know how to do is to post some data from client to server. There is no exception when i run the code.Imagine that i am making POST request with body "sent from client" and want to update "Some data" string to "Some data sent from client" or in other words i do not know where to take the "sent from client" String from so that concatenate to "Some data" string and return the response to the client.
Does ECF Rest api add the posted data to the request body?

By default (i.e. without being overridden for a HttpPostRequestType), this is the code that's executed to prepare a httpclient post method:

(in class RestClientService):

protected HttpMethod preparePostMethod(String uri, IRemoteCall call, IRemoteCallable callable) throws NotSerializableException {
PostMethod result = new PostMethod(uri);
HttpPostRequestType postRequestType = (HttpPostRequestType) callable.getRequestType();

IRemoteCallParameter[] defaultParameters = callable.getDefaultParameters();
Object[] parameters = call.getParameters();
if (postRequestType.useRequestEntity()) {
if (defaultParameters != null && defaultParameters.length > 0 && parameters != null && parameters.length > 0) { RequestEntity requestEntity = postRequestType.generateRequestEntity(uri, call, callable, defaultParameters[0], parameters[0]);
result.setRequestEntity(requestEntity);
}
} else {

So what it's expecting (i.e. if conditionals above) is that

defaultParameters > length 0 and parameters is greater than length 0. Then it callse postRequestType.generateRequestEntity (with the first entry in defaultParameters array and parameters array) to generate/create the httpclient RequestEntity.

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

is code like this:

if (paramToSerialize instanceof RequestEntity)
return (RequestEntity) paramToSerialize;
switch (requestEntityType) {
case INPUT_STREAM_REQUEST_ENTITY :
if (paramToSerialize instanceof InputStream) {
return new InputStreamRequestEntity((InputStream) paramToSerialize, getContentLength(call, callable, paramDefault), getContentType(call, callable, paramDefault));
}
throw new NotSerializableException("Cannot generate request entity. Expecting InputStream and got class=" + paramToSerialize.getClass().getName()); //$NON-NLS-1$
case STRING_REQUEST_ENTITY :
if (paramToSerialize instanceof String) {
try {
return new StringRequestEntity((String) paramToSerialize, getContentType(call, callable, paramDefault), getCharset(call, callable, paramDefault));
} catch (UnsupportedEncodingException e) {
throw new NotSerializableException("Could not create request entity from call parameters: " + e.getMessage()); //$NON-NLS-1$
}
}
throw new NotSerializableException("Cannot generate request entity. Expecting String and got class=" + paramToSerialize.getClass().getName()); //$NON-NLS-1$
case BYTEARRAY_REQUEST_ENTITY :
if (paramToSerialize instanceof byte[]) {
return new ByteArrayRequestEntity((byte[]) paramToSerialize, getContentType(call, callable, paramDefault));
}
throw new NotSerializableException("Cannot generate request entity. Expecting byte[] and got class=" + paramToSerialize.getClass().getName()); //$NON-NLS-1$
case FILE_REQUEST_ENTITY :
if (paramToSerialize instanceof File) {
return new FileRequestEntity((File) paramToSerialize, getContentType(call, callable, paramDefault));
}
throw new NotSerializableException("Remote call parameter with name=" + paramDefault.getName() + " is incorrect type for creating request entity."); //$NON-NLS-1$ //$NON-NLS-2$
default :
throw new NotSerializableException("Request entity generation not supported for this request type"); //$NON-NLS-1$
}
}

What this is basically doing is making it possible to use an InputStream, String, byte[], or File as the post body (the contents of which go into the appropriate RequestEntity subclass (e.g. InputStreamRequestEntity).

I thought i would have been able to take it though org.restlet.Request object.

Yes, I believe you should be able to (i.e. in the Request body).

Perhaps it would be best if you opened a bug...and then you can attach your code for me to run/test against to help diagnose. If this works for you, please open a new bug and we will do this.

Thanks,

Scott




Back to the top