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/S...;
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/S...
http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/S...
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/S...
xmlns:atom=\"
http://www.w3.org/2005/Atom/
2013-01-23T14:10:33.173+05:30http://www.w3.org/2005/Atom\">2013-0...
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></at...
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/S...
http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/S...
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/").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&a...,
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&...]