[ 
https://issues.apache.org/jira/browse/CAMEL-12954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16697310#comment-16697310
 ] 

ASF GitHub Bot commented on CAMEL-12954:
----------------------------------------

rmannibucau commented on a change in pull request #2631: CAMEL-12954 adding 
camel-websocket-jsr356 module
URL: https://github.com/apache/camel/pull/2631#discussion_r235982067
 
 

 ##########
 File path: 
components/camel-websocket-jsr356/src/main/java/org/apache/camel/jsr356/JSR356Producer.java
 ##########
 @@ -0,0 +1,90 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.jsr356;
+
+import static java.util.Optional.ofNullable;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
+import java.util.function.BiConsumer;
+
+import javax.websocket.ClientEndpointConfig;
+import javax.websocket.Session;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultAsyncProducer;
+
+public class JSR356Producer extends DefaultAsyncProducer {
+    private final int sessionCount;
+    private ClientSessions manager;
+    private BiConsumer<Exchange, AsyncCallback> onExchange;
+
+    JSR356Producer(final JSR356Endpoint jsr356Endpoint, final int 
sessionCount) {
+        super(jsr356Endpoint);
+        this.sessionCount = sessionCount;
+    }
+
+    @Override
+    public JSR356Endpoint getEndpoint() {
+        return JSR356Endpoint.class.cast(super.getEndpoint());
+    }
+
+    @Override
+    public boolean process(final Exchange exchange, final AsyncCallback 
callback) {
+        final Session session = 
exchange.getIn().getHeader(JSR356Constants.SESSION, Session.class);
+        if (session != null && 
exchange.getIn().getHeader(JSR356Constants.USE_INCOMING_SESSION, false, 
Boolean.class)) {
+            synchronized (session) {
+                doSend(exchange, session);
+            }
+        } else {
+            onExchange.accept(exchange, callback);
+        }
+        return true;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        final String endpointKey = 
getEndpoint().getEndpointUri().substring("jsr356://".length());
+        if (!endpointKey.contains("://")) { // we act as a client in all cases 
here
+            throw new IllegalArgumentException("You should pass a client uri");
+        }
+        final ClientEndpointConfig.Builder clientConfig = 
ClientEndpointConfig.Builder.create();
+        manager = new ClientSessions(sessionCount, URI.create(endpointKey), 
clientConfig.build(), null);
+        manager.prepare();
+        onExchange = (ex, cb) -> manager.execute(session -> doSend(ex, 
session));
+    }
+
+    private CompletionStage<Object> doSend(final Exchange ex, final Session 
session) {
+        final CompletableFuture<Object> future = new CompletableFuture<>();
 
 Review comment:
   dropped it, originally I thought using it to integrate with AsyncCallback 
but was not needed

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Add a camel-websocket component 100% using only JSR356
> ------------------------------------------------------
>
>                 Key: CAMEL-12954
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12954
>             Project: Camel
>          Issue Type: New Feature
>            Reporter: Romain Manni-Bucau
>            Priority: Major
>             Fix For: Future
>
>
> Goal is to rely on the standard javax specification and not require to setup 
> Atmosphere in containers which now support it



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to