Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vospace-rest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
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
VOSpace INAF
vospace-rest
Commits
023b82fb
Commit
023b82fb
authored
3 years ago
by
Nicola Fulvio Calabria
Browse files
Options
Downloads
Patches
Plain Diff
Refactored protocol logic for https support
parent
c5e4fcb8
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/it/inaf/oats/vospace/UriService.java
+64
-10
64 additions, 10 deletions
src/main/java/it/inaf/oats/vospace/UriService.java
with
64 additions
and
10 deletions
src/main/java/it/inaf/oats/vospace/UriService.java
+
64
−
10
View file @
023b82fb
...
...
@@ -28,6 +28,7 @@ import java.net.MalformedURLException;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
javax.servlet.http.HttpServletRequest
;
...
...
@@ -94,14 +95,15 @@ public class UriService {
JobService
.
JobDirection
jobDirection
=
JobDirection
.
getJobDirectionEnumFromTransfer
(
transfer
);
List
<
String
>
validProtocol
Uri
s
=
new
ArrayList
<>();
List
<
ProtocolType
>
validProtocol
Type
s
=
new
ArrayList
<>();
switch
(
jobDirection
)
{
case
pullFromVoSpace:
validProtocolTypes
.
add
(
ProtocolType
.
HTTPSGET
);
case
pullToVoSpace:
validProtocol
Uri
s
.
add
(
"ivo://ivoa.net/vospace/core#httpget"
);
validProtocol
Type
s
.
add
(
ProtocolType
.
HTTPGET
);
break
;
case
pushToVoSpace:
validProtocol
Uri
s
.
add
(
"ivo://ivoa.net/vospace/core#httpput"
);
validProtocol
Type
s
.
add
(
ProtocolType
.
HTTPPUT
);
break
;
default
:
...
...
@@ -110,15 +112,30 @@ public class UriService {
List
<
Protocol
>
validProtocols
=
transfer
.
getProtocols
().
stream
()
// discard invalid protocols
.
filter
(
protocol
->
validProtocolUris
.
contains
(
protocol
.
getUri
()))
// discard invalid protocols by uri String
.
filter
(
protocol
->
validProtocolTypes
.
stream
().
map
(
pt
->
{
return
pt
.
getUri
();
})
.
collect
(
Collectors
.
toList
())
.
contains
(
protocol
.
getUri
()))
.
map
(
p
->
{
// set endpoints
Protocol
protocol
=
new
Protocol
();
protocol
.
setUri
(
p
.
getUri
());
protocol
.
setEndpoint
(
getEndpoint
(
job
,
transfer
));
return
protocol
;
}).
collect
(
Collectors
.
toList
());
String
endpoint
=
getEndpoint
(
job
,
transfer
);
ProtocolType
pt
=
ProtocolType
.
getProtocolTypeFromURI
(
p
.
getUri
());
if
(
pt
.
isEndpointCompliant
(
endpoint
))
{
Protocol
protocol
=
new
Protocol
();
protocol
.
setUri
(
p
.
getUri
());
protocol
.
setEndpoint
(
endpoint
);
return
protocol
;
}
else
{
return
null
;
}
}).
filter
(
Objects:
:
nonNull
)
.
collect
(
Collectors
.
toList
());
if
(
validProtocols
.
isEmpty
())
{
Protocol
protocol
=
transfer
.
getProtocols
().
get
(
0
);
...
...
@@ -326,4 +343,41 @@ public class UriService {
}
}
}
public
enum
ProtocolType
{
// Please keep the URIs in this enum UNIQUE!
// will add a unit test to check this
HTTPGET
(
"ivo://ivoa.net/vospace/core#httpget"
,
"http"
),
HTTPSGET
(
"ivo://ivoa.net/vospace/core#httpsget"
,
"https"
),
HTTPPUT
(
"ivo://ivoa.net/vospace/core#httpput"
,
"http"
),
HTTPSPUT
(
"ivo://ivoa.net/vospace/core#httpsput"
,
"https"
);
private
final
String
uri
;
private
final
String
protocolString
;
private
ProtocolType
(
String
uri
,
String
protocolString
)
{
this
.
uri
=
uri
;
this
.
protocolString
=
protocolString
;
}
public
String
getUri
()
{
return
this
.
uri
;
}
public
boolean
isEndpointCompliant
(
String
endpoint
)
{
return
endpoint
.
toLowerCase
()
.
startsWith
(
this
.
protocolString
+
"://"
);
}
public
static
ProtocolType
getProtocolTypeFromURI
(
String
uri
)
{
for
(
ProtocolType
pt
:
ProtocolType
.
values
())
{
if
(
pt
.
getUri
().
equals
(
uri
))
{
return
pt
;
}
}
return
null
;
}
}
}
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