Results 1 to 4 of 4
  1. #1
    Apprentice123 is offline Member
    Join Date
    Jul 2012
    Posts
    20
    Rep Power
    0

    Default REST Client POST

    I am developing an application using @POST from RESTEasy.

    Java Code:
    import javax.ws.rs.Consumes;
    import javax.ws.rs.DefaultValue; 
    import javax.ws.rs.FormParam;
    import javax.ws.rs.GET; 
    import javax.ws.rs.POST;
    import javax.ws.rs.Path; 
    import javax.ws.rs.PathParam; 
    import javax.ws.rs.Produces; 
    import javax.ws.rs.QueryParam; 
    import javax.ws.rs.WebApplicationException; 
    import javax.ws.rs.core.MediaType; 
    import javax.ws.rs.core.Response.Status;
    @Path("service") 
    public class Services { 
     
       @POST
       @Produces(MediaType.APPLICATION_JSON)
       @Consumes(MediaType.APPLICATION_JSON)
       public String met(
         @FormParam("param1") String e, @FormParam("param2") String p) { 
         return e + " " + p;
       }
      
    }
    Using Simple REST Client (google chrome):
    Java Code:
    URL: http://localhost:8080/ExampleREST/service
    Method: POST
    Data: {"param1":"Test1","param2":"Test2"}
    But the output returned:
    Java Code:
    <html><head><title>JBoss Web/2.1.2.GA - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 415 - Cannot consume content type</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>Cannot consume content type</u></p><p><b>description</b> <u>The server refused this request because the request entity is in a format not supported by the requested resource for the requested method (Cannot consume content type).</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/2.1.2.GA</h3></body></html>
    Not return JSon format.

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: REST Client POST

    Hi,

    You have to supply the headers information for your request. Add Content-Type: application/json headers to the POST message headers.

  3. #3
    Apprentice123 is offline Member
    Join Date
    Jul 2012
    Posts
    20
    Rep Power
    0

    Default Re: REST Client POST

    Quote Originally Posted by wsaryada View Post
    Hi,

    You have to supply the headers information for your request. Add Content-Type: application/json headers to the POST message headers.
    I add the Content-Type: application/json
    The Data from Rest Client:
    Java Code:
    <html><head><title>JBoss Web/2.1.3.GA - Error report</title>
    <style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} 
    H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} 
    H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} 
    BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} 
    B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} 
    P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}
    A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> 
    </head><body><h1>HTTP Status 404 - /fcf/services</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p>
    <p><b>message</b> <u>/fcf/services</u></p><p><b>description</b> <u>The requested resource (/fcf/services) is not available.</u></p>
    <HR size="1" noshade="noshade"><h3>JBoss Web/2.1.3.GA</h3></body></html>

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: REST Client POST

    The error said it cannot find your web services. The requested resource (/fcf/services) is not available. Is your web service up and running?

Similar Threads

  1. Coordinating GUI and Rest of Program
    By BAL in forum New To Java
    Replies: 1
    Last Post: 01-29-2012, 02:31 PM
  2. Replies: 3
    Last Post: 05-04-2009, 03:15 AM
  3. Sonatype GWT REST 1.0-SNAPSHOT
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 03-29-2008, 12:54 PM
  4. Replies: 1
    Last Post: 07-14-2007, 05:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •