java.net.SocketTimeoutException downloading large files from tomcat

2018-01-30 Thread Anthony Shaya
Hello,

I'm using tomcat 8.5.15 and spring 4.3.3 framework for our server application 
(hosted on centos 6 machines). I have noticed we get the below exception 
(java.net.SocketTimeoutException) when people are downloading files from our 
server that are over 500 mb (many of the files are around a gb in size). 
Usually the behavior on the browser (firefox or chrome) is the download 
completes but the file is corrupt (zip in this case). The file size is off by 
10mb each time. I've verified the actual files are valid on the servers file 
system. The only workaround I've found is to increase the connection timeout 
from 20seconds to 180 seconds (although I'm not sure why this would even 
matter). This seems to have fixed the issue, even though today we found another 
case after the timeout was increased where the issue resurfaced.


  *   This only seems to happen on our application when the downloads go over 
internet/network. Our local builds of the server application do not reproduce 
the problem.
  *   I've confirmed that firefox and chrome have the same issue and are not 
aborting the connection/download.
  *   I've attached the relevant stack trace, tomcat connector settings, 
relevant spring settings, and the code that does the sending of the file.


Any help or suggestions for troubleshooting would be much appreciated!


30-Jan-2018 15:16:23.130 SEVERE [http-nio-9000-exec-4] 
org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for 
servlet [spring] in context with path [/] threw exception [Request processing 
failed; nested exception is java.lang.RuntimeException: Problem sending file 
distributions/ZIP_NAME.zip] with root cause
java.net.SocketTimeoutException
   at 
org.apache.tomcat.util.net.NioBlockingSelector.write(NioBlockingSelector.java:134)
   at 
org.apache.tomcat.util.net.NioSelectorPool.write(NioSelectorPool.java:157)
   at 
org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.doWrite(NioEndpoint.java:1259)
   at 
org.apache.tomcat.util.net.SocketWrapperBase.doWrite(SocketWrapperBase.java:670)
   at 
org.apache.tomcat.util.net.SocketWrapperBase.writeBlocking(SocketWrapperBase.java:450)
   at 
org.apache.tomcat.util.net.SocketWrapperBase.write(SocketWrapperBase.java:388)
   at 
org.apache.coyote.http11.Http11OutputBuffer$SocketOutputBuffer.doWrite(Http11OutputBuffer.java:644)
   at 
org.apache.coyote.http11.filters.IdentityOutputFilter.doWrite(IdentityOutputFilter.java:119)
   at 
org.apache.coyote.http11.Http11OutputBuffer.doWrite(Http11OutputBuffer.java:235)
   at org.apache.coyote.Response.doWrite(Response.java:568)
   at 
org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:351)
   at 
org.apache.catalina.connector.OutputBuffer.flushByteBuffer(OutputBuffer.java:815)
   at 
org.apache.catalina.connector.OutputBuffer.append(OutputBuffer.java:720)
   at 
org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:391)
   at 
org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:369)
   at 
org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:96)
   at 
org.springframework.security.web.context.SaveContextOnUpdateOrErrorResponseWrapper$SaveContextServletOutputStream.write(SaveContextOnUpdateOrErrorResponseWrapper.java:457)
   at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1793)
   at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1769)
   at org.apache.commons.io.IOUtils.copy(IOUtils.java:1744)


Below is my connector settings (fairly default)




Below is the spring bean we use for handling the multi part file upload
  


  *   I'm aware of 
spring.http.multipart.max-file-size,pring.http.multipart.max-request-size and 
confirmed they are not set, resulting in the default of -1 being used for both.

Below is the actual code we use to send the file to the client

  public static void setDownloadContentHeaders(String fileName, boolean 
forceDownload, HttpServletResponse response, HttpServletRequest request) {
response.setContentType(request.getServletContext().getMimeType(fileName));
String contentDisposition = forceDownload ? "attachment" : "inline";
response.setHeader("Content-Disposition", contentDisposition + "; 
filename=\"" + fileName + "\"");
  }

  public void sendFile(String path, boolean forceDownload, HttpServletRequest 
request, HttpServletResponse response) {
try {
  // File to be downloaded
  File downloadFile = getFile(path); //this method just loads the file from 
disk
  if (!downloadFile.exists()) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
  }

  try(InputStream fis = new FileInputStream(downloadFile)) {
// Serve individual file

Re: Password Protected

2018-01-30 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Vicky,

On 1/30/18 11:10 AM, Vicky B wrote:
> Can i check if (xlx,xlsx, doc )  file is password protected through
> apache poi and can i use apache PDFBOX  to check if PDF file is
> password protected.

Maybe?

- -chris

PS I think you posted to the wrong list.
-BEGIN PGP SIGNATURE-
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQJRBAEBCAA7FiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlpwyJQdHGNocmlzQGNo
cmlzdG9waGVyc2NodWx0ei5uZXQACgkQHPApP6U8pFgTAQ/9FLYr3P8ikJUUJuyM
QUWS1i+XuJUl5aR3bWJcSuVf7ngCMUVhmFZ6ylL47ekn3aeunBgYj5hxFW6QbVeu
ttlpdU6/nimtjeA0H2s0Ne3yN+x3XlfTIeHTlHuTXwPSeZOMgoP6PCCkqs315vF4
vBmxVhcNZ55yKkyYxiX19/qRpylx3IQJ0R6MkoP93Nu93TDuP7OtM/FzwIATjqPw
FQEzifOOwOzXVEdroXOjydhH9eg4ISq9sT7cWYp6REB/wfwbuQP2BKr5B5+IlMPM
HIEZKrEqMHeHclEMYvri+wy40qLn/BBI+RsGX2f+uwjEldtLUm3RRZlFyLPrx8Vk
4WSEtDLCOLFXecAbvr2XFCeJbf5GUsQHSdcVyebfzjOSxs7f3Mz2kWiks9mVrhxE
LurIEsJw7KlW08KDQ7un5h1fSB/lUYft2Ix1jGTzBAhDPQ700VNKfUp/6cmWeiQm
uYWFXJ6kf0ix18b6G6WvZgRFbCPREV6yYZY4/CzVgzNqGBNUQJuFtiwROm6FIgIK
15P4BeYwzgzBRNLWmTZoy4IMQfUvXxiUV8ep860mOxFt2kapmxsEfzpT6YvIFeBx
XtNfSCf9LHRWH5kahBumFwdNSMMs1s7VExzbMO/blmRdK4DnD5aOWPUEPiSyXn2P
B3S2KOSq3tV1/VsOA/4L9nbo9k8=
=CkuO
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Password Protected

2018-01-30 Thread Vicky B
Hi ,

Can i check if (xlx,xlsx, doc )  file is password protected through apache
poi and can i use apache PDFBOX  to check if PDF file is password protected.

-- 



*Thanks & Regards Vickyb*


How to make Tomcat 7.0.52 and newer ones compatible regarding filter HttpHeaderSecurity?

2018-01-30 Thread Thorsten Schöning
Hi all,

in production I'm still running Ubuntu 14.04 LTS Server which provides
Tomcat 7.0.52, which doesn't contain the filter for HttpHeaderSecurity
yet[1]. Some of my customers on the other hand use Windows and run
newer versions of Tomcat which already support that filter. To not
force customers to change global Tomcat settings and to document that
my app is compatible, I would like to add HttpHeaderSecurity to the
web.xml of my own app with the correct settings. That breaks in my own
Ubuntus of course.

So, is there some way to get old and new Tomcats together if my app's
web.xml uses that filter?

Frist thing I tried was simply providing the implementation in the
classpath of my own app, which didn't work. Should that work in theory
and I most likely did something wrong or are those filters only
expected to be in the classpath of Tomcat itself? I'm using
"UrlRewriteFilter"[2] bundled with my app, configured in my web.xml
and that works.

Else, is there some condition for filters to only apply those
depending on e.g. the version of Tomcat or such? The only similar
question I found were pretty old and maybe things have changed since
then.

https://mail-archives.apache.org/mod_mbox/tomcat-users/200808.mbox/<4893749f.3070...@ice-sa.com>

Thanks for your input!

[1]: https://stackoverflow.com/a/35795122/2055163
[2]: http://tuckey.org/urlrewrite/

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning   E-Mail: thorsten.schoen...@am-soft.de
AM-SoFT IT-Systeme  http://www.AM-SoFT.de/

Telefon...05151-  9468- 55
Fax...05151-  9468- 88
Mobil..0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org