Dear all,

I'm implementing a REST server using CXF.  I would like to return a
multipart/related response to the client.  Unfortunately, the
Content-Location header of the multipart attachment, e.g.:
"Content-Location: image.jpg", is always set to "content-location:
null".  Below is an example:

--uuid:1fb1641b-124e-4f3f-8598-4a90831d980a
Content-Type: image/jpeg;Name=albumart.jpg
Content-Transfer-Encoding: binary
Content-ID: <819382211784.1274417053011.ibm.webservi...@toolapdv02>
content-location: null

In my code, the Content-Location header is correctly added to a map,
and the MutipartBody object has been created correctly.  However, the
response received by the client still contains incorrect
"Content-Location" header in the attachments.

Can anyone help?  Thanks.

@Path("/mmsMessage")
@Produces("multipart/related")
public class MmsMessageServices {

        Logger log = Logger.getLogger(getClass());
        MMSReciveMessageClient receiveclient = new MMSReciveMessageClient();
        ErrorBean errorbean = new ErrorBean();
        NsnException exception = new NsnException();

        @GET
        // public List<Attachment> getMessage(@HeaderParam("Authorization") 
String
        // authorization,@Context MessageContext mc,
        public MultipartBody getMessage(
                        @HeaderParam("Authorization") String authorization,
                        @Context MessageContext mc,
                        @QueryParam("messageIdentifier") String 
messageIdentifier)
                        throws FileNotFoundException {
                log.info("getMessage Rest operation has been called");
                log.info("Requested URI::" + mc.getUriInfo().getRequestUri());
                Map<String, String> credentials = null;
                Iterator<AttachmentPartImpl> attach = null;
                List<Attachment> responseAttach = new LinkedList<Attachment>();
                
                if (messageIdentifier == null) {
                        throw new WebApplicationException(400);
                }

                if (authorization == null) {
                        throw new WebApplicationException(401);
                } else {
                        BasicAuthorizationConversion basicauth = new 
BasicAuthorizationConversion();
                        credentials = basicauth.getCredentials(authorization);
                }
                GetMessage param = new GetMessage();
                try {
                        param.setMessageRefIdentifier(messageIdentifier);
                        attach = receiveclient.getMessage(param, credentials);

                        if (attach.hasNext()) {
                                while (attach.hasNext()) {
                                        MultivaluedMap<String, String> map = 
new MetadataMap<String, String>();
                                        AttachmentPartImpl impl = attach.next();

                                        Iterator<MimeHeader> itor = 
impl.getAllMimeHeaders();
                                        while (itor.hasNext()) {
                                                MimeHeader mimeHdr = 
(MimeHeader) itor.next();
                                                map.add(mimeHdr.getName(), 
mimeHdr.getValue());
                                        }

                                        log.info("Incoming Headers: " + 
map.toString());
                                        Attachment attachment = new 
Attachment(impl
                                                        
.getDataHandler().getInputStream(), map);

                                        log.info("Outgoing Headers: "
                                                        + 
attachment.getHeaders().toString());
                                        responseAttach.add(attachment);
                                        // map.clear();
                                        // responseAttach.add(new
                                        // 
Attachment(impl.getContentId(),impl.getContentType(),impl.getDataHandler().getInputStream()));
                                }
                                for (int i = 0; i < responseAttach.size(); i++) 
{
                                        log.info("responseAttach[" + i + "]: "
                                                        + 
responseAttach.get(i).getHeaders().toString());
                                }
                        }

                } catch (MalformedURLException malexp) {
                        log.error("MalformedURLException::" + 
malexp.getMessage());
                } catch (ServiceException se) {
                        log.error("ServiceException::" + se.getMessage());
                        errorbean = exception.getServiceException(se);
                        throw new ServicePolicyException(errorbean);
                } catch (PolicyException pe) {
                        log.error("PolicyException::" + pe.getMessage());
                        errorbean = exception.getPolicyException(pe);
                        throw new ServicePolicyException(errorbean);
                } catch (SOAPFaultException soapexp) {
                        log.error("SOAPFaultException::" + 
soapexp.getMessage());
                        errorbean = exception.getSOAPFaultException(soapexp);
                        throw new ServicePolicyException(errorbean);
                } catch (WebApplicationException webexp) {
                        log.error("WebApplication exception::" + 
webexp.getMessage());
                } catch (WebServiceException webserviceexp) {
                        if 
(webserviceexp.getMessage().contains("Unauthorized")) {
                                throw new WebApplicationException(401);
                        } else {
                                log.fatal("WebServiceException::" + 
webserviceexp.getMessage());
                                throw new WebApplicationException(500);
                        }
                } catch (Exception exp) {
                        log.error("Exception::" + exp.getMessage());
                }
                log.info("response has been succesfully received from toolbox");

                // return responseAttach;
                return new MultipartBody(responseAttach, true);
        }

}

regards,
KJLoh

Reply via email to