[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 :


        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");
        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());
        request.body(contentType, input );
        response = request.post();

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


    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";




Reply to this message by going to Community

Start a new discussion in JBoss Web Services at Community

-------------- 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