java - Odata V4 Client: getEntityCreate method -


i developed odataclient in java in order create new entities. encountering difficulties create new entities. took initiative see messages sent client fiddler.

        odataentitycreaterequest<cliententity>  request=              client.getcudrequestfactory()             .getentitycreaterequest(new uri("http://localhost:8888/"), cliententity);      request.addcustomheader("content-type", "application/json;odata.metadata=minimal");     request.setaccept("application/json;odata=minimalmetadata");      odataentitycreateresponse<cliententity> response = request.execute(); 

below first line of body obtained fiddler:

17b {"@odata.type":"#odatademo.product", ....} 

i tested manually fiddler create new entity , first line of message body should be:

 {"odata.type":"odatademo.product", ....} 

i know if possible set body of request odata in order delete "@" , "#".

thanks,

i found alternative solution problem. not use entirely odata libraries. created methods to post request.

public void insertdata(string entityname, entity entity) {            try {         reswrap<entity> resw = new reswrap<entity>(new uri(this.baseuri.concat("/").concat(entityname)), "full", entity);         cliententity cliententity = this.client.getbinder().getodataentity(resw);         //string message = getmessagerebuild(client.getwriter().writeentity(cliententity, contenttype.application_json));          inputstream = client.getwriter().writeentity(cliententity, contenttype.application_json);          if(is != null)         {             system.out.println("post: "+post(this.baseuri.concat("/").concat(entityname), is));             //system.out.println("post:"+post("http://localhost:8888/"+entityname, is));         }     } catch (urisyntaxexception e) {         // todo auto-generated catch block         e.printstacktrace();     } catch (odataserializerexception e) {         // todo auto-generated catch block         e.printstacktrace();     } catch (exception e) {         // todo auto-generated catch block         e.printstacktrace();     } }  public string post(string url,inputstream message) throws exception{     httpclient client = new defaulthttpclient();     httppost post = new httppost(url);     //post.addheader("content-type", "application/json;odata.metadata=minimal");     //post.addheader("accept", "application/json;odata=verbose");     post.addheader("content-type", "application/json");     post.addheader("accept", "application/json");     httpentity entity = new bytearrayentity(ioutils.tobytearray(message));     post.setentity(entity);     httpresponse response = client.execute(post);     string result = entityutils.tostring(response.getentity());     return result; } 

insertdata take 2 parameters : entityname + entity generated. use librairie org.apache.http send http message odata server.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -