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();
        }

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).
But my question is, when and why a developer need to use the first method?
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 

Reply via email to