[jboss-user] [jBPM] - Create a new asset in Guvnor through REST API (POST method)

sayan dutta do-not-reply at jboss.com
Mon Jan 28 00:25:47 EST 2013


sayan dutta [https://community.jboss.org/people/neokiing] created the discussion

"Create a new asset in Guvnor through REST API (POST method)"

To view the discussion, visit: https://community.jboss.org/message/794494#794494

--------------------------------------------------------------
Hi All,
I am trying to create an asset (.txt file ) in GUVNOR through REST API in JAVA. But the problem is when using the post method to create asset .. program is executing with no error but i am having SERVER_ERROR(http 500  error..) as a response. 
Steps I followed :-
1.Created an asset named SayanFileTest2.Got the Asset Info in Atom -XML format .. 
3.Replaced the asset name With new one (FileUploadTest1)
4.Called the post method to create a new entry in GUVNOR.

Can anybody please help me with this one?  I am providing the code.. Please tell me what i am doing wrong in this and how to solve it. 
(N.B. - I am using jboss-as-7.1.1.Final and drools-guvnor 5.3.0)


***********************
//package imported..
AbderaClient client = 
**new** AbderaClient(abdera);
UsernamePasswordCredentials userpass = 
**new** UsernamePasswordCredentials("admin","admin");
client.addCredentials(url.toExternalForm(),
**null**,"Basic",userpass);

  
ClientResponse resp = client.get(new URL("http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTest").toExternalForm (http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTest").toExternalForm)());
Document<Entry> doc = resp.getDocument();

        Entry prevEntry = doc.getRoot();  // have done this to get the atom-entry at the first place 

        Entry newEntry = abdera.newEntry();

 // copied the prevEntry to populate the below string 



        String newResponse ="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><atom:entry xmlns:atom=\" http://www.w3.org/2005/Atom\ http://www.w3.org/2005/Atom\" xmlns=\" http://www.w3.org/XML/1998/namespace\ http://www.w3.org/XML/1998/namespace\" xml:base=\" http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTest/ http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTest\"><atom:title xmlns:atom=\" http://www.w3.org/2005/Atom\ http://www.w3.org/2005/Atom\" type=\"text\">SayanFileTest</atom:title><atom:id xmlns:atom=\" http://www.w3.org/2005/Atom/ http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTesthttp://www.w3.org/2005/Atom\">http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTest</atom:id><atom:published xmlns:atom=\" http://www.w3.org/2005/Atom/ 2013-01-23T14:10:33.173+05:30http://www.w3.org/2005/Atom\">2013-01-23T14:10:33.173+05:30</atom:published><atom:author xmlns:atom=\" http://www.w3.org/2005/Atom/ http://www.w3.org/2005/Atom\"><atom:name xmlns:atom=\" http://www.w3.org/2005/Atom/ adminhttp://www.w3.org/2005/Atom\">admin</atom:name></atom:author><atom:content xmlns:atom=\" http://www.w3.org/2005/Atom\ http://www.w3.org/2005/Atom\" type=\"application/octet-stream\" src=\" http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTest/binary/ http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTest/binary\"></atom:content><atom:summary xmlns:atom=\" http://www.w3.org/2005/Atom\ http://www.w3.org/2005/Atom\" type=\"text\"></atom:summary><metadata xmlns=\"\"><uuid><value></value></uuid><categories></categories><format><value>.txt</value></format><state><value>Draft</value></state><versionNumber><value>2</value></versionNumber><checkinComment><value></value></checkinComment><archived><value>false</value></archived></metadata></atom:entry>";

// replaced the name of the previous asset   
  newResponse=newResponse.replaceAll("SayanFileTest","FileUploadTest1");

        System.out.println(newResponse);

        newEntry.setContent(newResponse);

        client = new AbderaClient(abdera);
        client.addCredentials(new URL("http://localhost:8080/drools-guvnor/").toExternalForm (http://localhost:8080/drools-guvnor/&quot;).toExternalForm)(), null,"Basic",new org.apache.commons.httpclient.UsernamePasswordCredentials("admin", "admin"));
          
        RequestOptions  options = client.getDefaultRequestOptions();
        options.setContentType(MediaType.APPLICATION_ATOM_XML);
        ClientResponse clientResponsePost = client.post(new URL("http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets").toExternalForm (http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets&quot;).toExternalForm)(), newEntry, options);
   
        System.out.println(clientResponsePost.getType()+ "__________ " + clientResponsePost.getStatus());
*****************

I am a newbie in this. Any help will be really appreciated.
Thanks in advance ,
Sayan 
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.protocol.Response.ResponseType;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
import org.apache.abdera.protocol.client.RequestOptions;


********
***
******// post method..******
******************
Abdera abdera= **new** Abdera();*****
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/794494#794494]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130128/d60ea4dc/attachment-0001.html 


More information about the jboss-user mailing list