Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Challenges in My POSTING(Adding) / PUTTING(Update)Restful Web service Using A Team Persistence Acce

OmileNov 21 2015 — edited Nov 24 2015

After creating  my simple  restful webservice  using netbeans v8 and apache Tomee as server.i tested it ,it was working fine.When i use A-Team to create the mobile client i do encounter this challeng,if i post or put  the data ,it is alway sending null  values to the server.i tried to debug it by printing the  data both in Datacontrol addPerson/savePerson method and POST/PUT method of server class.The print in Data control methods does not print null but the actual values i type through  the emulator..In Server side both POST?PUT prints null always.i have tested it with simple html form which is not null. because the table  variables or attributes in the database  is not null configured  it keep on throwing error which makes the values not to  commit.Of course the payload (Get method)  from the server show  the actual values in the emulator.client get method of Maf is working fine.

when i was creating the restful client using A-Team extension before the end of the configuration i checked "send serialised data Object as payload and send as Array " of both POST,PUT,DELETE methods. below are both the server codes and clients codes

       

ENTITY CLASS

@Entity

@Table(name = "person", catalog = "Personality", schema = "")

@XmlRootElement

@NamedQueries({

    @NamedQuery(name = "Person.findAll", query = "SELECT p FROM Person p"),

    @NamedQuery(name = "Person.findByPersonid", query = "SELECT p FROM Person p WHERE p.personid = :personid"),

    @NamedQuery(name = "Person.findByFirstName", query = "SELECT p FROM Person p WHERE p.firstName = :firstName"),

    @NamedQuery(name = "Person.findByLastName", query = "SELECT p FROM Person p WHERE p.lastName = :lastName"),

    @NamedQuery(name = "Person.findByAddress", query = "SELECT p FROM Person p WHERE p.address = :address")})

public class Person  implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id

    @GeneratedValue(strategy = GenerationType.IDENTITY)

    @Basic(optional = false)

    @Column(name = "Person_id")

    private Integer personid;

    @Basic(optional = false)

    @NotNull

    @Size(min = 1, max = 45)

    @Column(name = "FirstName")

    private String firstName;

    @Basic(optional = false)

    @NotNull

    @Size(min = 1, max = 45)

    @Column(name = "LastName")

    private String lastName;

    @Basic(optional = false)

    @NotNull

    @Size(min = 1, max = 400)

    @Column(name = "Address")

    private String address;

    @Lob

    @Column(name = "Pics")

    private byte[] pics;

    public Person() {

    }

    public Person(Integer personid) {

        this.personid = personid;

    }

    public Person(Integer personid, String firstName, String lastName, String address) {

        this.personid = personid;

        this.firstName = firstName;

        this.lastName = lastName;

        this.address = address;

    }

    public Integer getPersonid() {

        return personid;

    }

    public void setPersonid(Integer personid) {

        this.personid = personid;

    }

    public String getFirstName() {

        return firstName;

    }

    public void setFirstName(String firstName) {

        this.firstName = firstName;

    }

    public String getLastName() {

        return lastName;

    }

    public void setLastName(String lastName) {

        this.lastName = lastName;

    }

    public String getAddress() {

        return address;

    }

    public void setAddress(String address) {

        this.address = address;

    }

    public byte[] getPics() {

        return pics;

    }

    public void setPics(byte[] pics) {

        this.pics = pics;

    }

    @Override

    public int hashCode() {

        int hash = 0;

        hash += (personid != null ? personid.hashCode() : 0);

        return hash;

    }

    @Override

    public boolean equals(Object object) {

        // TODO: Warning - this method won't work in the case the id fields are not set

        if (!(object instanceof Person)) {

            return false;

        }

        Person other = (Person) object;

        if ((this.personid == null && other.personid != null) || (this.personid != null && !this.personid.equals(other.personid))) {

            return false;

        }

        return true;

    }

    @Override

    public String toString() {

        return "entity.Person[ personid=" + personid + " ]";

    }

   

}

RESTFUL CLASS

@Stateless

@Path("entity.person")

public class PersonFacadeREST extends AbstractFacade<Person> {

    @PersistenceContext(unitName = "PersonalityPU")

    private EntityManager em;

    public PersonFacadeREST() {

        super(Person.class);

    }

//   Note : i  tried to print the values send through the emulator.  But it  prints    null.

    @POST 

    @Path("POSTMOBILE")

    @Consumes("application/json")

    public void creates( Person entity) {      

        try{ 

            System.err.println(" print");

            System.out.println(entity.getFirstName()+" "+ entity.getPersonid()+ " "+ entity.getAddress());

        super.created(entity);

        }catch(Exception e){

            e.printStackTrace();

        }

    }

  //   Note : i  tried to print the values send through the emulator.  But it  prints    null.

@PUT

    @Path("PUTMOBILE")

    @Consumes("application/json")   

    public void edits( Person entity) {

       

        try{

            System.out.println(" put print");

            System.out.println(entity.getFirstName()+"  id   "+ entity.getPersonid()+ "  adress  "+ entity.getAddress());

            if(entity.getPersonid()!=null)

              super.created(entity);

           

            super.edit(entity);

        }catch(Exception e){

            e.printStackTrace();

        }

    }

@GET

    @Override

    @JSONP(queryParam = "parseResponse")

    @Produces({"application/javascript","application/json","text/javascript",  "application/ecmascript", "application/x-ecmascript"})

    public List<Person> findAll() {

        return super.findAll();

    }

    @Override

    protected EntityManager getEntityManager() {

        return em;

    }

    A-TEAM 

public class PersonService extends EntityCRUDService<Person> {

    public PersonService() {

    }

/**  Note : i  tried to print the values returned by the Person object to check  if  addPerson   sends null value.  But   the values print was  not null.**/

    public void addPerson(int index, Person person) {

        System.err.println("error  edit");

        System.out.println("id  "+person.getPersonid()+" addre  "+ person.getAddress()+"   firstname   "+ person.getFirstName());

        addEntity(index, person);

    };

/**   Note : i  tried to print the values returned by the Person object to check  if   savePerson  sends null value.  But   the values print was  not null.**/

    public void savePerson(Person person) {

        System.err.println("error  save ");

        System.out.println("id  "+person.getPersonid()+" addre  "+ person.getAddress()+"   firstname   "+ person.getFirstName());

        super.mergeEntity(person);

    }

any suggestions?

Thanks .

Best Regards,

Omile Bartholomew

Comments
Post Details
Added on Nov 21 2015
2 comments
813 views