Hello,
thank you for your reply.

Currently, I am doing a study about well dynamic typing of web service and I 
choose cxf 
to run some examples.
In fact, for SOAP/WS* services, there is a standard used , wsdl files, which 
are generated by a web service.
A client can use this wsdl to generate an appropriated interface in java to 
build an appropriated request to
the designed web service. Thus, I can say, following this way, there must not 
be any typing errors.
But for Restful services, the situation differs a bit. There is a WADL files to 
describe the web services like the
WSDL files in SOAP/WS*, but WADL still not a standard.
My question is, if a restful web service doesn't define a WADL, thus the client 
can't generate in java the appropriated
classes (like using wadltojava), then how he can know the type of messages?
I suppose that in the absence of a WADL for a web service, there is a text 
description file describing all methods and 
there messages types. Thus, the client has to read this document to know how to 
build his messages.
Here, he can make mistakes by sending to a restful resource an inappropriate 
data.

Is my reasoning correct about that?


Regards,

Diana

On 29 nov. 2011, at 18:01, Sergey Beryozkin wrote:

> Hi
> 
> On 29/11/11 15:33, Diana ALLAM wrote:
>> Hello,
>> 
>> After using the restful examples in the "samples" directory of cxf 
>> distribution, I distinguished
>> two types of restful request for "put/post" CRUD methods.
>> 1) the first one is by sending a request with an xml object description 
>> (samples ->  jax_rs ->  basic)
>> Follows, there is a part of the code example for calling the put method by 
>> using an input file containing the "customer" xml code:
>>         // Sent HTTP PUT request to update customer info
>>         System.out.println("\n");
>>         System.out.println("Sent HTTP PUT request to update customer info");
>>         Client client = new Client();
>>         String inputFile = 
>> client.getClass().getResource("update_customer.xml").getFile();
>>         URIResolver resolver = new URIResolver(inputFile);
>>         File input = new File(resolver.getURI());
>>         PutMethod put = new 
>> PutMethod("http://localhost:8080/CustomerRestfullTest/jaxrs/customerservice/customers";);
>>         RequestEntity entity = new FileRequestEntity(input, "text/xml; 
>> charset=ISO-8859-1");
>>         put.setRequestEntity(entity);
>>         HttpClient httpclient = new HttpClient();
>> 
>>         try {
>>             int result = httpclient.executeMethod(put);
>>             System.out.println("Response status code: " + result);
>>             System.out.println("Response body: ");
>>             System.out.println(put.getResponseBodyAsString());
>>             
>> System.out.println(put.getResponseHeader(Message.ENDPOINT_ADDRESS));
>>         } finally {
>>             // Release current connection to the connection pool once you are
>>             // done
>>             put.releaseConnection();
>>         }
>> 
> 
> This is a very old code that will be replaced
> 
>> 2) the second one is by using an instance of a Java class, here is Customer, 
>> instead of getting data from an input file (samples ->  jax_rs ->  
>> basic_https)
>> 
>>         WebClient wc = WebClient.create(BASE_SERVICE_URL, 
>> CLIENT_CONFIG_FILE);
>>         Customer customer = new Customer();
>>         customer.setId(123);
>>         customer.setName("Mary");
>>         Response resp = wc.put(customer);
>> 
>> 
>> I prefer to use the second method because in the first method,
>> a developer could make mistakes in his input file, then the server will 
>> reply by a fault message, while the second
>> method allows to avoid such errors as there is a customer object conform to 
>> a specified class Customer.
>> 
>> I think also the second method is more adapted if the client wishes using a 
>> wadl file, then by using wadltojava, all the appropriated classes
>> are generated (like the Customer class in my previous example).
> Agreed
>> But my question is, when and why a developer need to use the first method?
> 
> If developers do prefer using Apache HttpClient for whatever reasons then 
> they may want to use that API
> 
> Cheers, Sergey
> 
>> And by such a use, the developer doesn't take the risk of sending inadapted 
>> data to the server?
>> and how the developer knows which data description form (for the customer 
>> example, it is an xsd) he must use in this case, if he doesn't have a wadl?
>> because I suppose that if he had a wadl then he must use the second method.
>> 
>> Thank you in advance.
>> 
>> Regards,
>> 
>> Diana
>> 
>> 
> 
> 
> -- 
> Sergey Beryozkin
> 
> Talend Community Coders
> http://coders.talend.com/
> 
> Blog: http://sberyozkin.blogspot.com

Reply via email to