From user-return-219102-archive-asf-public=cust-asf.ponee.io@struts.apache.org Mon Oct 8 11:07:00 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 64487180652 for ; Mon, 8 Oct 2018 11:07:00 +0200 (CEST) Received: (qmail 66245 invoked by uid 500); 8 Oct 2018 09:06:59 -0000 Mailing-List: contact user-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list user@struts.apache.org Received: (qmail 66229 invoked by uid 99); 8 Oct 2018 09:06:58 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Oct 2018 09:06:58 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id E2622C60FF for ; Mon, 8 Oct 2018 09:06:57 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3 X-Spam-Level: *** X-Spam-Status: No, score=3 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=2, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id zF-bw4v7bdFk for ; Mon, 8 Oct 2018 09:06:56 +0000 (UTC) Received: from sg2plsmtpa01-01.prod.sin2.secureserver.net (sg2plsmtpa01-01.prod.sin2.secureserver.net [182.50.145.6]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 9ADDE5F36F for ; Mon, 8 Oct 2018 09:06:55 +0000 (UTC) Received: from [192.168.0.2] ([49.206.11.63]) by :SMTPAUTH: with ESMTPSA id 9RV1gvrAlKnM99RV2g610c; Mon, 08 Oct 2018 02:06:48 -0700 To: user@struts.apache.org From: Nikhil P Kookkiri Subject: Struts2 - multipart/related - HttpServletRequest#getParts not working Message-ID: <7e17e561-21fc-51ac-263f-209018a88bdb@sicurosolutions.com> Date: Mon, 8 Oct 2018 14:36:47 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------F68AA1589E549490F8C04C08" Content-Language: en-US X-CMAE-Envelope: MS4wfHWw22/WXAeyYrQ7bK6vyoxlwVU+5UzK/ArVp5FFsAD9LQG1e6c1AftACM1DPnSfwH9tj5eVD3yy6Fmw8j/aK3jlBlOtbVye0+mUzkqyB9Hvo/o05OK3 c4trhDFRFFXwNMbSBXd+UAcp77dNNxw0DMA94sJnTjpAh1/3bGoJ/d6Ektw/OK92n0n5Au/+Cly55Q== --------------F68AA1589E549490F8C04C08 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit I have request coming from another application which is 'multipart/related'. In the mutlipart request body, I am receiving image/jpeg and application/xml. I suppose, I should be iterating over the http part obtained from getPaths method in the HttpServletRequest object and read the stream available on each of the parts. When I try doing that, I am getting the following error: java.lang.IllegalStateException: UT010057: multipart config was not present on Servlet ERROR [stderr] (default task-2)     at io.undertow.servlet//io.undertow.servlet.spec.HttpServletRequestImpl.verifyMultipartServlet(HttpServletRequestImpl.java:523) ERROR [stderr] (default task-2)     at io.undertow.servlet//io.undertow.servlet.spec.HttpServletRequestImpl.getParts(HttpServletRequestImpl.java:512) ERROR [stderr] (default task-2)     at javax.servlet.api//javax.servlet.http.HttpServletRequestWrapper.getParts(HttpServletRequestWrapper.java:375) Please let me know the best possible solution for this. Here is what I am doing in the code:     public class TestMultiPart extends ActionSupport implements ServletRequestAware     {         private InputStream inputStream;         private HttpServletRequest request;     public String execute()     {         BufferedInputStream bis = null;         BufferedOutputStream bos = null;         try         {             Collection parts = request.getParts();             for(Part part : parts)             {                 String contentType = part.getContentType();                 System.out.println("Content type is: " + contentType);                 File file = getFileToDownload(getContentType(contentType));                 if(file != null)                 {                     bis = new BufferedInputStream(request.getInputStream());                     bos = new BufferedOutputStream(new FileOutputStream(file));                     byte[] bytes = new byte[bis.available()];                     while(bis.read(bytes) > 0)                     {                         bos.write(bytes);                         bos.flush();                         bytes = new byte[bis.available()];                     }                 }             }         } catch (IOException e) {             // TODO Auto-generated catch block             e.printStackTrace();         } catch (ServletException e) {             // TODO Auto-generated catch block             e.printStackTrace();         } finally {             if(bis != null)             {                 try {                     bis.close();                 } catch (IOException e) {                     // TODO Auto-generated catch block                     e.printStackTrace();                 }             }             if(bos != null)             {                 try {                     bos.close();                 } catch (IOException e) {                     // TODO Auto-generated catch block                     e.printStackTrace();                 }             }         }         inputStream = new ByteArrayInputStream("200".getBytes(StandardCharsets.UTF_8));         return SUCCESS;     }     public InputStream getInputStream() {         return inputStream;     }     public void setInputStream(InputStream inputStream) {         this.inputStream = inputStream;     }     @Override     public void setServletRequest(HttpServletRequest requestObject)     {         this.request = requestObject;     } } -- Best regards, Nikhil P kookkiri Gtalk: nikhil.pk81 Skype: nikhil.pk81 --------------F68AA1589E549490F8C04C08--