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
6bf53f68
authored
2014-01-20 17:38:01 -0600
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'BFP-1784' of /home/git/repositories/brainfood/java-nginx-upload-processor
2 parents
ab099caf
7954523f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
15 deletions
src/com/brainfood/servlet/NGINXUploadProcessor.java
src/com/brainfood/servlet/NGINXUploadProcessor.java
View file @
6bf53f6
...
...
@@ -18,15 +18,17 @@ 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
;
final
class
ProgressRecord
{
final
boolean
complete
;
final
long
bytesRead
;
final
long
contentLength
;
final
int
items
;
public
ProgressRecord
(
long
bytesRead
,
long
contentLength
,
int
items
)
{
public
ProgressRecord
(
long
bytesRead
,
long
contentLength
,
int
items
,
boolean
complete
)
{
this
.
bytesRead
=
bytesRead
;
this
.
contentLength
=
contentLength
;
this
.
items
=
items
;
this
.
complete
=
complete
;
}
}
...
...
@@ -65,12 +67,8 @@ public class NGINXUploadProcessor extends HttpServlet {
System
.
err
.
println
(
"QUERY PROGRESS: ["
+
xProgressId
+
"] - "
+
progress
.
get
(
xProgressId
));
if
(
xProgressId
!=
null
&&
progress
.
get
(
xProgressId
)
!=
null
)
{
ProgressRecord
record
=
progress
.
get
(
xProgressId
);
String
status
=
"done"
;
if
(
record
.
bytesRead
<
record
.
contentLength
)
{
status
=
"uploading"
;
}
out
.
println
(
"({ \"state\" : \""
+
status
+
"\", \"received\" : "
+
record
.
bytesRead
+
", \"size\" : "
+
record
.
contentLength
+
" });"
);
out
.
println
(
"({ \"state\" : \""
+
(
record
.
complete
?
"done"
:
"uploading"
)
+
"\", \"received\" : "
+
record
.
bytesRead
+
", \"size\" : "
+
record
.
contentLength
+
" });"
);
}
else
{
out
.
println
(
"({ \"error\" : \"Invalid X-Progress-ID\" });"
);
}
...
...
@@ -78,7 +76,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
,
false
));
if
(
ServletFileUpload
.
isMultipartContent
(
request
))
{
// Create a factory for disk-based file items
...
...
@@ -108,9 +106,9 @@ public class NGINXUploadProcessor extends HttpServlet {
this
.
progress
=
progress
;
}
@Override
public
void
update
(
long
sent
,
long
l
ength
,
int
items
)
{
System
.
err
.
println
(
"PROGRESS: "
+
sent
+
" "
+
l
ength
+
" "
+
items
);
progress
.
put
(
xProgressId
,
new
ProgressRecord
(
sent
,
length
,
items
));
public
void
update
(
long
bytesRead
,
long
contentL
ength
,
int
items
)
{
System
.
err
.
println
(
"PROGRESS: "
+
bytesRead
+
" "
+
contentL
ength
+
" "
+
items
);
progress
.
put
(
xProgressId
,
new
ProgressRecord
(
bytesRead
,
contentLength
,
items
,
false
));
}
};
...
...
@@ -132,6 +130,9 @@ public class NGINXUploadProcessor extends HttpServlet {
String
pResponse
=
http
.
post
();
System
.
err
.
println
(
"FINISHED:"
+
pResponse
);
out
.
print
(
pResponse
);
ProgressRecord
oldRecord
=
progress
.
get
(
xProgressId
);
progress
.
put
(
xProgressId
,
new
ProgressRecord
(
oldRecord
.
bytesRead
,
oldRecord
.
contentLength
,
oldRecord
.
items
,
true
));
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
...
...
Please
register
or
sign in
to post a comment