java - I need an example on how to use the function create created by the RESTful from entity class -


i need example on how use function create created restful entity class

my entity class (countries) :

package entities;

import java.io.serializable;  import javax.persistence.basic; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.id; import javax.persistence.namedqueries; import javax.persistence.namedquery; import javax.persistence.table; import javax.validation.constraints.notnull; import javax.validation.constraints.size; import javax.xml.bind.annotation.xmlrootelement; import org.hibernate.sessionfactory; import org.hibernate.session; import org.hibernate.cfg.configuration;   /**  *  * @author oracle  */ @entity @table(name = "countries") @xmlrootelement @namedqueries({     @namedquery(name = "countries.findall", query = "select c countries c"),     @namedquery(name = "countries.findbycountryid", query = "select c countries c c.countryid = :countryid"),     @namedquery(name = "countries.findbycountryname", query = "select c countries c c.countryname = :countryname")}) public class countries implements serializable {     private static final long serialversionuid = 1l;     @id     @basic(optional = false)     @notnull     @size(min = 1, max = 2)     @column(name = "country_id")     private string countryid;     @size(max = 40)     @column(name = "country_name")     private string countryname;    static sessionfactory sessionfactory ;       public countries() {     }      public countries(string countryid) {         this.countryid = countryid;     }      public string getcountryid() {         return countryid;     }      public void setcountryid(string countryid) {         this.countryid = countryid;     }      public string getcountryname() {         return countryname;     }      public void setcountryname(string countryname) {         this.countryname = countryname;     }      @override     public int hashcode() {         int hash = 0;         hash += (countryid != null ? countryid.hashcode() : 0);         return hash;     }      @override     public boolean equals(object object) {         // todo: warning - method won't work in case id fields not set         if (!(object instanceof countries)) {             return false;         }         countries other = (countries) object;         if ((this.countryid == null && other.countryid != null) || (this.countryid != null && !this.countryid.equals(other.countryid))) {             return false;         }         return true;     }      @override     public string tostring() {         return "entities.countries[ countryid=" + countryid + " ]";     } 

my countriesfacaderest contains create function :

 @post     @override     @consumes({"application/xml", "application/json"})     public void create(countries entity) {         super.create(entity);      } 

the client code android application :

protected string doinbackground(void... params) { httpclient httpclient = new defaulthttpclient(); httpcontext localcontext = new basichttpcontext();        httppost httppost = new httppost("http://192.168.0.104:8080/wsdatabase/webresources/entities.countries/create"); string text = null; try { httpresponse response = httpclient.execute(httppost, localcontext);   httpentity entity = response.getentity();   text = getasciicontentfromentity(entity);   } catch (exception e) { return e.getlocalizedmessage(); }  return text; } 

btw : client code working , tested on other web services need let work on "create web service "

try change httpget httppost since rest service answer post request.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -