facebook

RESTful web service client

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #316906 Reply

    k_elgazzar
    Member

    Hello,

    I’ve tried this tutorial (http://www.myeclipseide.com/documentation/quickstarts/webservices_rest/) to develop a RESTful Web service. To test the Web service I wrote the following client.

    import …
    public class TestService {
    public static void main(String[] args) {
    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    WebResource service = client.resource(getBaseURI());
    //test Get
    ClientResponse response = service.path(“services”).path(“customers”).accept(“application/xml”).get(ClientResponse.class);
    System.out.println(response.toString());
    System.out.println(“Response body: “+response.getEntity(String.class);
    System.out.println(“Response size: “+ textEntity.getBytes().length + ” Bytes”);
    //test Post
    //create a form
    //Form formData = new Form();
    //formData.add(“address”, “address2”);
    //formData.add(“name”,”client2″);

    ClientResponse response1 = service.path(“services”).path(“customers”).path(“add”).accept(“application/xml”).post(ClientResponse.class,formData);
    System.out.println(response1.toString());
    }
    private static URI getBaseURI() {
    return UriBuilder.fromUri(“http://localhost:8081/restdemo/”).build();
    }

    }
    The test for GET was ok, but POST did not, and returned the http error code 415. Seems I could not build the correct object “formData” (in my example) to pass it with the POST method. However, the POST method is working fine when I use the poster add-on for firefox and records successfully added to my web service.

    Could you please help me on how to build the correct object with post in this case?
    Thanks,
    Khalid

Viewing 1 post (of 1 total)
Reply To: RESTful web service client

You must be logged in to post in the forum log in