hello;
you need to add following jars to your classpath:
tomcat7-websocket.jar
websocket-api.jar
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"
metadata-complete="true">
<servlet>
<servlet-name>AsteriskSocket</servlet-name>
<servlet-class>org.ofbiz.service.asterisk.websocket.AsteriskSocket</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AsteriskSocket</servlet-name>
<url-pattern>/ws</url-pattern>
</servlet-mapping>
</web-app>
you need to copy the .class AsteriskSocket into your webapp dir, i used
ant jar target to make it.
+ <property name="ws.src"
value="build/classes/org/ofbiz/service/asterisk"/>
+ <property name="ws.dest"
value="webapp/asterisk/WEB-INF/classes/org/ofbiz/service/asterisk"/>
<target name="main-jar" depends="stubs">
<main-jar/>
<test-jar/>
+ <mkdir dir="${ws.dest}"/>
+ <copy todir="${ws.dest}" flatten="true">
+ <fileset dir="${ws.src}" includes="**"/>
+ </copy>
</target>
look at attachement for the websocket server side implementation
hope this will help you.
Le 24/04/2014 13:40, MelonJaya a écrit :
HI Youssef,
I tried the old deprecated API but still cannot make websocket connection
between browser and server(ofbiz embedded tomcat).
Can you explain more how you do it?
another alternative would be deploy ofbiz to (outside)Tomcat, but I am
stuck too.
On Sun, Apr 20, 2014 at 6:37 PM, Youssef Khaye <[email protected]>wrote:
Hi
yes, i hav successfully use websockets to send information to connected
when some event occures server side.
in details, i used asterisk-java, to interact wieth an servisk server, and
used websockets to communicate with client browser, to whox coming calls
for examples.
i used the old apache websocket api, which is deprecated. the new one
still difficle to make working within ofbiz, i faced sale issues as
jaccoppo.
hope this help.
Le 17/04/2014 12:48, MelonJaya a écrit :
Hi all,
I've been trying to utilize the websocket in current trunk of ofbiz.
Make new component in hot-deploy, using the exact chat example from tomcat
and include the Java class. It can be compiled and ant start run without
any problem, but my browser console keeps telling me that ws connection
cannot be made.
I have read the discussion from Jacopo in Tomcat mailing list too, tried
to
add the listener in web.xml and still my browser cannot make ws connection
to my ofbiz instance.
Have you guys any experience on this issue?
Thanks in advance!
Johnson Chandra
/*
* 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.ofbiz.service.asterisk.websocket;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import org.apache.catalina.websocket.MessageInbound;
import org.apache.catalina.websocket.StreamInbound;
import org.apache.catalina.websocket.WebSocketServlet;
import org.apache.catalina.websocket.WsOutbound;
import org.apache.commons.lang3.StringEscapeUtils;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.service.asterisk.AsteriskServiceProvider;
@SuppressWarnings("deprecation")
public class AsteriskSocket extends WebSocketServlet {
public static String module = AsteriskSocket.class.getName();
private static final long serialVersionUID = 1L;
private final AtomicInteger sessionId = new AtomicInteger(0);
@Override
public void init() throws ServletException {
super.init();
asp.setSockets(sessions);
}
@Override
protected StreamInbound createWebSocketInbound(String subProtocol,
HttpServletRequest request) {
return new AsteriskSocketSession(sessionId.incrementAndGet());
}
public final class AsteriskSocketSession extends MessageInbound {
public final int id;
public AsteriskSocketSession(int id) {
super();
this.id = id;
}
public int getId() {
return id;
}
@Override
protected void onBinaryMessage(ByteBuffer message) throws IOException {
}
@Override
protected void onTextMessage(CharBuffer msg) throws IOException {
Debug.logInfo("^^^^^^^^^^^^^^^^^^^^^^^^^message received " + msg.toString(), module);
}
@Override
protected void onOpen(WsOutbound outbound) {
if(Debug.verboseOn()) {
Debug.logInfo("^^^^^^^^^^^^^^^^^^^^^^^^^create session " + this.getId(), module);
}
sessions.add(this);
}
@Override
protected void onClose(int status) {
if(Debug.verboseOn()) {
Debug.logInfo("^^^^^^^^^^^^^^^^^^^^^^^^^destroy sessions " + this.getId(), module);
}
sessions.remove(this);
}
}
}