Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
java-nginx-upload-processor
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
ab099caf
authored
2014-01-20 16:18:16 -0600
by
Ean Schuessler
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Replace tabs with 4 spaces.
1 parent
707be16d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
57 deletions
src/com/brainfood/servlet/NGINXUploadProcessor.java
src/com/brainfood/servlet/NGINXUploadProcessor.java
View file @
ab099ca
...
...
@@ -18,47 +18,47 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload;
import
org.ofbiz.base.util.HttpClient
;
public
class
NGINXUploadProcessor
extends
HttpServlet
{
class
ProgressRecord
{
long
bytesRead
;
long
contentLength
;
int
items
;
public
ProgressRecord
(
long
bytesRead
,
long
contentLength
,
int
items
)
{
this
.
bytesRead
=
bytesRead
;
this
.
contentLength
=
contentLength
;
this
.
items
=
items
;
}
}
class
ProgressRecord
{
long
bytesRead
;
long
contentLength
;
int
items
;
public
ProgressRecord
(
long
bytesRead
,
long
contentLength
,
int
items
)
{
this
.
bytesRead
=
bytesRead
;
this
.
contentLength
=
contentLength
;
this
.
items
=
items
;
}
}
private
static
final
long
serialVersionUID
=
1L
;
private
ServletConfig
config
;
private
static
final
ConcurrentHashMap
<
String
,
ProgressRecord
>
progress
=
new
ConcurrentHashMap
<
String
,
ProgressRecord
>();
private
static
final
long
serialVersionUID
=
1L
;
private
ServletConfig
config
;
private
static
final
ConcurrentHashMap
<
String
,
ProgressRecord
>
progress
=
new
ConcurrentHashMap
<
String
,
ProgressRecord
>();
@Override
public
void
destroy
()
{
// TODO Auto-generated method stub
}
@Override
public
void
destroy
()
{
// TODO Auto-generated method stub
}
@Override
public
ServletConfig
getServletConfig
()
{
// TODO Auto-generated method stub
return
this
.
config
;
}
@Override
public
ServletConfig
getServletConfig
()
{
// TODO Auto-generated method stub
return
this
.
config
;
}
@Override
public
String
getServletInfo
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
String
getServletInfo
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
void
init
(
ServletConfig
config
)
throws
ServletException
{
this
.
config
=
config
;
}
@Override
public
void
init
(
ServletConfig
config
)
throws
ServletException
{
this
.
config
=
config
;
}
@Override
public
void
service
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
@Override
public
void
service
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
if
(
request
.
getRequestURI
().
contains
(
"progress"
))
{
PrintWriter
out
=
new
PrintWriter
(
response
.
getWriter
());
String
xProgressId
=
request
.
getHeader
(
"X-Progress-ID"
);
...
...
@@ -70,7 +70,7 @@ public class NGINXUploadProcessor extends HttpServlet {
status
=
"uploading"
;
}
out
.
println
(
"({ \"state\" : \""
+
status
+
"\", \"received\" : "
+
record
.
bytesRead
+
", \"size\" : "
+
record
.
contentLength
+
" });"
);
record
.
bytesRead
+
", \"size\" : "
+
record
.
contentLength
+
" });"
);
}
else
{
out
.
println
(
"({ \"error\" : \"Invalid X-Progress-ID\" });"
);
}
...
...
@@ -78,7 +78,7 @@ public class NGINXUploadProcessor extends HttpServlet {
}
else
{
String
xProgressId
=
request
.
getParameter
(
"X-Progress-ID"
);
System
.
err
.
println
(
"STORE: ["
+
xProgressId
+
"]"
);
progress
.
put
(
xProgressId
,
new
ProgressRecord
(-
1
,
0
,
1
));
progress
.
put
(
xProgressId
,
new
ProgressRecord
(-
1
,
0
,
1
));
if
(
ServletFileUpload
.
isMultipartContent
(
request
))
{
// Create a factory for disk-based file items
...
...
@@ -97,29 +97,29 @@ public class NGINXUploadProcessor extends HttpServlet {
// Parse the request
PrintWriter
out
=
new
PrintWriter
(
response
.
getWriter
());
try
{
Map
<
String
,
FileItem
>
itemMap
=
new
HashMap
<
String
,
FileItem
>();
Map
<
String
,
FileItem
>
itemMap
=
new
HashMap
<
String
,
FileItem
>();
class
UploadProgressListener
implements
ProgressListener
{
String
xProgressId
;
Map
<
String
,
ProgressRecord
>
progress
;
public
UploadProgressListener
(
String
xProgressId
,
Map
<
String
,
ProgressRecord
>
progress
)
{
this
.
xProgressId
=
xProgressId
;
this
.
progress
=
progress
;
}
@Override
public
void
update
(
long
sent
,
long
length
,
int
items
)
{
System
.
err
.
println
(
"PROGRESS: "
+
sent
+
" "
+
length
+
" "
+
items
);
progress
.
put
(
xProgressId
,
new
ProgressRecord
(
sent
,
length
,
items
));
}
};
ProgressListener
listener
=
(
ProgressListener
)
new
UploadProgressListener
(
xProgressId
,
this
.
progress
);
upload
.
setProgressListener
(
listener
);
class
UploadProgressListener
implements
ProgressListener
{
String
xProgressId
;
Map
<
String
,
ProgressRecord
>
progress
;
public
UploadProgressListener
(
String
xProgressId
,
Map
<
String
,
ProgressRecord
>
progress
)
{
this
.
xProgressId
=
xProgressId
;
this
.
progress
=
progress
;
}
@Override
public
void
update
(
long
sent
,
long
length
,
int
items
)
{
System
.
err
.
println
(
"PROGRESS: "
+
sent
+
" "
+
length
+
" "
+
items
);
progress
.
put
(
xProgressId
,
new
ProgressRecord
(
sent
,
length
,
items
));
}
};
ProgressListener
listener
=
(
ProgressListener
)
new
UploadProgressListener
(
xProgressId
,
this
.
progress
);
upload
.
setProgressListener
(
listener
);
List
<
FileItem
>
items
=
(
List
<
FileItem
>)
upload
.
parseRequest
(
request
);
for
(
FileItem
item
:
items
)
{
itemMap
.
put
(
item
.
getFieldName
(),
item
);
itemMap
.
put
(
item
.
getFieldName
(),
item
);
}
HashMap
parameters
=
new
HashMap
();
...
...
@@ -142,5 +142,5 @@ public class NGINXUploadProcessor extends HttpServlet {
out
.
close
();
}
}
}
}
}
...
...
Please
register
or
sign in
to post a comment