<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Create a new asset in Guvnor through REST API (POST method)
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/neokiing">sayan dutta</a> in <i>jBPM</i> - <a href="https://community.jboss.org/message/794494#794494">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hi All,</p><p>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. </p><p>Steps I followed :-</p><p>1.Created an asset named SayanFileTest<p>2.Got the Asset Info in Atom -XML format .. </p><p>3.Replaced the asset name With new one (FileUploadTest1)</p><p>4.Called the post method to create a new entry in GUVNOR.</p><p></p><p>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. </p><p>(N.B. - I am using jboss-as-7.1.1.Final and drools-guvnor 5.3.0)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p></p><p>***********************</p><p>//package imported..</p><p><p><span style="font-size: 10pt;"><span style="font-size: 2;"><p align="left">AbderaClient client = </p></span><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;">new</strong></strong><span style="font-size: 2;"> AbderaClient(abdera);</span></span><span style="font-size: 10pt;"><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><span style="font-size: 10pt;"><span style="font-size: 2;"><p align="left">UsernamePasswordCredentials userpass = </p></span><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;">new</strong></strong><span style="font-size: 10pt;"> UsernamePasswordCredentials(</span><span style="color: #2a00ff; font-size: 10pt;">"admin"</span><span style="font-size: 10pt;">,</span><span style="color: #2a00ff; font-size: 10pt;">"admin"</span><span style="font-size: 2;">);</span></span></span></p><p><span style="font-size: 10pt;"><span style="font-size: 2;"><p align="left">client.addCredentials(url.toExternalForm(),</p></span><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;">null</strong></strong><span style="font-size: 10pt;">,</span><span style="color: #2a00ff; font-size: 10pt;">"Basic"</span><span style="font-size: 10pt;">,userpass);</span></span></p><p><span style="font-size: 10pt;"><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p align="left"><span style="font-size: 10pt;">  </span></p><span style="font-size: 10pt;"><p align="left">ClientResponse resp = client.get(new URL("<a class="jive-link-external-small" href="http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTest&quot;).toExternalForm" rel="nofollow">http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTest").toExternalForm</a>());</p><p align="left">Document<Entry> doc = resp.getDocument();</p><p align="left">     </p><p align="left">        Entry prevEntry = doc.getRoot();  // have done this to get the atom-entry at the first place </p><p align="left">        </p><p align="left">        Entry newEntry = abdera.newEntry();</p><p align="left">      </p><p align="left"> // copied the prevEntry to populate the below string </p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></span><p align="left"><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></p></span></p><p align="left">        String newResponse ="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><atom:entry xmlns:atom=\"<a class="jive-link-external-small" href="http://www.w3.org/2005/Atom\" rel="nofollow">http://www.w3.org/2005/Atom\</a>" xmlns=\"<a class="jive-link-external-small" href="http://www.w3.org/XML/1998/namespace\" rel="nofollow">http://www.w3.org/XML/1998/namespace\</a>" xml:base=\"<a class="jive-link-external-small" href="http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTest/" rel="nofollow">http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTest\"><atom:title xmlns:atom=\"</a><a class="jive-link-external-small" href="http://www.w3.org/2005/Atom\" rel="nofollow">http://www.w3.org/2005/Atom\</a>" type=\"text\">SayanFileTest</atom:title><atom:id xmlns:atom=\"<a class="jive-link-external-small" href="http://www.w3.org/2005/Atom/" rel="nofollow">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=\"</a><a class="jive-link-external-small" href="http://www.w3.org/2005/Atom/" rel="nofollow">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=\"</a><a class="jive-link-external-small" href="http://www.w3.org/2005/Atom/" rel="nofollow">http://www.w3.org/2005/Atom\"><atom:name xmlns:atom=\"</a><a class="jive-link-external-small" href="http://www.w3.org/2005/Atom/" rel="nofollow">adminhttp://www.w3.org/2005/Atom\">admin</atom:name></atom:author><atom:content xmlns:atom=\"</a><a class="jive-link-external-small" href="http://www.w3.org/2005/Atom\" rel="nofollow">http://www.w3.org/2005/Atom\</a>" type=\"application/octet-stream\" src=\"<a class="jive-link-external-small" href="http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTest/binary/" rel="nofollow">http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTest/binary\"></atom:content><atom:summary xmlns:atom=\"</a><a class="jive-link-external-small" href="http://www.w3.org/2005/Atom\" rel="nofollow">http://www.w3.org/2005/Atom\</a>" 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>";</p><p><p>   </p><p>// replaced the name of the previous asset   </p><p>  newResponse=newResponse.replaceAll("SayanFileTest","FileUploadTest1");<br/>        </p><p>        System.out.println(newResponse);<br/>       </p><p>        newEntry.setContent(newResponse);</p><p><span style="font-size: 10pt;"><br/>        client = new AbderaClient(abdera);<br/>        client.addCredentials(new URL("<a class="jive-link-external-small" href="http://localhost:8080/drools-guvnor/&quot;).toExternalForm" rel="nofollow">http://localhost:8080/drools-guvnor/").toExternalForm</a>(), null,"Basic",new org.apache.commons.httpclient.UsernamePasswordCredentials("admin", "admin"));<br/>          <br/>        RequestOptions  options = client.getDefaultRequestOptions();<br/>        options.setContentType(MediaType.APPLICATION_ATOM_XML);</span></p><p><span style="font-size: 10pt;">        ClientResponse clientResponsePost = client.post(new URL("<a class="jive-link-external-small" href="http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets&quot;).toExternalForm" rel="nofollow">http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets").toExternalForm</a>(), newEntry, options);<br/>   <br/>        System.out.println(clientResponsePost.getType()+ "__________ " + clientResponsePost.getStatus());</span></p></p><p align="left">*****************</p><p align="left"></p><p align="left">I am a newbie in this. Any help will be really appreciated.</p><p align="left">Thanks in advance ,</p><p align="left">Sayan </p></p><p align="left">import org.apache.abdera.model.Document;</p><p align="left">import org.apache.abdera.model.Entry;</p><p align="left">import org.apache.abdera.protocol.Response.ResponseType;</p><p align="left">import org.apache.abdera.protocol.client.AbderaClient;</p><p align="left">import org.apache.abdera.protocol.client.ClientResponse;</p><p align="left">import org.apache.abdera.protocol.client.RequestOptions;</p><p align="left"><p><span style=": ; font-size: 2;"><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></span></p></p><p align="left"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style=": ; color: #7f0055; font-size: 2;"><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;"> </p></strong></strong></strong><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;">// post method..</strong></strong></strong></strong></strong></strong></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"><span style="font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style=": ; color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;"></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></span> </p><span style="font-size: 10pt;"><span style="font-size: 10pt;">Abdera abdera= </span><strong style="color: #7f0055; font-size: 10pt;"><strong style="color: #7f0055; font-size: 10pt;">new</strong></strong><span style="font-size: 2;"> Abdera();</span></span></strong></strong></strong></strong></strong></p></p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/794494#794494">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>