-
Notifications
You must be signed in to change notification settings - Fork 6
Added file download support to EcpWebService, fixed a bug with non-au… #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1f615de
Added file download support to EcpWebService, fixed a bug with non-au…
chrisala ed3c9bb
Merge remote-tracking branch 'origin/dev' into feature/issue3715
chrisala bbd8647
Updated error messages fieldcapture#3715
chrisala 8d5346f
Don't return empty strings as status codes
chrisala 97bdad4
Bumped actions node version to 24 to resolve build warning fieldcaptu…
chrisala 6563c53
Bumped actions node version to 24 to resolve build warning fieldcaptu…
chrisala 7d1c8cc
Bumped actions node version to 24 to resolve build warning fieldcaptu…
chrisala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,6 +95,37 @@ class EcpWebService { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * This method is used when the response is expected to be a stream, e.g. for downloading files. | ||
| * It returns a Map with keys [statusCode: <http status code>, error: <error message if applicable>] | ||
| * The supplied outputStream will be written to with the response from the web service if the call is successful. | ||
| * The caller is responsible for closing the outputStream. | ||
| */ | ||
| Map readToStream(String url, OutputStream outputStream, boolean includeUserId = true, Integer timeout = null) { | ||
| HttpURLConnection conn = null | ||
| Map resp = [:] | ||
| try { | ||
| conn = configureConnection(url, includeUserId, timeout) | ||
| try (InputStream inputStream = conn.inputStream) { | ||
| outputStream << inputStream | ||
| } | ||
| resp = [statusCode: conn.responseCode] | ||
|
|
||
| } catch (SocketTimeoutException e) { | ||
| resp = [error: "Timed out calling web service. URL= ${url}.", statusCode: conn?.responseCode?:""] | ||
| log.error "Timed out calling web service. URL= ${url}.", e | ||
| } catch (SocketException se) { | ||
| resp = [error: "Timed out calling web service. URL= ${url}.", statusCode: conn?.responseCode?:""] | ||
|
|
||
| log.warn "Socket connection closed. ${se.getMessage()} URL= ${url}.", se | ||
| } catch (Exception e) { | ||
| resp = [error: "Timed out calling web service. URL= ${url}.", statusCode: conn?.responseCode?:""] | ||
chrisala marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
chrisala marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| log.error "Failed calling web service. ${e.getClass()} ${e.getMessage()} URL= ${url}.", e | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling disconnect is only recommended if more calls to the server are not anticipated. Almost all requests are to ecodata and we don't want to close the socket here.
Comment on lines
+109
to
+127
|
||
| } | ||
| resp | ||
| } | ||
|
|
||
| Map getString(String url, boolean includeAuth) { | ||
| URLConnection conn = null | ||
| Map resp = [:] | ||
|
|
@@ -104,7 +135,7 @@ class EcpWebService { | |
| resp.statusCode = conn.responseCode | ||
| } catch (SocketTimeoutException e) { | ||
| resp.error = "Timed out calling web service. URL= ${url}." | ||
| resp.statusCode = HttpStatus.CONNECTION_TIMED_OUT | ||
| resp.statusCode = HttpStatus.SC_GATEWAY_TIMEOUT | ||
| log.warn resp.error | ||
| } catch (SocketException se) { | ||
| resp.error = "Socket connection closed. ${se.getMessage()} URL= ${url}." | ||
|
|
@@ -607,9 +638,10 @@ class EcpWebService { | |
| } | ||
|
|
||
| def user = userService.getUser() | ||
| String userId = user.userId | ||
| String userIdHeader = grailsApplication.config.getProperty('app.http.header.userId') | ||
|
|
||
| if (user) { | ||
| String userIdHeader = grailsApplication.config.getProperty('app.http.header.userId') | ||
| String userId = user.userId | ||
| requestBuilder.addHeader(userIdHeader, userId) | ||
| } else { | ||
| log.warn("No user associated with request: ${url}") | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.