0 Replies Latest reply on May 19, 2010 11:42 PM by Kevin Moodley

    Using MutlipartInput via ClientRequest

    Kevin Moodley Newbie

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