[jboss-user] [JBoss Web Services] - Using MutlipartInput via ClientRequest

Kevin Moodley do-not-reply at jboss.com
Wed May 19 23:42:54 EDT 2010


Kevin Moodley [http://community.jboss.org/people/kevinmoodley] created the discussion

"Using MutlipartInput via ClientRequest"

To view the discussion, visit: http://community.jboss.org/message/543949#543949

--------------------------------------------------------------
Does anyone have an example of how to set up a request with MultipartInput using the ClientRequest class ?

I tried something like this - without success :


Client:

        String url =  http://localhost:8080/resteasy/test http://localhost:8080/resteasy/test
        ClientRequest request = new ClientRequest(url);
        Customer customer = new Customer("kmoodley");
        StringBuilder resource = new StringBuilder(JAXBMarshall.marshall(customer));
        User user = new User("kmoodley");
        resource.append("SECURE_USER");
        resource.append(JAXBMarshall.marshall(user));
        Map<String, String> parameters = new HashMap<String, String>();
        parameters.put("boundary", "SECURE_USER");
        MediaType contentType = new MediaType("multipart",null,parameters);
        MultipartInputImpl input = new MultipartInputImpl(contentType, ResteasyProviderFactory.getInstance());
        ByteArrayInputStream bais = new ByteArrayInputStream(resource.toString().getBytes());
        input.parse(bais);
        request.body(contentType, input );
        response = request.post();


The JAXBMarshall class is a utility class that marshalls classes annotated with @XmlRootElement into XML


Server:

    @POST
    @Path("/resteasy/test")
    @Produces("application/xml")
    @Consumes("multipart/mixed")
    public String testMultipart(MultipartInput input) {
        Customer customer = null;
        User user = null;
        for (InputPart part : input.getParts()){
            try {
                customer = part.getBody(Customer.class, null);
                user = part.getBody(User.class, null);
            } catch (IOException e) {
                logger.error("Failed to get objects from multipart input");
                return null;
            }
        }
        ....
        
        return "SUCCESS";
    }


Thanks

Kevin

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

Reply to this message by going to Community
[http://community.jboss.org/message/543949#543949]

Start a new discussion in JBoss Web Services at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2044]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100519/4810cfb1/attachment.html 


More information about the jboss-user mailing list