Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VIPSLogic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
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
VIPS
VIPSLogic
Commits
dd96f332
Commit
dd96f332
authored
4 years ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
Added support for receiving 404 and other errors from proxied URL
parent
0d7a91b8
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/main/java/no/nibio/vips/logic/util/CorsProxyServlet.java
+7
-2
7 additions, 2 deletions
src/main/java/no/nibio/vips/logic/util/CorsProxyServlet.java
with
7 additions
and
2 deletions
src/main/java/no/nibio/vips/logic/util/CorsProxyServlet.java
+
7
−
2
View file @
dd96f332
...
@@ -21,6 +21,7 @@ package no.nibio.vips.logic.util;
...
@@ -21,6 +21,7 @@ package no.nibio.vips.logic.util;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.io.PrintWriter
;
import
java.io.PrintWriter
;
import
java.net.HttpURLConnection
;
import
java.net.HttpURLConnection
;
...
@@ -46,9 +47,10 @@ public class CorsProxyServlet extends HttpServlet {
...
@@ -46,9 +47,10 @@ public class CorsProxyServlet extends HttpServlet {
*/
*/
protected
void
processRequest
(
HttpServletRequest
request
,
HttpServletResponse
response
)
protected
void
processRequest
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
throws
ServletException
,
IOException
{
// Analyze request
// Analyze request
// Get the path
// Get the path
String
completePath
=
request
.
getRequestURI
()
+
"?"
+
request
.
getQueryString
();
String
completePath
=
request
.
getRequestURI
()
+
(
request
.
getQueryString
()
!=
null
?
"?"
+
request
.
getQueryString
()
:
""
)
;
String
urlToProxy
=
completePath
.
substring
(
completePath
.
indexOf
(
request
.
getServletPath
())
+
request
.
getServletPath
().
length
()
+
1
);
String
urlToProxy
=
completePath
.
substring
(
completePath
.
indexOf
(
request
.
getServletPath
())
+
request
.
getServletPath
().
length
()
+
1
);
// Sometimes (for what reason??) the http(s):// is being converted to http(s):/ (double to single slash)
// Sometimes (for what reason??) the http(s):// is being converted to http(s):/ (double to single slash)
// We need to ensure double slashes!
// We need to ensure double slashes!
...
@@ -64,7 +66,9 @@ public class CorsProxyServlet extends HttpServlet {
...
@@ -64,7 +66,9 @@ public class CorsProxyServlet extends HttpServlet {
URL
url
=
new
URL
(
urlToProxy
);
URL
url
=
new
URL
(
urlToProxy
);
HttpURLConnection
con
=
(
HttpURLConnection
)
url
.
openConnection
();
HttpURLConnection
con
=
(
HttpURLConnection
)
url
.
openConnection
();
con
.
setRequestMethod
(
"GET"
);
con
.
setRequestMethod
(
"GET"
);
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
con
.
getInputStream
()));
InputStream
theContent
=
con
.
getResponseCode
()
==
200
?
con
.
getInputStream
()
:
con
.
getErrorStream
();
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
theContent
));
String
inputLine
;
String
inputLine
;
String
contents
=
""
;
String
contents
=
""
;
while
((
inputLine
=
in
.
readLine
())
!=
null
)
while
((
inputLine
=
in
.
readLine
())
!=
null
)
...
@@ -77,6 +81,7 @@ public class CorsProxyServlet extends HttpServlet {
...
@@ -77,6 +81,7 @@ public class CorsProxyServlet extends HttpServlet {
try
(
PrintWriter
out
=
response
.
getWriter
())
{
try
(
PrintWriter
out
=
response
.
getWriter
())
{
out
.
println
(
contents
);
out
.
println
(
contents
);
}
}
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
...
...
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