Send XML to activeMQ using Django
<p>I am trying to send a XML file generated using 'ElementTree' to activeMQ server using python django 'requests' library .My views.py code is :</p>

<pre><code>from django.shortcuts import render
import requests
import xml.etree.cElementTree as ET
# Create your views here.

def index(request):
    return render(request,"indexer.html")


def xml(request):
    root = ET.Element("root")
    doc = ET.SubElement(root, "doc")
    field1 = ET.SubElement(doc,"field1")
    ET.SubElement(doc, "field2", fame="yeah", name="asdfasd").text = "some vlaue2"
    ET.SubElement(field1,"fielder", name="ksd").text = "valer"
    tree = ET.ElementTree(root)
    headers = {}
    tree.write("filename.xml", encoding = "us-ascii", xml_declaration = 'utf-8', default_namespace = xml, method = "xml")

    url = 'http://localhost:8082/testurl/'
    headers = {'Content-Type': 'application/xml'}
    files = {'file': open('filename.xml', 'rb')}
    requests.post(url, files=files, headers = headers)
    return render(request,"indexer.html")
</code></pre>

<p>and there is a simple submit button on indexer.html page.</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form method="post" action="/xml/"&gt;{% csrf_token %}
    &lt;input type="submit" value="submit"&gt;
&lt;/form&gt; 
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>When I click submit button it's generating filename.xml file and then sending it successfully to activeMQ server, but at activeMQ i am getting XML message which contains header information also . So ,is it possible to send only body part without header or how to omit header at activeMQ side and keep only body/data part ?
At activeMQ I'm getting following message:</p>

<pre><code>--6dc760762ba245eb8e4c3d72aa38062b
Content-Disposition: form-data; name="file"; filename="filename.xml"

&lt;root&gt;&lt;doc&gt;&lt;field1&gt;&lt;fielder name="ksd"&gt;valer&lt;/fielder&gt;&lt;/field1&gt;&lt;field2 fame="yeah" name="asdfasd"&gt;some vlaue2&lt;/field2&gt;&lt;/doc&gt;&lt;/root&gt;
--6dc760762ba245eb8e4c3d72aa38062b--
</code></pre>

<p>I suggest looking at using the available STOMP protocol instead of HTTP. You'll have more control over message payloads and message headers.</p>

<p>Python library: <a href="https://pypi.python.org/pypi/stomp.py" rel="nofollow">https://pypi.python.org/pypi/stomp.py</a>
ActiveMQ Support: <a href="http://activemq.apache.org/stomp.html" rel="nofollow">http://activemq.apache.org/stomp.html</a></p>

python xml django jms activemq