<!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&#160; 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?&#160; 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;">&#160;</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;">&#160;</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;">&#160;</p><p align="left"><span style="font-size: 10pt;">&#160; </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&amp;quot;).toExternalForm" rel="nofollow">http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTest").toExternalForm</a>());</p><p align="left">Document&lt;Entry&gt; doc = resp.getDocument();</p><p align="left">&#160;&#160;&#160;&#160; </p><p align="left">&#160;&#160;&#160;&#160;&#160;&#160;&#160; Entry prevEntry = doc.getRoot();&#160; // have done this to get the atom-entry at the first place </p><p align="left">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p align="left">&#160;&#160;&#160;&#160;&#160;&#160;&#160; Entry newEntry = abdera.newEntry();</p><p align="left">&#160;&#160;&#160;&#160;&#160; </p><p align="left"> // copied the prevEntry to populate the below string </p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p></span><p align="left"><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p></p></span></p><p align="left">&#160;&#160;&#160;&#160;&#160;&#160;&#160; String newResponse ="&lt;?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?&gt;&lt;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\"&gt;&lt;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\"&gt;SayanFileTest&lt;/atom:title&gt;&lt;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\"&gt;http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets/SayanFileTest&lt;/atom:id&gt;&lt;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\"&gt;2013-01-23T14:10:33.173+05:30&lt;/atom:published&gt;&lt;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\"&gt;&lt;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\"&gt;admin&lt;/atom:name&gt;&lt;/atom:author&gt;&lt;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\"&gt;&lt;/atom:content&gt;&lt;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\"&gt;&lt;/atom:summary&gt;&lt;metadata xmlns=\"\"&gt;&lt;uuid&gt;&lt;value&gt;&lt;/value&gt;&lt;/uuid&gt;&lt;categories&gt;&lt;/categories&gt;&lt;format&gt;&lt;value&gt;.txt&lt;/value&gt;&lt;/format&gt;&lt;state&gt;&lt;value&gt;Draft&lt;/value&gt;&lt;/state&gt;&lt;versionNumber&gt;&lt;value&gt;2&lt;/value&gt;&lt;/versionNumber&gt;&lt;checkinComment&gt;&lt;value&gt;&lt;/value&gt;&lt;/checkinComment&gt;&lt;archived&gt;&lt;value&gt;false&lt;/value&gt;&lt;/archived&gt;&lt;/metadata&gt;&lt;/atom:entry&gt;";</p><p><p>&#160;&#160; </p><p>// replaced the name of the previous asset&#160;&#160; </p><p>&#160; newResponse=newResponse.replaceAll("SayanFileTest","FileUploadTest1");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(newResponse);<br/>&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; newEntry.setContent(newResponse);</p><p><span style="font-size: 10pt;"><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; client = new AbderaClient(abdera);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; client.addCredentials(new URL("<a class="jive-link-external-small" href="http://localhost:8080/drools-guvnor/&amp;quot;).toExternalForm" rel="nofollow">http://localhost:8080/drools-guvnor/").toExternalForm</a>(), null,"Basic",new org.apache.commons.httpclient.UsernamePasswordCredentials("admin", "admin"));<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; RequestOptions&#160; options = client.getDefaultRequestOptions();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; options.setContentType(MediaType.APPLICATION_ATOM_XML);</span></p><p><span style="font-size: 10pt;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; ClientResponse clientResponsePost = client.post(new URL("<a class="jive-link-external-small" href="http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets&amp;quot;).toExternalForm" rel="nofollow">http://localhost:8080/drools-guvnor/rest/packages/defaultPackage/assets").toExternalForm</a>(), newEntry, options);<br/>&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; 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;">&#160;</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;">&#160;</p></strong></strong></strong><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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>&#160;</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>