struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yasser Zamani <yasserzam...@apache.org>
Subject RE: Struts2 - multipart/related - HttpServletRequest#getParts not working
Date Tue, 09 Oct 2018 08:47:21 GMT
I see Struts REST plugin has a handler for multipart request but it and even the whole Struts
framework also talks only about multipart/form-data ;) Unfortunately it seems Struts doesn't
know such content type at all. Anyway, some tips can be found in net via googling "UT010016:
Not a multi part request".

Regards.

>-----Original Message-----
>From: Nikhil P Kookkiri <nikhil.kookkiri@sicurosolutions.com>
>Sent: Tuesday, October 9, 2018 10:05 AM
>To: Struts Users Mailing List <user@struts.apache.org>; Yasser Zamani
><yasserzamani@apache.org>
>Subject: Re: Struts2 - multipart/related - HttpServletRequest#getParts not
>working
>
>
>Hi Yesser, thanks for your response. Yes, it is the issue with the servlet. I am
>suspecting that MutiPartConfig works only for multipart/form-data and does not
>work with multipart/related. I passed the request directly to HttpServlet instead
>of Sturts mapped Action with @MultiPartConfig configured and I got the
>exception:
>javax.servlet.ServletException: UT010016: Not a multi part request.
>Almost all documentation I saw talks only about multipart/form-data.
>
>I am assuming using Struts rest plugin also will not help in this case.
>Kindly let me know.
>
>Best regards,
>Nikhil P kookkiri
>
>On Tuesday 09 October 2018 11:02 AM, Yasser Zamani wrote:
>> This isn't Struts issue but your underlying servlet message. Anyway, what about
>trying Struts itself file upload feature. Then ask that another app to http post the
>file to a file upload action.
>>
>> Regards.
>>
>>> -----Original Message-----
>>> From: Nikhil P Kookkiri <nikhil.kookkiri@sicurosolutions.com>
>>> Sent: Monday, October 8, 2018 12:37 PM
>>> To: user@struts.apache.org
>>> Subject: Struts2 - multipart/related - HttpServletRequest#getParts
>>> not working
>>>
>>> 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.
>>> verifyMul
>>> tipartServlet(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.getPa
>>> rts(HttpSer
>>> vletRequestWrapper.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<Part> 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
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org

Mime
View raw message