Skip to content
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

Question: How do I get the service name in my tomcat container #15897

Closed
sonntag-dev opened this issue Jan 31, 2020 · 7 comments
Closed

Question: How do I get the service name in my tomcat container #15897

sonntag-dev opened this issue Jan 31, 2020 · 7 comments
Assignees
Labels
kind/question Questions that haven't been identified as being feature requests or bugs.

Comments

@sonntag-dev
Copy link

Hello,

thanks for the great work with eclipse che. We want to use eclipse che to deploy our own workspace. Part of this workspace is a tomcat container, in which we are planning to run our own app.

This app generates different URLs that make the various app components accessible. The app has an init process to set these URLs. So we need the from eclipse che generated tomcat service name (see image below) before we start the init process.

image

Is there a possibility to get this name within the tomcat container?

I would appreciate if you could give me some help. Thank you.

@che-bot che-bot added the status/need-triage An issue that needs to be prioritized by the curator responsible for the triage. See https://github. label Jan 31, 2020
@sleshchenko sleshchenko added the kind/question Questions that haven't been identified as being feature requests or bugs. label Feb 3, 2020
@sleshchenko
Copy link
Member

Unfortunately, there is not really easy way to do it, you can create a feature request, I wonder if we can inject value you need with env var.
While it's not implemented yet, the only way I know - it's requesting Che API, like curl $CHE_API/workspace/$CHE_WORKSPACE_ID?token=CHE_MACHINE_TOKEN
Where you get

{ 
   "links":{ 
      "self":"http://che-che.192.168.99.100.nip.io/api/workspace/workspacek5figooh89z74f8t",
      "ide":"http://che-che.192.168.99.100.nip.io/che/wksp-voiu",
      "environment/statusChannel":"ws://che-che.192.
168.99.100.nip.io/api/websocket",
      "environment/outputChannel":"ws://che-che.192.168.99.100.nip.io/api/websocket"
   },
   "attributes":{ 
      "stackName":"Java Gradle",
      "org.eclipse.che.runtimes_id":"runtimesafkyvt3rk
65nd6ql",
      "infrastructureNamespace":"che",
      "updated":"1580737469057",
      "created":"1580737177090"
   },
   "namespace":"che",
   "temporary":false,
   "id":"workspacek5figooh89z74f8t",
   "status":"RUNNING",
   "runtime":{ 
      "machines":{ 
         "gradle":{ 
            "attributes":{ 
               "memoryLimitBytes":"536870912",
               "memoryRequestBytes":"536870912",
               "component":"gradle",
               "source":"recipe"
            },
            "servers":{ 
               "tomcat":{ 
                  "url":"http://servernyb67a6i-gradle-server-8080.192.168.99.100.nip.io/",
                  "attributes":{ 
                     "port":"8080"
                  },
                  "status":"UNKNOWN"
               }
            },
            "status":"RUNNING"
         },
         ....
}
Devfile I used to get such server info from Che Server
metadata:
  name: wksp-voiu
projects:
  - name: console-java-simple
    source:
      location: 'https://github.com/che-samples/console-java-simple.git'
      type: git
      branch: java1.11
components:
  - id: redhat/java11/latest
    type: chePlugin
  - mountSources: true
    endpoints:
      - name: tomcat
        port: 8080
        attributes:
          public: 'true'
    memoryLimit: 512Mi
    type: dockerimage
    volumes:
      - name: gradle
        containerPath: /home/gradle/.gradle
    alias: gradle
    image: 'quay.io/eclipse/che-java11-gradle:nightly'
    env:
      - value: /home/gradle/.gradle
        name: GRADLE_USER_HOME
      - value: >-
          -XX:MaxRAMPercentage=50 -XX:+UseParallelGC -XX:MinHeapFreeRatio=10
          -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4
          -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true
          -Xms20m -Djava.security.egd=file:/dev/./urandom
        name: JAVA_OPTS
      - value: >-
          -XX:MaxRAMPercentage=50 -XX:+UseParallelGC -XX:MinHeapFreeRatio=10
          -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4
          -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true
          -Xms20m -Djava.security.egd=file:/dev/./urandom
        name: JAVA_TOOL_OPTIONS
      - value: /home/gradle
        name: HOME
apiVersion: 1.0.0
commands:
  - name: gradle build
    actions:
      - workdir: '${CHE_PROJECTS_ROOT}/console-java-simple'
        type: exec
        command: gradle build
        component: gradle
  - name: gradle run
    actions:
      - workdir: '${CHE_PROJECTS_ROOT}/console-java-simple'
        type: exec
        command: gradle run
        component: gradle

@ibuziuk
Copy link
Member

ibuziuk commented Feb 3, 2020

@sleshchenko thanks for detailed info
@sonntag-dev do you think we can close the issue?

@ibuziuk ibuziuk removed the status/need-triage An issue that needs to be prioritized by the curator responsible for the triage. See https://github. label Feb 3, 2020
@svkr2k
Copy link

svkr2k commented Feb 11, 2020

Hi @sleshchenko , thank you for the nice example !
Thank you @tolusha for providing the link to this issue.

I noticed that in your devfile:

  • there is a container of type 'dockerimage', alias name : 'gradle'
  • the above container exposes a 'public' port# 8080 (with endpoint name 'tomcat')
    Question Update DTD for GWT-module descriptors #1:
    I believe the above steps are required to make the endpoint of a container (which is part of the workspace) public. Is this correct?

from the response to curl $CHE_API/workspace/$CHE_WORKSPACE_ID?token=CHE_MACHINE_TOKEN, i noticed the URL:

"url":"http://servernyb67a6i-gradle-server-8080.192.168.99.100.nip.io/" and
"port":"8080"

So, if any other external web application (not part of che) running somewhere else in the cloud needs to access the above container's api, can it use the following url ?
http://servernyb67a6i-gradle-server-8080.192.168.99.100.nip.io:8080

Should the external web application need to provide access token in order to access this api? Should there be any other information that needs to be part of the http/https request from the external web application?

for example, in case the above container supports rest api, can the request from external web app be as follows ?
http://servernyb67a6i-gradle-server-8080.192.168.99.100.nip.io:8080/api/v1/myShop/getProducts that returns a JSON object?

Please advise.

@metlos
Copy link
Contributor

metlos commented Feb 11, 2020

So, if any other external web application (not part of che) running somewhere else in the cloud needs to access the above container's api, can it use the following url ?
http://servernyb67a6i-gradle-server-8080.192.168.99.100.nip.io:8080

Should the external web application need to provide access token in order to access this api? Should there be any other information that needs to be part of the http/https request from the external web application?

for example, in case the above container supports rest api, can the request from external web app be as follows ?
http://servernyb67a6i-gradle-server-8080.192.168.99.100.nip.io:8080/api/v1/myShop/getProducts that returns a JSON object?

Please advise.

I believe those questions are answered in the documentation where you can read about it in much more detail than we can afford to provide here in the comments. Please consult https://www.eclipse.org/che/docs/che-7/making-a-workspace-portable-using-a-devfile/

@svkr2k
Copy link

svkr2k commented Feb 12, 2020

Thank you all ! I was able to get the public url as https://... (when i set protocol: 'http' for the endpoint) and open it in a browser and it worked.

However, when I try to use the endpoint protocol type as websocket (protocol: 'ws' & secure: 'false'), I get an url like this:

"servers": {
          "helloworld": {
            "url": "wss://server2q809nz0-dedicated-container-server-6000.mydomain.com/",
            "attributes": {
              "secure": "false",
              "port": "6000"
            },
            "status": "UNKNOWN"
          }
        }
Here is the java websocket client

	WebSocketClient simpleWebSocketClient =
	    new StandardWebSocketClient();
	List<Transport> transports = new ArrayList<>(1);
	transports.add(new WebSocketTransport(simpleWebSocketClient));

	SockJsClient sockJsClient = new SockJsClient(transports);
	WebSocketStompClient stompClient =
	    new WebSocketStompClient(sockJsClient);
	stompClient.setMessageConverter(new MappingJackson2MessageConverter());

	String url = "wss://server2q809nz0-dedicated-container-server-6000.mydomain.com/chat/";
	String userId = "spring-" + ThreadLocalRandom.current().nextInt(1, 99);
	StompSessionHandler sessionHandler = new MyStompSessionHandler(userId);
	
	final WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
	headers.add("Authorization", "Bearer <<machine token here>>");
	
	StompSession session = stompClient.connect(url, headers, sessionHandler).get();

I get an exception in the call stompClient.connect().

Exception Log:

00:25:00.891 [main] DEBUG org.springframework.web.socket.sockjs.client.RestTemplateXhrTransport - Executing SockJS Info request, url=https://server2q809nz0-dedicated-container-server-6000.mydomain.com/chat/info
00:25:04.590 [main] DEBUG org.springframework.web.client.RestTemplate - Created GET request for "https://server2q809nz0-dedicated-container-server-6000.mydomain.com/chat/info"
00:25:08.534 [main] DEBUG org.springframework.web.client.RestTemplate - GET request for "https://server2q809nz0-dedicated-container-server-6000.mydomain.com/chat/info" resulted in 200 (null)
00:25:08.563 [main] DEBUG org.springframework.web.socket.sockjs.client.WebSocketTransport - Starting WebSocket session url=wss://server2q809nz0-dedicated-container-server-6000.mydomain.com/chat/921/0fc9bec2e7b34b798d7b7492f0477120/websocket
00:25:08.563 [main] DEBUG org.springframework.web.socket.client.standard.StandardWebSocketClient - Connecting to wss://server2q809nz0-dedicated-container-server-6000.mydomain.com/chat/921/0fc9bec2e7b34b798d7b7492f0477120/websocket
00:25:09.233 [SimpleAsyncTaskExecutor-1] ERROR org.springframework.web.socket.sockjs.client.DefaultTransportRequest - No more fallback transports after TransportRequest[url=wss://server2q809nz0-dedicated-container-server-6000.mydomain.com/chat/921/0fc9bec2e7b34b798d7b7492f0477120/websocket]
javax.websocket.DeploymentException: The HTTP request to initiate the WebSocket connection failed
	at org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:392)
	at org.springframework.web.socket.client.standard.StandardWebSocketClient$1.call(StandardWebSocketClient.java:150)
	at org.springframework.web.socket.client.standard.StandardWebSocketClient$1.call(StandardWebSocketClient.java:147)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.util.concurrent.ExecutionException: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
	at org.apache.tomcat.websocket.AsyncChannelWrapperSecure$WrapperFuture.get(AsyncChannelWrapperSecure.java:510)
	at org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:336)
	... 4 common frames omitted
Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
	at sun.security.ssl.Handshaker.checkThrown(Handshaker.java:1521)
	at sun.security.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:528)
	at sun.security.ssl.SSLEngineImpl.writeAppRecord(SSLEngineImpl.java:1197)
	at sun.security.ssl.SSLEngineImpl.wrap(SSLEngineImpl.java:1165)
	at javax.net.ssl.SSLEngine.wrap(SSLEngine.java:469)
	at org.apache.tomcat.websocket.AsyncChannelWrapperSecure$WebSocketSslHandshakeThread.run(AsyncChannelWrapperSecure.java:371)
Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
	at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
	at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1709)
	at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:318)
	at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:310)
	at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1639)
	at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:223)
	at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1037)
	at sun.security.ssl.Handshaker$1.run(Handshaker.java:970)
	at sun.security.ssl.Handshaker$1.run(Handshaker.java:967)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.security.ssl.Handshaker$DelegatedTask.run(Handshaker.java:1459)
	at org.apache.tomcat.websocket.AsyncChannelWrapperSecure$WebSocketSslHandshakeThread.run(AsyncChannelWrapperSecure.java:397)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:450)
	at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:317)
	at sun.security.validator.Validator.validate(Validator.java:262)
	at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:330)
	at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:289)
	at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:144)
	at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1626)
	... 7 common frames omitted
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
	at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
	at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
	at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:445)
	... 13 common frames omitted
00:25:09.234 [SimpleAsyncTaskExecutor-1] DEBUG org.springframework.messaging.simp.stomp.DefaultStompSession - Failed to connect session id=dc74d342-7db9-166c-faa5-7d24561dd0d5
javax.websocket.DeploymentException: The HTTP request to initiate the WebSocket connection failed
	at org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:392)
	at org.springframework.web.socket.client.standard.StandardWebSocketClient$1.call(StandardWebSocketClient.java:150)
	at org.springframework.web.socket.client.standard.StandardWebSocketClient$1.call(StandardWebSocketClient.java:147)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.util.concurrent.ExecutionException: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
	at org.apache.tomcat.websocket.AsyncChannelWrapperSecure$WrapperFuture.get(AsyncChannelWrapperSecure.java:510)
	at org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:336)
	... 4 common frames omitted
Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
	at sun.security.ssl.Handshaker.checkThrown(Handshaker.java:1521)
	at sun.security.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:528)
	at sun.security.ssl.SSLEngineImpl.writeAppRecord(SSLEngineImpl.java:1197)
	at sun.security.ssl.SSLEngineImpl.wrap(SSLEngineImpl.java:1165)
	at javax.net.ssl.SSLEngine.wrap(SSLEngine.java:469)
	at org.apache.tomcat.websocket.AsyncChannelWrapperSecure$WebSocketSslHandshakeThread.run(AsyncChannelWrapperSecure.java:371)
Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
	at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
	at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1709)
	at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:318)
	at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:310)
	at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1639)
	at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:223)
	at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1037)
	at sun.security.ssl.Handshaker$1.run(Handshaker.java:970)
	at sun.security.ssl.Handshaker$1.run(Handshaker.java:967)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.security.ssl.Handshaker$DelegatedTask.run(Handshaker.java:1459)
	at org.apache.tomcat.websocket.AsyncChannelWrapperSecure$WebSocketSslHandshakeThread.run(AsyncChannelWrapperSecure.java:397)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:450)
	at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:317)
	at sun.security.validator.Validator.validate(Validator.java:262)
	at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:330)
	at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:289)
	at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:144)
	at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1626)
	... 7 common frames omitted
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
	at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
	at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
	at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:445)
	... 13 common frames omitted

@svkr2k
Copy link

svkr2k commented Feb 13, 2020

Created new thread here for websocket communication : #16014

@sonntag-dev
Copy link
Author

Hi @sleshchenko. Thank you for your answer. I created a feature request #16096 for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Questions that haven't been identified as being feature requests or bugs.
Projects
None yet
Development

No branches or pull requests

6 participants