[SOLVED] [PUSH] - Intermittent JSON errors

UI Components for JSF
Post Reply
venturus
Posts: 7
Joined: 27 Aug 2013, 13:58

04 Aug 2014, 14:15

Hello,

Since I upgraded my project to Primefaces 5.0.4, Im facing some problems with Push. It just stops working, all I noticed was some expcetions that you can check below.

[Error] SyntaxError: JSON Parse error: Exponent symbols should be followed by an optional '+' or '-' and then by at least one number (jquery.js, line 25)

[Error] [Error] SyntaxError: JSON Parse error: Unable to parse JSON string [Error]

[Error] SyntaxError: JSON Parse error: Unexpected identifier "e4beb579"
parseJSON (jquery.js, line 25)
onMessage (push.js, line 1)
onMessage (push.js, line 1)
av (push.js, line 1)
ac (push.js, line 1)
D (push.js, line 1)
G (push.js, line 1)
(anonymous function) (push.js, line 1)


Note: This is really intermittent, there is not a way to always reproduce it.


My EndPoint:

Code: Select all

@PushEndpoint("/admin/sale/{channel}")
public class SalePushResource {

    @OnMessage(encoders = { JSONEncoder.class })
    public String onMessage(String message) {
        return message;
    }

}
My Socket:

Code: Select all

<p:socket onMessage="onSalesMessage" autoConnect="true"
				channel="/admin/sale/#{salesBean.pushChannel}"
				transport="websocket" fallbackTransport="jsonp" />
My PushBean:

Code: Select all

public class SalePushBean implements Serializable {

    private static final long serialVersionUID = 3217299041897220877L;

    private Map<Integer, Channel> channels = new HashMap<>();

    public void register(Long productId) {
        Channel channel = getChannel(productId);
        if (channel == null) {
            channel = new Channel(UUID.randomUUID().toString());
            channels.put(generateChannelHash(productId), channel);
        } else {
            channel.incNumOfListeners();
        }
    }

    public void unregister(Long productId) {
        Channel channel = getChannel(productId);
        if (channel != null) {
            if (channel.getNumOfListeners() == 1) {
                channels.remove(generateChannelHash(productId));
            } else {
                channel.decNumOfListeners();
            }
        }
    }

    public String getPushChannel(Long productId) {
        String channelName = null;
        Channel channel = channels.get(generateChannelHash(productId));
        if (channel != null) {
            channelName = channel.getName();
        } else {
            register(productId);
            channel = channels.get(generateChannelHash(productId));
            channelName = channel.getName();
        }
        return channelName;
    }

    private Channel getChannel(Long productId) {
        return channels.get(generateChannelHash(productId));
    }

    private void updateSaleFields(Long saleId) {
        String channel = getPushChannel(saleId);
        if (channel != null) {
            EventBus eventBus = EventBusFactory.getDefault().eventBus();
            eventBus.publish("/admin/sale/" + channel, "updateSales();");
        }
    }

    public void updateSaleFields(Long productId, SaleEventType updateEventType) {
        if (updateEventType.equals(SaleEventType.MODIFY)) {
            updateSaleFields(productId);
        } else {
            updateSalesAllChannels();
        }
    }

    private void updateSalesAllChannels() {
        for (Channel channel : channels.values()) {
            EventBus eventBus = EventBusFactory.getDefault().eventBus();
            eventBus.publish("/admin/sale/" + channel.getName(), "updateSales();");
        }
    }

    public int generateChannelHash(Long productId) {
        final int prime = 31;
        int result = 1;
        result = prime * result + productId.hashCode();
        return result;
    }

}
Additional Information:
There are 2 p:socket in the same page.
The Channel identifier is a hashcode.

Best Regards,
Last edited by venturus on 12 Aug 2014, 15:48, edited 1 time in total.
Primefaces 5.1
Extensions 2.0.0
Atmosphere 2.2.3

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

04 Aug 2014, 16:26

looks like it is treated like a IEEE754 floating point number or something... might it be that every moment this error occurs it starts with e...?

venturus
Posts: 7
Joined: 27 Aug 2013, 13:58

12 Aug 2014, 15:47

Problem solved.

Jboss Websocket support was not working properly so it was always using the fallback (jsonp). Some times push was being executed before the fallback gets up, so it was causing that error.


Just changed to:

Code: Select all

<p:socket onMessage="onSalesMessage" autoConnect="true"
            channel="/admin/sale/#{salesBean.pushChannel}"
            transport="sse" fallbackTransport="jsonp" />

Thank you for your attention :mrgreen: ,
Primefaces 5.1
Extensions 2.0.0
Atmosphere 2.2.3

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

12 Aug 2014, 17:19

venturus wrote:There are 2 p:socket in the same page.
do you still have 2 p:socket in one page, and that is working with your solution?
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

venturus
Posts: 7
Joined: 27 Aug 2013, 13:58

12 Aug 2014, 20:35

smithh032772 wrote:
do you still have 2 p:socket in one page, and that is working with your solution?
Yes
Primefaces 5.1
Extensions 2.0.0
Atmosphere 2.2.3

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 33 guests