I want to send messages from the Xpert.ivy server to a HTML Dialog, i.e. to JSF pages. PrimePush supports this but is not yet integrated in Xpert.ivy. How can I use it anyways?

asked 07.10.2013 at 12:18

SupportIvyTeam's gravatar image

SupportIvyTeam ♦♦
1.4k102118122
accept rate: 77%

edited 08.10.2013 at 14:34


Answers for Axon.ivy 5.1 (Lauberhorn) with Primefaces 5.0

The usage of PrimePush has changed in many ways since ivy 5.1 as Primefaces has changed its implementation between primefaces 3.5 (ivy 5.0) and primefaces 5.0 (ivy 5.1). The documentation for Primefaces 5.0 with PrimePush is here.

But basically primefaces push still works. There is an updated demo project here: PrimePush_51.iar. It can be set up as follows:

  • Download the atmospehere-runtime jar (and optionally its sources) from a maven repository: atomsphere-runtime.jar. I used the version 2.1.3 that is documented by Primefaces. But I think newer versions should work also.
  • Copy the atmosphere JAR into your designer/webapps/ivy/WEB-INF/lib
  • Adjust the web.xml in designer/webapps/ivy/WEB-INF/web.xml as documented in the first answer

web.xml example:

<servlet>
    <servlet-name>Push Servlet</servlet-name>
    <servlet-class>org.primefaces.push.PushServlet</servlet-class>
    <async-supported>true</async-supported>
    <init-param>
        <param-name>org.atmosphere.useWebSocketAndServlet3</param-name>
        <param-value>true</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>Push Servlet</servlet-name>
    <url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
  • Write an endpoint bean for your channel. For instance a simple echo bean look like this:

endpoint example:

package ch.ivyteam.test;

import org.primefaces.push.annotation.OnMessage;
import org.primefaces.push.annotation.PushEndpoint;
import org.primefaces.push.impl.JSONEncoder;

@PushEndpoint("/mychannel")
public class MessageResource {

    @OnMessage(encoders = { JSONEncoder.class })
    public String onMessage(String message) 
    {
        return message;
    }
}
  • copy the resulting .class file with its parent package folders into designer/webapps/ivy/WEB-INF/classes directory. Or copy the existing from the demo.iar/classes_endpoints
  • Restart your Designer
  • Import the PrimePush_51.iar demo project
  • Run the Hello World example.

If you still run into problem with atomsphere. It can help to get more log outputs form the atmosphere runtime jar. To do so copy the following xml into your designer/configuration/log4jconfig.xml:

<category name="org.atmosphere.cpr.AtmosphereFramework" class="ch.ivyteam.log.Logger">
    <priority value="INFO"/>
</category>
link

answered 21.04.2015 at 09:08

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
9.4k31958
accept rate: 70%

edited 07.03.2018 at 10:35

Alex%20Suter's gravatar image

Alex Suter ♦♦
3.1k122247

Thanks for your solution!

After doing a lot of research on internet and make the same demo in eclipse as well to know about mechanism of primepush and atmosphere. --> Yesterday, I have found out the solution (same your solution) in Ivy Designer. and It works correctly now.

Thanks again!

(22.04.2015 at 06:27) Hap Em Hap%20Em's gravatar image

Thanks for your reply. I guess that the endpoint can also be registered programatically. But i do not have the time at the moment to find out how. But if you inspect the code in the "AtmosphereFramework" class you should get an idea.

(22.04.2015 at 09:26) Reguel Werme... ♦♦ Reguel%20Wermelinger's gravatar image

Yes. The Endpoints have registered programmatically when the server/designer started. By default, It'll find all classes having @PushEndpoint in WEB-INF/classes.

(23.04.2015 at 04:03) Hap Em Hap%20Em's gravatar image

I mean we should look for a more intuitive way where we do not have to copy classes around the designer and server as this is very unflexible, difficult for deployment. And of course the endpoint is always global instead of local for one pmv.

(23.04.2015 at 08:40) Reguel Werme... ♦♦ Reguel%20Wermelinger's gravatar image

Answers for Xpert.ivy 5.0 (Rothorn) with Primefaces 3.5

There are two steps to do. First you have to install the Atmosphere framework on which PrimePush is based on. Second you have to configure PrimePush to use it in Xpert.ivy.

For the first step, Atmosphere unfortunately does not provide binary releases. So, please follow the instructions on the Atmosphere homepage to get the Atmosphere jar files. Then move them into the directory webapps/Ivy/WEB-INF/lib of the Designer/Server.

For the second step, please open the file webapps/Ivy/WEB_INF/web.xml. Within the web-app tag, add the following text:

<servlet>
    <servlet-name>Push Servlet</servlet-name>
    <servlet-class>org.primefaces.push.PushServlet</servlet-class>
    <async-supported>true</async-supported>
    <init-param>
        <param-name>org.atmosphere.useWebSocketAndServlet3</param-name>
        <param-value>true</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>Push Servlet</servlet-name>
    <url-pattern>/primepush/*</url-pattern>
</servlet-mapping>

Re-start the Designer/Server. To check whether it works not, please use the example project from the Xpert.ivy Hacker. Start the process PrimePush Hello World in multiple browsers and type a message in one of the browsers. If everything is correct you should see the message posted to all browser windows.



Note: This question and answer was originally posted by Heinrich Spreiter on his Xpert.ivy Hacker blog. Many thanks to Henry for his enthusiastic work.

link

answered 07.10.2013 at 13:42

SupportIvyTeam's gravatar image

SupportIvyTeam ♦♦
1.4k102118122
accept rate: 77%

edited 22.04.2015 at 09:10

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
9.4k31958

I have just added the init-param 'org.atmosphere.useWebSocketAndServlet3'. This is required that non-IO blocking threads are used for AJP connections! (e.g. when Xpert.ivy is integrated with IIS). Otherwise each connection consumes a thread on the server side. As soon as the MaxThreadCount is reached (default value is 200) no more connection could be created and the server will no longer answer.

(10.04.2014 at 16:58) Flavio Sadeghi ♦♦ Flavio%20Sadeghi's gravatar image

Hello Flavio!

I want to test before and after I apply useWebSocketAndServlet3 into Ivy Engine.

So, Pls give me some information: - Where is MaxThreadCount defined? - How can I test MaxThreadCount is reached? (Do you have a monitor tool to or test tool?

Thanks & Regards,

(26.08.2015 at 06:26) Hap Em Hap%20Em's gravatar image

Hello All,

I have made a demo to use primepush on Ivy 5.1.4 and atmosphere 2.1.6. When I started Ivy --> It showed an error: 13:08:34.123 ERROR [org.primefaces.push.PushServlet] [localhost-startStop-1] [] No Annotated class using @PushEndpoint found. Push will not work.

This is my code:

xhtml page: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" <br=""/> xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui">

<h:head>
    <title>JSF User Dialog</title>
    <script>
        function onMessage(msg) {
            $('.display').html(msg);
        };
        function onError() {
            alert("error");
        };
    </script>
</h:head>
<h:body>
    <h:form>
        <h:outputText id="out" styleClass="ui-widget display" /><br></br>
        <p:inputText required="true" value="#{data.message}" />
        <p:commandButton value="Nachricht senden" actionListener="#{logic.SendMessage}" />
    </h:form>
    <p:socket channel="/chat" onMessage="onMessage" onMessagePublished="onMessage" transport="websocket" widgetVar="pfsocket" autoConnect="true" fallbackTransport="websocket"/>
</h:body>

</html>

In SendMessage event: JSONObject rs = new JSONObject(); rs.put("pfpd", String.valueOf("Nachricht: " + in.message));

EventBusFactory.getDefault().eventBus().publish("/chat", rs);

In web.xml: <servlet> <servlet-name>Push Servlet</servlet-name> <servlet-class>org.primefaces.push.PushServlet</servlet-class> <init-param> <param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name> <param-value>org.atmosphere.cache.UUIDBroadcasterCache</param-value> </init-param> <init-param> <param-name>org.atmosphere.cpr.broadcasterClass</param-name> <param-value>org.atmosphere.cpr.DefaultBroadcaster</param-value> </init-param> <init-param> <param-name>channels</param-name> <param-value>chat</param-value> </init-param> <init-param> <param-name>org.atmosphere.useWebSocketAndServlet3</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>org.atmosphere.cpr.SessionSupport</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> <async-supported>true</async-supported> </servlet> <servlet-mapping> <servlet-name>Push Servlet</servlet-name> <url-pattern>/primepush/*</url-pattern> </servlet-mapping>

When I sent a message to "chat" channels --> It's not working

Pls help me if you have any idea! Thanks in advance! Regards,

link

answered 20.04.2015 at 08:34

Hap%20Em's gravatar image

Hap Em
(suspended)
accept rate: 0%

We need to do one more step to create Endpoint java class. For example: package ch.soreco.primepush.endpoints; import org.primefaces.push.annotation.OnMessage; import org.primefaces.push.annotation.PushEndpoint; import org.primefaces.push.impl.JSONEncoder; @PushEndpoint("/chat") public class ChatResource { @OnMessage(encoders = { JSONEncoder.class }) public String onMessage(String msg) { return msg; } }

  • Compile this java file to class file
  • Copy this class file to {Ivy_Server_Folder}\webapps\ivy\WEB-INF\classes.....\ChatResource.class
(23.04.2015 at 03:48) Hap Em Hap%20Em's gravatar image

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×58
×51

Asked: 07.10.2013 at 12:18

Seen: 22,765 times

Last updated: 07.03.2018 at 10:35