Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
osug-doi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
OSUG
Pôle Numérique
osug-doi
Commits
42b5fed7
Commit
42b5fed7
authored
6 years ago
by
bourgesl
Browse files
Options
Downloads
Patches
Plain Diff
use HEAD for binary files (dataAccess URL)
parent
150193cc
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/fr/osug/doi/ProcessUrlPipeline.java
+4
-4
4 additions, 4 deletions
src/main/java/fr/osug/doi/ProcessUrlPipeline.java
src/main/java/fr/osug/doi/service/UrlChecker.java
+18
-3
18 additions, 3 deletions
src/main/java/fr/osug/doi/service/UrlChecker.java
with
22 additions
and
7 deletions
src/main/java/fr/osug/doi/ProcessUrlPipeline.java
+
4
−
4
View file @
42b5fed7
...
...
@@ -91,13 +91,13 @@ public final class ProcessUrlPipeline extends AbstractPipeline<PipelineCommonDat
if
(
dataAccessUrl
==
null
)
{
doiData
.
addError
(
"Missing data access url"
);
}
else
{
checkUrl
(
doiData
,
dataAccessUrl
);
checkUrl
(
doiData
,
dataAccessUrl
,
true
);
}
// Get external Landing page URL:
final
String
landingPageExtUrl
=
projectConfig
.
getUrlLandingPage
(
doiSuffix
);
if
(
landingPageExtUrl
!=
null
)
{
checkUrl
(
doiData
,
landingPageExtUrl
);
checkUrl
(
doiData
,
landingPageExtUrl
,
false
);
logger
.
debug
(
"landingPageUrl: {}"
,
landingPageExtUrl
);
}
...
...
@@ -113,12 +113,12 @@ public final class ProcessUrlPipeline extends AbstractPipeline<PipelineCommonDat
logger
.
info
(
"processUrls: done"
);
}
private
void
checkUrl
(
final
PipelineCommonDoiData
doiData
,
final
String
url
)
{
private
void
checkUrl
(
final
PipelineCommonDoiData
doiData
,
final
String
url
,
final
boolean
binary
)
{
logger
.
debug
(
"checkUrl: {}"
,
url
);
Integer
check
=
checkUrlCache
.
get
(
url
);
if
(
check
==
null
)
{
final
String
doc
=
doiConfig
.
getUrlChecker
().
getResource
(
url
);
final
String
doc
=
doiConfig
.
getUrlChecker
().
getResource
(
url
,
binary
);
check
=
checkDocument
(
doc
);
checkUrlCache
.
put
(
url
,
check
);
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/fr/osug/doi/service/UrlChecker.java
+
18
−
3
View file @
42b5fed7
...
...
@@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.web.client.RestClientException
;
/**
...
...
@@ -38,16 +39,30 @@ public class UrlChecker {
200 OK - operation successful
@param url resource to load
@return
@param headOnly true to only retrieve content-type
@return resource as string or Content-Type header if headOnly is true
*/
public
String
getResource
(
final
String
url
)
{
public
String
getResource
(
final
String
url
,
final
boolean
headOnly
)
{
// Note: url must not be encoded (%)
if
(
url
.
contains
(
"%"
))
{
logger
.
info
(
"Url is encoded (may cause problem with HTTP request) : {}"
,
url
);
}
String
response
=
null
;
try
{
response
=
this
.
restTemplate
.
getForObject
(
url
,
String
.
class
);
logger
.
debug
(
"getResource: {}"
,
url
);
if
(
headOnly
)
{
final
HttpHeaders
headers
=
this
.
restTemplate
.
headForHeaders
(
url
);
if
(
headers
!=
null
)
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"headers: {}"
,
headers
.
values
());
}
response
=
headers
.
getContentType
().
toString
();
}
}
else
{
response
=
this
.
restTemplate
.
getForObject
(
url
,
String
.
class
);
}
}
catch
(
RestClientException
rce
)
{
logger
.
error
(
"getResource: failed"
,
rce
);
}
...
...
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