Forum Stats

  • 3,875,517 Users
  • 2,266,938 Discussions
  • 7,912,241 Comments

Discussions

Accepting json object not working

Jack_Tauson_Sr
Jack_Tauson_Sr Member Posts: 1
edited Mar 13, 2018 1:23PM in Java Programming

I am following an online example to test a POST request by passing a JSON object using Postman client as shown below. :

HelloWorldApplication.java

    package com.thejavageek.jaxrs;       import javax.ws.rs.ApplicationPath;    import javax.ws.rs.core.Application;       @ApplicationPath("/rest")    public class ExampleApplication extends Application {       }

HelloWorldService.java

    package com.thejavageek.jaxrs;       import javax.ws.rs.Consumes;    import javax.ws.rs.POST;    import javax.ws.rs.Path;    import javax.ws.rs.core.MediaType;       import com.thejavageek.jaxrs.model.Person;       @Path("/HelloWorld")    public class HelloWorldService {       @POST    @Path("/writePersonToDB")    @Consumes(MediaType.APPLICATION_JSON)    public void writePersonToDB(Person person) {       System.out.println(person);       }       }

Person.java

    package com.thejavageek.jaxrs.model;       public class Person {       private String name;    private String surname;    private String address;       public String getName() {    return name;    }       public void setName(String name) {    this.name = name;    }       public String getSurname() {    return surname;    }       public void setSurname(String surname) {    this.surname = surname;    }       public String getAddress() {    return address;    }       public void setAddress(String address) {    this.address = address;    }       @Override    public String toString() {    return "Person [name=" + name + ", surname=" + surname + ", address=" + address + "]";    }       }

Error in Postman :

2QzV5.png

I have tested another HelloWorld example of GET request from here and it worked fine. So there isn't any eclipse related issue on my local host/browser.

eudriscabrera-JavaNet

Answers

  • handat
    handat Member Posts: 4,688 Gold Crown
    edited Mar 13, 2018 2:26AM

    You failed to mention what the project name was that you deployed your application as. From your postman screenshot, one would assume that it was JAX-RS_PostExamples, but you should double check what it really is as it needs to match what you put into postman.

  • Unknown
    edited Mar 13, 2018 1:20PM

    And that is NOT the project name in the example at the link posted.

    That project name was JAX-RS_examples

  • Unknown
    edited Mar 13, 2018 1:23PM

    You clearly did NOT follow that example exactly because it says to do this:

    Deploy the web app in jboss server and open chrome rest client. and send request as below. URL: http://localhost:8080/JAX-RS_examples/rest/HelloWorld/writePersonToDB

    That is NOT the project name in your code.

    Did you 'Deploy the web app in jboss server'?

    Did you 'open chrome rest client'?

    Assuming the example at the link actually works the error you got indicates there is no such project/jar/file/code at the location where the server is looking.

    Not a Java issue - a deployment issue.

    eudriscabrera-JavaNet
This discussion has been closed.