You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by SaravananRamamoorthy <sa...@gmail.com> on 2010/05/20 18:02:01 UTC

content location issue in attachment response

Hi All,

I am trying to send attachment as a response using Jax - RS.
The system gets the attachment details from Saaj api to Jax - RS and it need
to send as a response.

Please see the code below:

List<Attachment> responseAttach = new ArrayList<Attachment>();

while(attach.hasNext())  //attach is an Iterator receives from saaj
{
AttachmentPartImpl impl = attach.next();
MultiValuedMap<String,String> map = new MetadataMap<String,String>();
Iterator itr = impl.getAllMimeHeaders();
while(itr.hasNext())
{
 MimeHeader mimeHdr =(MimeHeader) itr.next();
 System.out.println("Name::"+mimeHdr.getName()+"Value::"+mimeHdr.getValue())
 map.add(mimeHdr.getName(),mimeHdr.getValue());

}
 
responseAttach.add(impl.getDataHandler().getInputStream(),map);

}
return responseAttach;

All the attachments are received correctly with the Content Header like
Content-ID,Content-Type.
But in the Content-Location I am facing the following issue.

>> First attachment having the Content-Location value correctly.The
>> subsequent Content-Location having only null values and it displays in
>> lower-case(content-location). But when I trace the Content-Location
>> inside the while loop it displays all the Content-Location properly.

Please provide the solution to fix this issue.

Regards
Saravanan Ramamoorthy








-- 
View this message in context: http://old.nabble.com/content-location-issue-in-attachment-response-tp28623343p28623343.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: content location issue in attachment response

Posted by Loh Kok Jeng <ko...@gmail.com>.
Hi Sergey,

To fix the extra angular "<>" brackets, I did the following changes:

apache-cxf-2.2.5\rt\core\src\main\java\org\apache\cxf\attachment\AttachmentSerializer.java

108,112c108,118
<             .append("\"; ")
<             .append("start=\"<")
<             .append(rootContentId)
<             .append(">\"; ")
<             .append("start-info=\"")
---
>             .append("\"; ");
>         if (rootContentId.startsWith("<"))
>             ct.append("start=\"");
>         else
>         	ct.append("start=\"<");
>         ct.append(rootContentId);
>         if (rootContentId.endsWith(">"))
>             ct.append("\"; ");
>         else
>         	ct.append(">\"; ");
>         ct.append("start-info=\"")


regards,
Loh Kok Jeng



On 22 May 2010 04:50, Sergey Beryozkin <sb...@gmail.com> wrote:
> Hi
>
> On Fri, May 21, 2010 at 5:54 AM, SaravananRamamoorthy <
> saravanan.ramamoorthy.s@gmail.com> wrote:
>
>>
>> Hi Sergey,
>>
>> As you said the Content-Location being changed to lower case.
>> I checked both while iterating the MimeHeaders (s.o.p in while) and I tried
>> to check the map values before sending the attachment. All having the
>> correct Name(including Content-Location) and Values.
>> Suppose I am sending 3 attachments, the first attachment having the Correct
>> Content-Location and its value. The ramaining 2 attachments having the
>> above
>> said issue.
>>
>>
> I think I've got it fixed. It occurs only when you have a case of the server
> 're-sending' the attachments, ex, gets them from a SOAP node and exposes
> again over plain HTTP. Basically, AttachmentImpl (created after reading the
> multipart stream) in rt/core used to convert the headers to lower-case. When
> you iterate over SAAJ attachments and use keys like "Content-Location",
> internally it is a 'content-location' key is used. Likewise when you iterate
> over CXF JAXRS Attachments and check the headers it works because they use
> case-insensitive maps internally.
>
> So I believe it is (AttachmentImpl) fixed now on the trunk/2.2.9-SNAPSHOT.
> In meantime what you need to do is to get headers explicitly from SAAJ
> attachments and add them using well-known keys, here is the updated code :
>
>
>>> List<Attachment> responseAttach = new ArrayList<Attachment>();
>>>
>>> while(attach.hasNext())  //attach is an Iterator receives from saaj
>>> {
>>> AttachmentPartImpl impl = attach.next();
>>> MultiValuedMap<String,String> map = new MetadataMap<String,String>();
>>> // get Content-Id, Content-Location, Content-Encoding, Content-Type
>>> MimeHeader mimeHdr =(MimeHeader) impl.getMimeHeader("Content-Location");
>>> map.add("Content-Location",mimeHdr.getValue());
>>> responseAttach.add(new
> Attachment(impl.getDataHandler().getInputStream(),map));
>>>
>>> }
>>> return responseAttach;
>
>
>
>> Even I hard-coded the Content-Location name and value pair and add it to
>> the
>> MultiValuedMap. It too having the same issue.
>>
>> But when I saw in the soapui, I faced the issue. Hence the map contains the
>> exact name and value pairs, but after sending the attachment the
>> Content-Location gets changed. I am not able to trigger out this issue.
>>
>> Regarding the angular braces, It is not in the Content-Id, In boundary of
>> the content header like
>>
>> boundary="uuid:97...";start="<<90>>".
>>
>> This is due to the fact that a Content-ID you're getting from SAAJ gives
> you <90> as opposed to 90. I've updated AttachmentSerializer to check for
> such brackets but at the moment you need to get Content-ID as suggested
> above and strip off '<' and '>' before adding it to the map.
>
> Alternatively, you can try 2.9-SNAPSHOT and confirm that the issue has been
> fixed
>
> cheers, Sergey
>
>
>> Please help me trigger out this issue.
>>
>> Regards
>> Saravanan R
>>
>>
>

Re: content location issue in attachment response

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

On Fri, May 21, 2010 at 5:54 AM, SaravananRamamoorthy <
saravanan.ramamoorthy.s@gmail.com> wrote:

>
> Hi Sergey,
>
> As you said the Content-Location being changed to lower case.
> I checked both while iterating the MimeHeaders (s.o.p in while) and I tried
> to check the map values before sending the attachment. All having the
> correct Name(including Content-Location) and Values.
> Suppose I am sending 3 attachments, the first attachment having the Correct
> Content-Location and its value. The ramaining 2 attachments having the
> above
> said issue.
>
>
I think I've got it fixed. It occurs only when you have a case of the server
're-sending' the attachments, ex, gets them from a SOAP node and exposes
again over plain HTTP. Basically, AttachmentImpl (created after reading the
multipart stream) in rt/core used to convert the headers to lower-case. When
you iterate over SAAJ attachments and use keys like "Content-Location",
internally it is a 'content-location' key is used. Likewise when you iterate
over CXF JAXRS Attachments and check the headers it works because they use
case-insensitive maps internally.

So I believe it is (AttachmentImpl) fixed now on the trunk/2.2.9-SNAPSHOT.
In meantime what you need to do is to get headers explicitly from SAAJ
attachments and add them using well-known keys, here is the updated code :


>> List<Attachment> responseAttach = new ArrayList<Attachment>();
>>
>> while(attach.hasNext())  //attach is an Iterator receives from saaj
>> {
>> AttachmentPartImpl impl = attach.next();
>> MultiValuedMap<String,String> map = new MetadataMap<String,String>();
>> // get Content-Id, Content-Location, Content-Encoding, Content-Type
>> MimeHeader mimeHdr =(MimeHeader) impl.getMimeHeader("Content-Location");
>> map.add("Content-Location",mimeHdr.getValue());
>> responseAttach.add(new
Attachment(impl.getDataHandler().getInputStream(),map));
>>
>> }
>> return responseAttach;



> Even I hard-coded the Content-Location name and value pair and add it to
> the
> MultiValuedMap. It too having the same issue.
>
> But when I saw in the soapui, I faced the issue. Hence the map contains the
> exact name and value pairs, but after sending the attachment the
> Content-Location gets changed. I am not able to trigger out this issue.
>
> Regarding the angular braces, It is not in the Content-Id, In boundary of
> the content header like
>
> boundary="uuid:97...";start="<<90>>".
>
> This is due to the fact that a Content-ID you're getting from SAAJ gives
you <90> as opposed to 90. I've updated AttachmentSerializer to check for
such brackets but at the moment you need to get Content-ID as suggested
above and strip off '<' and '>' before adding it to the map.

Alternatively, you can try 2.9-SNAPSHOT and confirm that the issue has been
fixed

cheers, Sergey


> Please help me trigger out this issue.
>
> Regards
> Saravanan R
>
>

Re: content location issue in attachment response

Posted by SaravananRamamoorthy <sa...@gmail.com>.
Hi Sergey,

As you said the Content-Location being changed to lower case.
I checked both while iterating the MimeHeaders (s.o.p in while) and I tried
to check the map values before sending the attachment. All having the
correct Name(including Content-Location) and Values.
Suppose I am sending 3 attachments, the first attachment having the Correct
Content-Location and its value. The ramaining 2 attachments having the above
said issue.

Even I hard-coded the Content-Location name and value pair and add it to the
MultiValuedMap. It too having the same issue.

But when I saw in the soapui, I faced the issue. Hence the map contains the
exact name and value pairs, but after sending the attachment the
Content-Location gets changed. I am not able to trigger out this issue.

Regarding the angular braces, It is not in the Content-Id, In boundary of
the content header like 

boundary="uuid:97...";start="<<90>>".

Please help me trigger out this issue.

Regards
Saravanan R








Sergey Beryozkin-5 wrote:
> 
> Hi
> 
> So what I understand is that the root part has a proper Content-Location
> (with C & L being capital) header, while all the remaining parts have a
> 'content-location' header thus when you try to get them (from SoapUI ?)
> you're getting 'null' because of a case-sensitivity issue... Is it what is
> happening ?
> 
> Also, you see double "<<" and ">>" Content-IDs, right ?
> 
> When you iterate over SAAJ attachments and print the headers, do you see
> the
> existing Content-ID values ? Are they already 'wrapped' with '<' and '>' ?
> CXF AttachmentSerializer also adds '<' and '>' too, so if yes then at the
> moment you'll need to ensure '<' and '>' are stripped and in meantime
> AttachmentSerializer can get fixed to check for '<' before appending '<'.
> 
> Also can you please try to iterate over List<Attachment>, after you've
> built
> it, and verify the headers have not been modified (i.e, you still see
> 'Content-Location' as opposed to 'content-location') ?
> 
> cheers, Sergey
> 
> On Thu, May 20, 2010 at 5:02 PM, SaravananRamamoorthy <
> saravanan.ramamoorthy.s@gmail.com> wrote:
> 
>>
>> Hi All,
>>
>> I am trying to send attachment as a response using Jax - RS.
>> The system gets the attachment details from Saaj api to Jax - RS and it
>> need
>> to send as a response.
>>
>> Please see the code below:
>>
>> List<Attachment> responseAttach = new ArrayList<Attachment>();
>>
>> while(attach.hasNext())  //attach is an Iterator receives from saaj
>> {
>> AttachmentPartImpl impl = attach.next();
>> MultiValuedMap<String,String> map = new MetadataMap<String,String>();
>> Iterator itr = impl.getAllMimeHeaders();
>> while(itr.hasNext())
>> {
>>  MimeHeader mimeHdr =(MimeHeader) itr.next();
>>
>> 
>> System.out.println("Name::"+mimeHdr.getName()+"Value::"+mimeHdr.getValue())
>>  map.add(mimeHdr.getName(),mimeHdr.getValue());
>>
>> }
>>
>> responseAttach.add(impl.getDataHandler().getInputStream(),map);
>>
>> }
>> return responseAttach;
>>
>> All the attachments are received correctly with the Content Header like
>> Content-ID,Content-Type.
>> But in the Content-Location I am facing the following issue.
>>
>> >> First attachment having the Content-Location value correctly.The
>> >> subsequent Content-Location having only null values and it displays in
>> >> lower-case(content-location). But when I trace the Content-Location
>> >> inside the while loop it displays all the Content-Location properly.
>>
>> Please provide the solution to fix this issue.
>>
>> Regards
>> Saravanan Ramamoorthy
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/content-location-issue-in-attachment-response-tp28623343p28623343.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/content-location-issue-in-attachment-response-tp28623343p28629634.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: content location issue in attachment response

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

So what I understand is that the root part has a proper Content-Location
(with C & L being capital) header, while all the remaining parts have a
'content-location' header thus when you try to get them (from SoapUI ?)
you're getting 'null' because of a case-sensitivity issue... Is it what is
happening ?

Also, you see double "<<" and ">>" Content-IDs, right ?

When you iterate over SAAJ attachments and print the headers, do you see the
existing Content-ID values ? Are they already 'wrapped' with '<' and '>' ?
CXF AttachmentSerializer also adds '<' and '>' too, so if yes then at the
moment you'll need to ensure '<' and '>' are stripped and in meantime
AttachmentSerializer can get fixed to check for '<' before appending '<'.

Also can you please try to iterate over List<Attachment>, after you've built
it, and verify the headers have not been modified (i.e, you still see
'Content-Location' as opposed to 'content-location') ?

cheers, Sergey

On Thu, May 20, 2010 at 5:02 PM, SaravananRamamoorthy <
saravanan.ramamoorthy.s@gmail.com> wrote:

>
> Hi All,
>
> I am trying to send attachment as a response using Jax - RS.
> The system gets the attachment details from Saaj api to Jax - RS and it
> need
> to send as a response.
>
> Please see the code below:
>
> List<Attachment> responseAttach = new ArrayList<Attachment>();
>
> while(attach.hasNext())  //attach is an Iterator receives from saaj
> {
> AttachmentPartImpl impl = attach.next();
> MultiValuedMap<String,String> map = new MetadataMap<String,String>();
> Iterator itr = impl.getAllMimeHeaders();
> while(itr.hasNext())
> {
>  MimeHeader mimeHdr =(MimeHeader) itr.next();
>
>  System.out.println("Name::"+mimeHdr.getName()+"Value::"+mimeHdr.getValue())
>  map.add(mimeHdr.getName(),mimeHdr.getValue());
>
> }
>
> responseAttach.add(impl.getDataHandler().getInputStream(),map);
>
> }
> return responseAttach;
>
> All the attachments are received correctly with the Content Header like
> Content-ID,Content-Type.
> But in the Content-Location I am facing the following issue.
>
> >> First attachment having the Content-Location value correctly.The
> >> subsequent Content-Location having only null values and it displays in
> >> lower-case(content-location). But when I trace the Content-Location
> >> inside the while loop it displays all the Content-Location properly.
>
> Please provide the solution to fix this issue.
>
> Regards
> Saravanan Ramamoorthy
>
>
>
>
>
>
>
>
> --
> View this message in context:
> http://old.nabble.com/content-location-issue-in-attachment-response-tp28623343p28623343.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
>