<< Back to previous view

[GLASSFISH-20909] Error (NPE) with WebSockets (GF4 in NB7.4) using Decoder for JSON object - removing decoder allows onMessage to Work Created: 27/Nov/13  Updated: 10/Dec/13  Resolved: 09/Dec/13

Status: Resolved
Project: glassfish
Component/s: web_socket
Affects Version/s: 4.0_b89_RC5
Fix Version/s: None

Type: Bug Priority: Major
Reporter: HecklerMark Assignee: Pavel Bucek
Resolution: Invalid Votes: 0
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7, NB 7.4, GF 4.0b89.


Tags: glassfish4 websockets endpoint decod
Participants: HecklerMark and Pavel Bucek

 Description   

Ran into issue in normal project, so I created a "toy project" to isolate issue...but seeing the same results.

Created simple WebSockets app with @ServerEndpoint annotated class, Person (lastName, firstName), PersonEncoder, & PersonDecoder. App works fine without encoder/decoder designated in endpoint, but adding encoders= and decoders= to the @ServerEndpoint annotation causes an error on receipt of message:

SEVERE: java.lang.NullPointerException
at org.glassfish.tyrus.core.EndpointWrapper.findApplicableDecoders(EndpointWrapper.java:313)
at org.glassfish.tyrus.core.EndpointWrapper.onMessage(EndpointWrapper.java:495)
at org.glassfish.tyrus.server.TyrusEndpoint.onMessage(TyrusEndpoint.java:174)
at org.glassfish.tyrus.websockets.DefaultWebSocket.onMessage(DefaultWebSocket.java:156)
at org.glassfish.tyrus.websockets.frametypes.TextFrameType.respond(TextFrameType.java:66)
at org.glassfish.tyrus.websockets.DataFrame.respond(DataFrame.java:102)
at org.glassfish.tyrus.servlet.TyrusHttpUpgradeHandler.onDataAvailable(TyrusHttpUpgradeHandler.java:113)
at org.apache.catalina.connector.InputBuffer$ReadHandlerImpl.processDataAvailable(InputBuffer.java:488)
at org.apache.catalina.connector.InputBuffer$ReadHandlerImpl.onDataAvailable(InputBuffer.java:453)
at org.glassfish.grizzly.http.io.InputBuffer.append(InputBuffer.java:855)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:222)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:744)

I'm hoping this is something simple I'm overlooking, but if so, I'm consistently overlooking it.

Happy to upload the simple test project I created if it will help. To duplicate, I just let NB create a new webapp, added a Websocket Endpoint, & the Person and enc/decoder classes, filling in annotations & interfaces as simply as I could for testing. Please do email me for files and/or clarification, happy to fill in any details I may have inadvertently left out.



 Comments   
Comment by Pavel Bucek [ 27/Nov/13 08:00 PM ]

Hi,

can you please try with latest glassfish nightly build? Also test case would be nice (feel free to paste your endpoint and decoder here, I can do the rest).

Thanks!

Comment by Pavel Bucek [ 04/Dec/13 08:34 AM ]

ping

Comment by HecklerMark [ 04/Dec/13 08:05 PM ]

Hi Pavel,

Somehow I missed your replies, so sorry! I've looked for the nightly build, but apparently I'm looking in the wrong place, as the links I can locate only take it up to June 2013. Could you provide a link to more recent builds? Thanks!

Mark

P.S. - I'll post code shortly for you to verify with your configuration. Again, thanks!

Comment by HecklerMark [ 04/Dec/13 08:15 PM ]

I created a simple case to isolate the issue, yet it (still) doesn't seem happy - on my system, at least.

File 1 (PersonEndpoint.java):

package org.websocks;

import java.io.IOException;
import javax.websocket.EncodeException;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import org.person.Person;

/**
 *
 * @author mheckler
 */
@ServerEndpoint(value="/endpoint", encoders={PersonEncoder.class}, decoders={PersonDecoder.class})
public class PersonEndpoint {

    @OnMessage
    public void onMessage(Person message, Session session) throws IOException, EncodeException {
        System.out.println("Received message: " + message.toString());
        
        // Echo the received message back to the client
        Person response = new Person();
        response.setLastName(message.getLastName());
        response.setFirstName(message.getFirstName());
        session.getBasicRemote().sendObject(response);
    }
    
    @OnClose
    public void onClose(Session session) {
        System.out.println("Closing websocket: " + session.getId());
    }

    @OnOpen
    public void onOpen(Session session) {
        System.out.println("Opening websocket: " + session.getId());
    }

    @OnError
    public void onError(Session session, Throwable t) {
        t.printStackTrace();
    }
    
}

File 2 (PersonDecoder.java):

package org.websocks;

import java.io.StringReader;
import javax.json.Json;
import javax.json.JsonObject;
import javax.websocket.DecodeException;
import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;
import org.person.Person;

/**
 *
 * @author mheckler
 */
class PersonDecoder implements Decoder.Text<Person> {

    @Override
    public Person decode(String jsonMessage) throws DecodeException {
        System.out.println("PersonDecoder decode() method called.");
        JsonObject jsonObject = Json
            .createReader(new StringReader(jsonMessage)).readObject();
        Person person = new Person();
        person.setLastName(jsonObject.getString("lastName"));
        person.setFirstName(jsonObject.getString("firstName"));

        return person;
    }

    @Override
    public boolean willDecode(String jsonMessage) {
        System.out.println("PersonDecoder willDecode() method called.");
        try {
            // Check if incoming message is valid JSON
            Json.createReader(new StringReader(jsonMessage)).readObject();
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public void init(EndpointConfig config) {
        System.out.println("PersonDecoder init() method called.");
    }

    @Override
    public void destroy() {
        System.out.println("PersonDecoder destroy() method called.");
    }
    
}
Comment by Pavel Bucek [ 04/Dec/13 08:51 PM ]

link to GF nightlies:

http://dlc.sun.com.edgesuite.net/glassfish/4.0.1/nightly/

(Thanks for the code, I will try to reproduce it tomorrow).

Comment by HecklerMark [ 06/Dec/13 06:52 PM ]

Hi Pavel,

I downloaded & ran the latest nightly build (Dec 5) and get the same results.

Please let me know what you find out from your end or if you need anything else from me to pinpoint further. Thanks so much!

Mark

Comment by Pavel Bucek [ 08/Dec/13 05:52 PM ]

can you post updated stack trace? I'm pretty sure that it is different from the original one.

Comment by Pavel Bucek [ 08/Dec/13 10:39 PM ]

just noticed - your decoder class (PersonDecoder) is not public? That definitely won't work..

Comment by Pavel Bucek [ 09/Dec/13 01:46 PM ]

I compared line numbers against Tyrus 1.0 tag and seems like my last comment is true. Your decoder is not public, so the instance cannot be created. Last version of Tyrus also prints out the exception which caused this (was fixed as part of different issue some time ago).

closing as invalid.

Comment by HecklerMark [ 09/Dec/13 05:19 PM ]

What the...???

I'm not sure when that happened, but - sorry about that.

Still seeing some oddness, but will isolate it and see where it leads. Thanks, Pavel.

Mark

Comment by Pavel Bucek [ 09/Dec/13 05:24 PM ]

no need to apologise The error message was far from being usable so it is/was a bug in some form.

Feel free to file another issue when you are done with your evaluation. You can use Tyrus issue tracker directly - it will be more visible for me that way. https://java.net/jira/browse/TYRUS

Comment by HecklerMark [ 10/Dec/13 05:23 PM ]

Thanks, Pavel (sheepish grin)...

I was also the "lucky recipient" of some malformed JSON coming in. Once we cleaned that up, everything seems to be operating as expected!

Thanks again for your help,
Mark





[GLASSFISH-18963] Create a Design for the GlassFish Community T-shirt Created: 30/Jul/12  Updated: 26/Nov/12  Due: 20/Aug/12  Resolved: 26/Nov/12

Status: Resolved
Project: glassfish
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major
Reporter: arungupta Assignee: arungupta
Resolution: Fixed Votes: 1
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

File Attachments: PNG File All-JavaEE.png     PNG File Fast-like-a-fish.png     PDF File How Can GlassFish.org Serve You.pdf     PNG File How Can GlassFish.org Serve You.png     PNG File I-Love-Fish.png     PNG File I-Love.png     PNG File I_caught_it!.png     PNG File No-Need-to-add-water.png     PNG File Not-just-words.png     PNG File skyline.png     PNG File The-shark-of-JEE.png     PNG File This-City_is_what_it_is.png     PDF File Work Is Never Done.pdf     PNG File Work Is Never Done.png    
Tags:
Participants: ags, ainu, alexandrahuff, angelarenahouston, arungupta, edlorga, emailnbw, HecklerMark, jareado, jclingan, Melissa_Nicole, Mitesh Meswani, myfear, pbakker, pramajaya, Rajiv Mordani and shreedhar_ganapathy

 Comments   
Comment by myfear [ 02/Aug/12 10:13 AM ]

Let me be the first one to break the silence
Feedback welcome!

Comment by myfear [ 02/Aug/12 10:13 AM ]

And one more.

Comment by edlorga [ 03/Aug/12 07:10 PM ]

This is my proposal. I caught it!

Comment by angelarenahouston [ 10/Aug/12 04:37 AM ]

Hi everyone, I have submitted the "How can GlassFish.org serve you?" slogan.

Comment by angelarenahouston [ 11/Aug/12 10:38 PM ]

Hi Arun Gupta,

Have I properly submitted my contest entry and how do we vote?

1.) I emailed my "Oracle Contributor Agreement" to oracle-ca_us@oracle.com.

2.) I attached my image and document file to GLASSFISH-18963.

Sincerely,

Angela Rena Houston

Comment by arungupta [ 13/Aug/12 05:53 PM ]

Angela,

Thanks for your contributions!

Your OCA was somewhat unclear and David is following up with you for the same.

Thanks,
Arun

Comment by angelarenahouston [ 13/Aug/12 09:16 PM ]

Hi Arun,

Thank you for your response. I have since replied to David implying that I will email the signed OCA before August 20, 2012.

Sincerely,

Angela Rena Houston

Comment by angelarenahouston [ 14/Aug/12 07:29 AM ]

Hi everyone, I have submitted the "Work is never done!" slogan.

Comment by angelarenahouston [ 15/Aug/12 11:42 PM ]

Hi Arun and David,

I was able to fax the Oracle Contribution Agreement to the (650) Headquarters number this afternoon. Arun, I apologize for my cellular phone battery dying during our conversation.

Sincerely,

Angela Rena Houston

Comment by myfear [ 16/Aug/12 04:32 AM ]

This one is for you Arun
The GF-City Shirt.

Comment by myfear [ 16/Aug/12 08:00 AM ]

One last thing called "Skyline". This is the CodeCity rendering of the 3.1.2-b15 in a skyline-like view.

Comment by arungupta [ 22/Aug/12 10:47 PM ]

The submissions are now closed. For all the design submitters, please make sure you've submitted OCA to oracle-ca_us@oracle.com.

Everybody,

Please list your top 3 choices as:

Choice 1: <Image Number>
Choice 2: <Image Number>
Choice 3: <Image Number>

Comment by HecklerMark [ 23/Aug/12 02:19 PM ]

Hi Arun,

Is voting public, here in the comments?

Thanks,
Mark

Comment by pramajaya [ 24/Aug/12 02:00 AM ]

Hi Arun,

My choices are:
1. 7 (No Need to add water) But the picture is wrong, it should be "No Need" not "No Ned".
2. 9 (Skyline) But, can we change the color? GlassFish Logo is Grey/Blue themed. It's not supposed to be a red-themed. Just an advice, though..
3. 4 (I Love GlassFish)

Thanks,

Yosi Pramajaya
(Hope you'll like my page on http://www.facebook.com/pramajaya.dev)

Comment by angelarenahouston [ 24/Aug/12 02:49 AM ]

Top 3 choices:

Choice 1: <1>
Choice 2: <3>
Choice 3: <8>

Comment by pbakker [ 26/Aug/12 10:53 AM ]

Choice 1: <5> (I love my GF)

Comment by emailnbw [ 26/Aug/12 03:36 PM ]

My top 3:

1. #6
2. #9
3. #4

Comment by edlorga [ 27/Aug/12 06:51 AM ]

My choices are:

Choice 1: <6>
Choice 2: <10>
Choice 3: <12>

Comment by jareado [ 27/Aug/12 11:21 AM ]

Hi,

Choice 1: 6
Choice 2: 11
Choice 3: 2

Comment by ainu [ 27/Aug/12 01:07 PM ]

My choices are:

Choice 1: <6>
Choice 2: <3>
Choice 3: <8>

Greetings to all!!

Comment by HecklerMark [ 28/Aug/12 08:29 PM ]

Choice 1: 6
Choice 2: 7
Choice 3: 11

Comment by Melissa_Nicole [ 30/Aug/12 06:08 PM ]

Choice 1: 5
Choice 2: 4

Comment by myfear [ 31/Aug/12 04:02 AM ]

Choice 1: 9
Choice 2: 5

Comment by ags [ 01/Sep/12 03:14 PM ]

Choice 1: 9
Choice 2: 6
Choice 3: 7

Comment by alexandrahuff [ 04/Sep/12 10:11 PM ]

choice 1: 5
choice 2: 9
choice 3: 6

Comment by Rajiv Mordani [ 04/Sep/12 10:27 PM ]

Choice 1: #9
Choice 2: #4
Choice 3: #6

Comment by shreedhar_ganapathy [ 04/Sep/12 10:28 PM ]

Choice 1: 9 (but with diff color than red)
Choice 2: 4
Choice 3: 7

Comment by Mitesh Meswani [ 04/Sep/12 10:30 PM ]

Choice 1: #9 (please choose a different background color)
Choice 2: #11
Chouce 3: #4

Comment by jclingan [ 04/Sep/12 10:55 PM ]

Choice 1: #4
Choice 2: #9

Comment by arungupta [ 05/Sep/12 12:35 AM ]

Choice 1: #9 (lighter background color)
Choice 2: #4
Choice 3: #6

Comment by arungupta [ 05/Sep/12 12:42 AM ]

Thank you everybody for the wonderful submissions and your votes! The voting is now closed.

The voting tally shows 6 votes for #9 and 5 votes for #6. The competition is really close but the tally declares #9 (skyline.png) as the winner. I'll work with the submitter to get a EPS Vector image of the file and submit for printing.

Comment by arungupta [ 26/Nov/12 05:47 PM ]

Design successfully chosen.





Generated at Wed Apr 23 12:13:55 UTC 2014 using JIRA 4.0.2#472.