Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
JAliEn
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
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
JAliEn
JAliEn
Merge requests
!20
Websocket client
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Websocket client
websocket-client
into
master
Overview
0
Commits
11
Pipelines
0
Changes
4
Open
Andrey Kondratyev
requested to merge
websocket-client
into
master
6 years ago
Overview
0
Commits
11
Pipelines
0
Changes
4
Expand
0
0
Merge request reports
Compare
master
version 5
4d30c65f
6 years ago
version 4
fcd4f9e2
6 years ago
version 3
e7d2ee08
6 years ago
version 2
1e4f128b
6 years ago
version 1
53b1fb04
6 years ago
master (HEAD)
and
latest version
latest version
4d30c65f
11 commits,
1 year ago
version 5
4d30c65f
11 commits,
6 years ago
version 4
fcd4f9e2
7 commits,
6 years ago
version 3
e7d2ee08
6 commits,
6 years ago
version 2
1e4f128b
5 commits,
6 years ago
version 1
53b1fb04
4 commits,
6 years ago
4 files
+
285
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
src/main/java/alien/shell/WebsockBox.java
0 → 100644
+
99
−
0
Options
package
alien.shell
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
java.io.Console
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.security.SecureRandom
;
import
java.security.Security
;
import
org.apache.tomcat.websocket.Constants
;
import
org.apache.tomcat.websocket.WsWebSocketContainer
;
import
org.json.simple.JSONArray
;
import
org.json.simple.JSONObject
;
import
javax.net.ssl.KeyManagerFactory
;
import
javax.net.ssl.SSLContext
;
import
javax.websocket.ClientEndpointConfig
;
import
javax.websocket.ContainerProvider
;
import
javax.websocket.OnMessage
;
import
javax.websocket.Session
;
import
javax.websocket.WebSocketContainer
;
import
alien.config.ConfigUtils
;
import
alien.user.JAKeyStore
;
import
alien.websockets.ClientEndPoint
;
public
class
WebsockBox
{
static
transient
final
Logger
logger
=
ConfigUtils
.
getLogger
(
WebsockBox
.
class
.
getCanonicalName
());
public
boolean
connect
()
{
Session
session
;
try
{
// get factory
final
KeyManagerFactory
kmf
=
KeyManagerFactory
.
getInstance
(
"SunX509"
,
"SunJSSE"
);
logger
.
log
(
Level
.
INFO
,
"Connecting with client cert: "
+
((
java
.
security
.
cert
.
X509Certificate
)
JAKeyStore
.
getKeyStore
().
getCertificateChain
(
"User.cert"
)[
0
]).
getSubjectDN
());
// initialize factory, with clientCert(incl. priv+pub)
kmf
.
init
(
JAKeyStore
.
getKeyStore
(),
JAKeyStore
.
pass
);
java
.
lang
.
System
.
setProperty
(
"jdk.tls.client.protocols"
,
"TLSv1,TLSv1.1,TLSv1.2"
);
final
SSLContext
ssc
=
SSLContext
.
getInstance
(
"TLS"
);
// initialize SSL with certificate and the trusted CA and pub
// certs
ssc
.
init
(
kmf
.
getKeyManagers
(),
JAKeyStore
.
trusts
,
new
SecureRandom
());
ClientEndpointConfig
config
=
ClientEndpointConfig
.
Builder
.
create
().
build
();
config
.
getUserProperties
().
put
(
Constants
.
SSL_CONTEXT_PROPERTY
,
ssc
);
URI
uri
=
URI
.
create
(
"wss://alice-jcentral.cern.ch:8097/websocket/json"
);
WebSocketContainer
container
=
ContainerProvider
.
getWebSocketContainer
();
session
=
container
.
connectToServer
(
ClientEndPoint
.
class
,
config
,
uri
);
///Send command to server
new
Thread
()
{
@Override
public
void
run
()
{
while
(
session
.
isOpen
())
{
SendCommand
(
session
);
}
}
}.
start
();
}
catch
(
final
Throwable
e
)
{
logger
.
log
(
Level
.
SEVERE
,
"Could not initiate SSL connection to the server."
,
e
);
// e.printStackTrace();
System
.
err
.
println
(
"Could not initiate SSL connection to the server."
);
}
return
false
;
}
@OnMessage
public
void
SendCommand
(
Session
session
)
{
String
message
;
Console
c
=
System
.
console
();
message
=
c
.
readLine
();
String
[]
splitcmd
=
message
.
split
(
" "
);
JSONObject
jsoncmd
=
new
JSONObject
();
JSONArray
Arroptions
=
new
JSONArray
();
if
(
splitcmd
[
0
]!=
null
)
{
jsoncmd
.
put
(
"command"
,
splitcmd
[
0
]);}
for
(
int
i
=
1
;
i
<
splitcmd
.
length
;
i
++)
{
if
(
splitcmd
[
i
]!=
null
)
{
Arroptions
.
add
(
splitcmd
[
i
]);}
}
if
(
Arroptions
!=
null
)
{
jsoncmd
.
put
(
"options"
,
Arroptions
);}
String
fullcmd
=
jsoncmd
.
toString
();
try
{
session
.
getBasicRemote
().
sendText
(
fullcmd
);
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
message
=
null
;
c
=
null
;
}
}
Loading