Hi
I've added a test showing how to use Map correctly:
http://git-wip-us.apache.org/repos/asf/cxf/commit/79fb92a5
Note, using Map might make sense if you have plain beans, if you created
Attachments then it is simpler to pass along a List of Attachments,
possibly wrapped in MultipartBody.
I've added one extra constructor to create Attachments from the beans,
if you have InputStream then use the existing constructors accepting
InputStream and headers. ContentDisposition helper is available too, you
don't really need to manually build the boundaries, etc...
HTH, Sergey
On 07/03/14 19:53, NALLA, VENKAT wrote:
Hi Sergey,
I am using CXF 2.7.6 to send a multipart message in JAX-RS. The code and
the log are given below.
1)This does not send all the multi parts
2)Content-Transfer-Encoding is not set right
3)Is there any way to set the Content-Transfer-Encoding value?
4)I tried to use XopType as well, but that does not work as the request
is wrapped in XopType XML message and the server does not about XopType
XML, so could not use it. Is there any way send the content in Base64
encoding without using XopType ?
Thanks,
Venkat
*public**static*Map<String, Object> getSMILAttachments(Object requestObj,
String requestObjectType,
String message,
String smilFile,
String fileName) {
Map<String, Object> objects = *new*LinkedHashMap<String,
Object>();
objects.put(requestObjectType, requestObj);
List<Attachment> attachments = *new*ArrayList<Attachment>();
MultivaluedMap<String, String> headers =
*new*MetadataMap<String, String>();
headers.put("Content-Type", Arrays./asList/(*new*String
[] { "application/smil"}));
headers.put("Content-ID", Arrays./asList/(*new*String []
{ "smil"} ));
headers.put("Content-Transfer-Encoding",
Arrays./asList/(*new*String [] { "BASE64"} ));
attachments.add(*new*Attachment(/encodeToBase64/(smilFile), headers));
headers = *new*MetadataMap<String, String>();
headers.put("Content-Type", Arrays./asList/(*new*String [] {
URLConnection./guessContentTypeFromName/(fileName)+"; name="+fileName }));
headers.put("Content-ID", Arrays./asList/(*new*String []
{ "0-image"} ));
headers.put("Content-Disposition",
Arrays./asList/(*new*String [] { "Content-Disposition: Attachment;
Filename="+fileName} ));
headers.put("Content-Transfer-Encoding",
Arrays./asList/(*new*String [] { "BASE64"} ));
attachments.add( *new*Attachment(/encodeToBase64/(fileName), headers) );
headers = *new*MetadataMap<String, String>();
headers.put("Content-Type", Arrays./asList/(*new*String [] {
"text/plain; name="+"text.txt"}));
headers.put("Content-ID", Arrays./asList/(*new*String []
{ "0-text"} ));
headers.put("Content-Disposition",
Arrays./asList/(*new*String [] { "Content-Disposition: Attachment;
Filename="+"text.txt"} ));
headers.put("Content-Transfer-Encoding",
Arrays./asList/(*new*String [] { "BASE64"} ));
attachments.add( *new*Attachment(/encodeToBase64String/(message), headers));
objects.put("multipart/related; type=application/smil;
Start=smil;", attachments);
*return*objects;
}
It does not write the full message on the wire and results in error
response from the server. The server is not implemented using CXF
(actually I do not know what is technology used on the server side).
[java] INFO: Outbound Message
[java] ---------------------------
[java] ID: 2
[java] Address: https://api.att.com/mms/v3/messaging/outbox
[java] Http-Method: POST
[java] Content-Type: multipart/related; type="application/json";
boundary="
uuid:20df8e8f-97ab-4a40-9226-5804f1927363";
start="<[email protected] <mailto:[email protected]>>
"; boundary="uuid:711b857f-bc2c-468a-be4c-9d7523477652"
[java] Headers: {Authorization=[BEARER
wd01hm0ScWBKQ8fQ1N6sedQEfjXAsbz2], A
ccept=[application/json], Connection=[Keep-Alive]}
[java] Payload: --uuid:20df8e8f-97ab-4a40-9226-5804f1927363
[java] Content-Type: application/json
[java] Content-Transfer-Encoding: binary
[java] Content-ID: <[email protected]
<mailto:[email protected]>>
[java]
[java]
{"outboundMessageRequest":{"address":"tel:7321112222","subject":"MMS
Attachments","priority":"Default","notifyDeliveryStatus":false}}
[java] --uuid:20df8e8f-97ab-4a40-9226-5804f1927363
[java] Content-Type:
multipart/related;start=smil;type=application/smil
[java] Content-Transfer-Encoding: binary
[java] Content-ID: <1>
[java]
[java] --uuid:711b857f-bc2c-468a-be4c-9d7523477652
[java] Content-Type: application/smil
[java] Content-Transfer-Encoding: binary
[java] Content-ID: <smil>
[java]
[java]
PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHNtaWw+Cgk8aGVh
ZD4KCQk8bGF5b3V0PgoJCQk8cm9vdC1sYXlvdXQgaGVpZ2h0PSIxMDAlIiB3aWR0aD0iMTAwJSIvPgoJ
CQk8cmVnaW9uIGZpdD0iaGlkZGVuIiBoZWlnaHQ9IjUwJSIgaWQ9IkltYWdlT3JWaWRlbyIgbGVmdD0i
MCIgdG9wPSI1MCUiIHdpZHRoPSIxMDAlIi8+CgkJCTxyZWdpb24gZml0PSJoaWRkZW4iIGhlaWdodD0i
NTAlIiBpZD0iVGV4dCIgbGVmdD0iMHB4IiB0b3A9IjUwJSIgd2lkdGg9IjEwMCUiLz4KCQk8L2xheW91
dD4KCTwvaGVhZD4KCTxib2R5PgoJCTxwYXI+CgkJCTxpbWcgcmVnaW9uPSJJbWFnZU9yVmlkZW8iIHNy
Yz0iY2lkOjAtaW1hZ2UiLz4KCQkJPHRleHQgcmVnaW9uPSJUZXh0IiBzcmM9ImNpZDowLXRleHQiLz4K
CQk8L3Bhcj4KCTwvYm9keT4KPC9zbWlsPgo=
[java] --uuid:20df8e8f-97ab-4a40-9226-5804f1927363--
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com