You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Ettoregia <et...@gmail.com> on 2015/06/19 18:39:47 UTC

Upload through HTTP with attachments - multipart/mixed - rfc 2046

Hi all,

I've been looking for clues for quite a while now, and given the poor
results, I thought it's time to ask 
the community.

I'm trying to create an http request to be in the format reported below with
Camel 2.12 within Jboss Fuse 6.1.  
Below is my attempt, which produces "Sent to server" also reported below.

So I can see that although I set the Content-type header to be 
"multipart/mixed", that is not set on server side. One more thing, I thought
and I have to, have the second part of the http message to be sent as an
attachment, but when I try to exchange.getIn().getAttachments() that is
always null.

Please if you find some time would you at least give an hint on that, I'm at
my wits end...

Thanks in advance.


--------------------------Code
attempt-----------------------------------------------------------------------------
	public void process() throws ClientProtocolException, IOException {
                
		HttpEntity entity = MultipartEntityBuilder
				.create()
				.addTextBody("jsonBody", requestBody,
						ContentType.create("application/json"))
				.addPart("att", attacement).build();

		HttpPost post = new HttpPost(
				"http://localhost:10191/smwangw/distributeFirmware");
		post.addHeader("Content-Type", "multipart/mixed");
		post.setEntity(entity);

		HttpClient httpclient = HttpClientBuilder.create().build();

		HttpResponse response = httpclient.execute(post);

--------------------------Code
attempt-----------------------------------------------------------------------------

--------------------------Sent to
server-----------------------------------------------------------------------------

--io5JwmaTY0Tww98skQZjAjJamv71dD
Content-Disposition: form-data; name="jsonBody"
Content-Type: application/json
Content-Transfer-Encoding: 8bit

{	"DDDfirmwareUpgrade": {		"requestId":
"123e4567-e89b-12d3-a456-426655440000",		"approvedFirmwareVersionId":
"ABC123123",		"deliveryPoint": [			{"commsHubId": 1854775807,
"businessTargetId": "8E-62-33-A5-4F-00-44-65"},			{"commsHubId": 1727580722,
"businessTargetId": "85-03-E9-E5-7F-60-72-73"}		]	}}

--io5JwmaTY0Tww98skQZjAjJamv71dD

Content-Disposition: form-data; name="att"; filename="firmwareDummyImage"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

fwefwerqfndsajncvdjakvn
--io5JwmaTY0Tww98skQZjAjJamv71dD--

--------------------------Sent to
server-----------------------------------------------------------------------------


-----------------------------------Wanted
Request-----------------------------------------------------------------
POST firmware-url HTTP/1.1
Content-Length: nnn
Content-Type: multipart/mixed;
boundary=gzC2kvz70sKw8y5teEexPrJ6RB7PKgCbvXLpU
 
--gzC2kvz70sKw8y5teEexPrJ6RB7PKgCbvXLpU
Content-Type: application/json; charset=UTF-8
 
{
     "firmwareUpgrade": {
           "requestId": "C2F440A248C84B919124DD8CCEBF8883",
           "approvedFirmwareVersionId": "ABC123123",
           "deliveryPoint": [
    
{"commsHubId":“123346123”,"businessTargetId":"8E-62-33-A5-4F-00-44-65"},
     {"commsHubId":“3454567”,"businessTargetId":"85-03-E9-E5-7F-60-72-73"}
           ]
     }
}
 
--gzC2kvz70sKw8y5teEexPrJ6RB7PKgCbvXLpU
Content-Type: application/octet-stream
 
<Binary firmware image here>
--gzC2kvz70sKw8y5teEexPrJ6RB7PKgCbvXLpU--

-------------------------------------------------------------------------------------------------------------------



--
View this message in context: http://camel.465427.n5.nabble.com/Upload-through-HTTP-with-attachments-multipart-mixed-rfc-2046-tp5768419.html
Sent from the Camel - Users mailing list archive at Nabble.com.