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

The library doesn't work properly with Tomcat server #51

Open
GalynaY opened this issue Jul 19, 2019 · 3 comments
Open

The library doesn't work properly with Tomcat server #51

GalynaY opened this issue Jul 19, 2019 · 3 comments
Assignees
Labels
Bug Something isn't working customer-reported Relay

Comments

@GalynaY
Copy link

GalynaY commented Jul 19, 2019

HybridConnectionListener throws exceptions when using it on a tomcat:

19-Jul-2019 13:48:07.248 SEVERE [autoshutdown-pool-1-thread-3] com.microsoft.azure.relay.RelayLogger.throwingException ClientWebSocket(TrackingId:de9dd33c-7433-49c0-978d-07e191f35798_G16_G10, Address:sb://statelink-relay.servicebus.windows.net) is throwing an Exception: javax.websocket.DeploymentException: Cannot use POJO class [com.microsoft.azure.relay.ClientWebSocket] as it is not annotated with @ClientEndpoint at org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:124) at com.microsoft.azure.relay.ClientWebSocket.lambda$connectAsync$0(ClientWebSocket.java:121) at com.microsoft.azure.relay.CompletableFutureUtil.lambda$futureToCompletableFuture$1(CompletableFutureUtil.java:62) at com.microsoft.azure.relay.AutoShutdownScheduledExecutor.lambda$submit$0(AutoShutdownScheduledExecutor.java:60) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) 19-Jul-2019 13:48:07.250 SEVERE [autoshutdown-pool-1-thread-3] com.microsoft.azure.relay.RelayLogger.throwingException HybridConnectionListener(TrackingId:92aa61bb-a431-4230-aa5f-a56bf29d0960, Address:sb://statelink-relay.servicebus.windows.net) is throwing an Exception: java.util.concurrent.CompletionException: java.lang.RuntimeException: javax.websocket.DeploymentException: Cannot use POJO class [com.microsoft.azure.relay.ClientWebSocket] as it is not annotated with @ClientEndpoint at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292) at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308) at java.util.concurrent.CompletableFuture.uniRun(CompletableFuture.java:700) at java.util.concurrent.CompletableFuture$UniRun.tryFire(CompletableFuture.java:687) at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474) at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977) at com.microsoft.azure.relay.CompletableFutureUtil.lambda$futureToCompletableFuture$1(CompletableFutureUtil.java:68) at com.microsoft.azure.relay.AutoShutdownScheduledExecutor.lambda$submit$0(AutoShutdownScheduledExecutor.java:60) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.RuntimeException: javax.websocket.DeploymentException: Cannot use POJO class [com.microsoft.azure.relay.ClientWebSocket] as it is not annotated with @ClientEndpoint at com.microsoft.azure.relay.RelayLogger.throwingException(RelayLogger.java:77) at com.microsoft.azure.relay.RelayLogger.throwingException(RelayLogger.java:53) at com.microsoft.azure.relay.ClientWebSocket.lambda$connectAsync$0(ClientWebSocket.java:127) at com.microsoft.azure.relay.CompletableFutureUtil.lambda$futureToCompletableFuture$1(CompletableFutureUtil.java:62) ... 8 more

If I add an annotation, receives other ClassNotFoundException and ClassCastException. I'd like to be able to use this library on any server not only jetty

@bainian12345
Copy link
Contributor

@GalynaY Hi, what dependency or configurations are you running this library with? And would you mind sharing some code that leads to the exceptions that you are seeing?

@GalynaY
Copy link
Author

GalynaY commented Jul 24, 2019

I run your sample built-in web application so I can deploy it on a tomcat:
`
import com.microsoft.azure.relay.HybridConnectionListener;
import com.microsoft.azure.relay.RelayConnectionStringBuilder;
import com.microsoft.azure.relay.TokenProvider;
import org.joda.time.DateTime;

import java.net.URI;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;

public class WebsocketListener {

private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";

public void startListening() throws URISyntaxException {

	String connectionName = System.getenv("connectionName");
	String url = System.getenv("url");
	String key = System.getenv("key");
	String connectionString = String.format("Endpoint=sb://%s/%s;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=%s", url, connectionName, key);
	System.out.println(connectionString);
	RelayConnectionStringBuilder connectionParams = new RelayConnectionStringBuilder(connectionString);

	TokenProvider tokenProvider = TokenProvider.createSharedAccessSignatureTokenProvider(
			connectionParams.getSharedAccessKeyName(), connectionParams.getSharedAccessKey());
	HybridConnectionListener listener = new HybridConnectionListener(new URI(connectionParams.getEndpoint().toString()), tokenProvider);

	listener.openAsync().join();

	while (listener.isOnline()) {

		// If listener closes, then listener.acceptConnectionAsync() will complete with null after closing down
		listener.acceptConnectionAsync().thenAccept(connection -> {
			// connection may be null if the listener is closed before receiving a connection
			if (connection != null) {
				System.out.println("New session connected.");

				while (connection.isOpen()) {
					ByteBuffer bytesReceived = connection.readAsync().join();
					// If the read operation is still pending when connection closes, the read result as null.
					if (bytesReceived.remaining() > 0) {
						String msg = new String(bytesReceived.array(), bytesReceived.arrayOffset(), bytesReceived.remaining());
						String response = "Message received";

						ByteBuffer msgToSend = ByteBuffer.wrap(response.getBytes());

						System.out.println("Received: " + msg);
						System.out.println("Received file at: " + DateTime.now().toString(TIMESTAMP_FORMAT));
						connection.writeAsync(msgToSend);
					}
				}
				System.out.println("Session disconnected.");
			}
		}).join();
	}
}

}`

The simple servlet:

`

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URISyntaxException;

@WebServlet(
name = "test",
urlPatterns = "/test"
)
public class SampleServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	HttpListener listener = new HttpListener();
	try {
		listener.doS();
	} catch (URISyntaxException e) {
		e.printStackTrace();
	}
}

}
`

and pom:
`

4.0.0

<groupId>face</groupId>
<artifactId>face</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-relay</artifactId>
        <version>0.0.2-PREVIEW</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
        <version>1.7.25</version>
    </dependency>
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-websocket</artifactId>
        <version>8.5.43</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-api</artifactId>
        <version>8.5.43</version>
    </dependency>


</dependencies>

<build>
    <finalName>SampleServlet</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>8</source>
                <target>8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webXml>src\main\webapp\WEB-INF\web.xml</webXml>
            </configuration>
        </plugin>
    </plugins>
</build>

`

@jfggdl
Copy link

jfggdl commented Jul 31, 2019

@GalynaY, thanks for creating this issue. We have added this request to our backlog. We will continue working in the root cause of this problem according to priorities.

@jfggdl jfggdl added the Bug Something isn't working label Jan 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working customer-reported Relay
Projects
None yet
Development

No branches or pull requests

4 participants