Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Alignment API
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
moex
Alignment API
Commits
de7c17c6
Commit
de7c17c6
authored
10 years ago
by
Jérôme Euzenat
Browse files
Options
Downloads
Patches
Plain Diff
- cleaned up and secured fileupload implementation
parent
8ee50c67
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/fr/inrialpes/exmo/align/service/HTTPTransport.java
+8
-36
8 additions, 36 deletions
src/fr/inrialpes/exmo/align/service/HTTPTransport.java
with
8 additions
and
36 deletions
src/fr/inrialpes/exmo/align/service/HTTPTransport.java
+
8
−
36
View file @
de7c17c6
...
@@ -52,6 +52,7 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
...
@@ -52,6 +52,7 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import
org.apache.commons.fileupload.servlet.ServletFileUpload
;
import
org.apache.commons.fileupload.servlet.ServletFileUpload
;
import
org.apache.commons.fileupload.FileItem
;
import
org.apache.commons.fileupload.FileItem
;
import
org.apache.commons.fileupload.FileUploadException
;
import
org.apache.commons.fileupload.FileUploadException
;
import
org.apache.commons.io.FilenameUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -90,22 +91,6 @@ public class HTTPTransport {
...
@@ -90,22 +91,6 @@ public class HTTPTransport {
tcpPort
=
Integer
.
parseInt
(
params
.
getProperty
(
"http"
)
);
tcpPort
=
Integer
.
parseInt
(
params
.
getProperty
(
"http"
)
);
tcpHost
=
params
.
getProperty
(
"host"
)
;
tcpHost
=
params
.
getProperty
(
"host"
)
;
/*
try {
final ServerSocket ss = new ServerSocket( tcpPort );
Thread t = new Thread( new Runnable() {
public void run() {
try { while( true ) new HTTPSession( ss.accept());
} catch ( IOException ioe ) { logger.debug( "IGNORED Exception", ioe ); }
}
});
t.setDaemon( true );
t.start();
} catch (Exception e) {
throw new AServException ( "Cannot launch HTTP Server" , e );
}
*/
// ********************************************************************
// ********************************************************************
// JE: Jetty implementation
// JE: Jetty implementation
server
=
new
Server
(
tcpPort
);
server
=
new
Server
(
tcpPort
);
...
@@ -114,11 +99,7 @@ public class HTTPTransport {
...
@@ -114,11 +99,7 @@ public class HTTPTransport {
// most of its work is to deal with large content sent in specific ways
// most of its work is to deal with large content sent in specific ways
Handler
handler
=
new
AbstractHandler
(){
Handler
handler
=
new
AbstractHandler
(){
public
void
handle
(
String
String
,
Request
baseRequest
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
,
ServletException
{
public
void
handle
(
String
String
,
Request
baseRequest
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
,
ServletException
{
// This was the required header for Jetty version 6
//public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch ) throws IOException, ServletException {
String
method
=
request
.
getMethod
();
String
method
=
request
.
getMethod
();
//uri = URLDecoder.decode( request.getURI(), "iso-8859-1" );
// Should be decoded?
String
uri
=
request
.
getPathInfo
();
String
uri
=
request
.
getPathInfo
();
Properties
params
=
new
Properties
();
Properties
params
=
new
Properties
();
try
{
decodeParams
(
request
.
getQueryString
(),
params
);
}
try
{
decodeParams
(
request
.
getQueryString
(),
params
);
}
...
@@ -136,23 +117,18 @@ public class HTTPTransport {
...
@@ -136,23 +117,18 @@ public class HTTPTransport {
// Get the content if any
// Get the content if any
// This is supposed to be only an uploaded file
// This is supposed to be only an uploaded file
// We use jetty MultiPartFilter to decode this file.
// Note that this could be made more uniform
// Note that this could be made more uniform
// with the text/xml part stored in a file as well.
// with the text/xml part stored in a file as well.
String
mimetype
=
request
.
getContentType
();
String
mimetype
=
request
.
getContentType
();
// Multi part: the content provided by an upload HTML form
// Multi part: the content provided by an upload HTML form
// This code is also in the MultiPartFilter
if
(
mimetype
!=
null
&&
mimetype
.
startsWith
(
"multipart/form-data"
)
)
{
if
(
mimetype
!=
null
&&
mimetype
.
startsWith
(
"multipart/form-data"
)
)
{
logger
.
info
(
"********************************************************************"
);
try
{
try
{
if
(
!
ServletFileUpload
.
isMultipartContent
(
request
)
)
{
//if ( !ServletFileUpload.isMultipartContent( request ) ) {
logger
.
debug
(
"Does not detect multipart"
);
// logger.debug( "Does not detect multipart" );
}
//}
// Man... fileupload...
DiskFileItemFactory
factory
=
new
DiskFileItemFactory
();
DiskFileItemFactory
factory
=
new
DiskFileItemFactory
();
// File repository = File.createTempFile( "testfileupload", null );
File
tempDir
=
new
File
(
System
.
getProperty
(
"java.io.tmpdir"
)
);
File
repository
=
new
File
(
"/tmp"
);
factory
.
setRepository
(
tempDir
);
factory
.
setRepository
(
repository
);
ServletFileUpload
upload
=
new
ServletFileUpload
(
factory
);
ServletFileUpload
upload
=
new
ServletFileUpload
(
factory
);
List
<
FileItem
>
items
=
upload
.
parseRequest
(
request
);
List
<
FileItem
>
items
=
upload
.
parseRequest
(
request
);
for
(
FileItem
fi
:
items
)
{
for
(
FileItem
fi
:
items
)
{
...
@@ -162,10 +138,9 @@ public class HTTPTransport {
...
@@ -162,10 +138,9 @@ public class HTTPTransport {
}
else
{
}
else
{
logger
.
trace
(
" >> {} : {}"
,
fi
.
getName
(),
fi
.
getSize
()
);
logger
.
trace
(
" >> {} : {}"
,
fi
.
getName
(),
fi
.
getSize
()
);
logger
.
trace
(
" Stored at {}"
,
fi
.
getName
(),
fi
.
getSize
()
);
logger
.
trace
(
" Stored at {}"
,
fi
.
getName
(),
fi
.
getSize
()
);
// This is a temoporary solution
// NOTE: This getName() won't work with internet explorer... create a new file name...
try
{
try
{
File
uploadedFile
=
new
File
(
"/tmp/"
+
fi
.
getName
()
);
// FilenameUtils.getName() needed for Internet Explorer problem
File
uploadedFile
=
new
File
(
tempDir
,
FilenameUtils
.
getName
(
fi
.
getName
()
)
);
fi
.
write
(
uploadedFile
);
fi
.
write
(
uploadedFile
);
params
.
setProperty
(
"filename"
,
uploadedFile
.
toString
()
);
params
.
setProperty
(
"filename"
,
uploadedFile
.
toString
()
);
params
.
setProperty
(
"todiscard"
,
"true"
);
params
.
setProperty
(
"todiscard"
,
"true"
);
...
@@ -182,10 +157,7 @@ public class HTTPTransport {
...
@@ -182,10 +157,7 @@ public class HTTPTransport {
};
};
}
catch
(
FileUploadException
fuex
)
{
}
catch
(
FileUploadException
fuex
)
{
logger
.
trace
(
"Upload Error"
,
fuex
);
logger
.
trace
(
"Upload Error"
,
fuex
);
}
catch
(
NullPointerException
npex
)
{
logger
.
trace
(
"NPE Error"
,
npex
);
}
}
logger
.
info
(
"********************************************************************"
);
}
else
if
(
mimetype
!=
null
&&
mimetype
.
startsWith
(
"text/xml"
)
)
{
}
else
if
(
mimetype
!=
null
&&
mimetype
.
startsWith
(
"text/xml"
)
)
{
// Most likely Web service request (REST through POST)
// Most likely Web service request (REST through POST)
int
length
=
request
.
getContentLength
();
int
length
=
request
.
getContentLength
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment