Craig McClanahan wrote:
> Larry Touve wrote:
>> I'm using Jersey for building OGC compliant Web Services. I'm currently
>> working on a Web Coverage Service, and discovered the
>> jersey-multipart code
>> that is just what I need. However, I have been unable to figure out
>> how to
>> set specific items in the header. Is it possible to set the
>> Content-ID and
>> the Content-Description for the BodyParts?
>>
>>
> You can definitely do this ... it will just require creating the body
> parts separately before stringing them together.
>
> BodyPart coverageBodyPart = new BodyPart();
> coverageBodyPart.setMediaType(MediaType.APPLICATION_XML_TYPE);
> coverageBodyPart.setEntity(coverageInfo);
> coverageBodyPart.getHeaders().putSingle("Content-ID", "xxx");
> coverageBodyPart.getHeaders().putSingle("Content-Description", "yyy");
>
I should also mention there are "builder pattern" methods in BodyPart to
do some of this as well, so you can simplify this a little bit more, to:
BodyPart coverageBodyPart = new BodyPart().
type(MediaType.APPLICATION_XML_TYPE).
entity(coverageInfo);
coverageBodyPart.getHeaders().putSingle("Content-ID", "xxx");
coverageBodyPart.getHeaders().putSingle("Content-Description", "yyy");
Look for the phrase "builder pattern" in the Javadocs for the supported
shortcuts that modify something and then return the updated instance, so
you can string the calls together. There's also lots of opportunities
for this in the JAX-RS APIs themselves.
Craig
> BodyPart imageBodyPart = new BodyPart();
> ... set this up in a similar manner ...
>
> MultiPart multiPart = new MultiPart().
> bodyPart(coverageBodyPart).
> bodyPart(imageBodyPart);
>
>> Thanks,
>> Larry
>>
>>
> Craig
>
>> Here's my code:
>>
>> @Path("/Coverage/{arg1}")
>> public class CoverageProvider {
>> :
>> @GET
>> @Produces("multipart/mixed")
>> public Response getCoverage() {
>> MultivaluedMap<String, String> map = uri.getPathParameters();
>> String arg1 = map.getFirst("arg1");
>> FileDataSource image = ... (gets the image file)
>> String coverageInfo = ... (gets the xml structured coverage
>> information)
>> MultiPart multiPart = new MultiPart().
>> bodyPart(new BodyPart(coverageInfo,
>> MediaType.APPLICATION_XML_TYPE)). bodyPart(new
>> BodyPart(image, new MediaType("image",
>> "nitf"))); return Response.ok(multiPart,
>> MultiPartMediaTypes.MULTIPART_MIXED_TYPE).build();
>> } :
>> }
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>