Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Jetty9 WebSocket Client - SessionFactory.createSession causes java.lang.NullPointerException

PS.
http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.html

Allowing a generate from a UpgradeRequest

String generate()
String getKey()
void setCookiesFrom(CookieStore cookieStore)
void setRequestURI(URI uri)

I guessed this is for 're-use' the instance with another URI or Cookie?

If so, I think this value is not needed to such a  SimpleEchoClient
example, and I also would omit it.

Regards,

Ken

On Thu, Jan 16, 2014 at 6:33 AM, Ken OKABE <kenokabe@xxxxxxxxx> wrote:
> Joakim,
>
> I found the example of files you provided is identical to
> http://www.eclipse.org/jetty/documentation/current/jetty-websocket-client-api.html
> which is handy to overview in a single page, so just for future reference.
>
> Everything seems clear to me except one thing.
> In the simple example, I found
>
> ClientUpgradeRequest request = new ClientUpgradeRequest();
> client.connect(socket, echoUri, request);
>
> and I could not find any information for what exactly the
> ClientUpgradeRequest is.
>
> Referring to
>
> http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/websocket/client/WebSocketClient.html
>
> Future<Session> connect(Object websocket, URI toUri)
> Future<Session> connect(Object websocket, URI toUri,
> ClientUpgradeRequest request)
>
> You can omit ClientUpgradeRequest, and the example does not tweak this value.
>
> Could you give me some pointer for what ClientUpgradeRequest is.
>
> Thanks again.
>
> Ken
>
> On Thu, Jan 16, 2014 at 6:07 AM, Joakim Erdfelt <joakim@xxxxxxxxxxx> wrote:
>> I need to write an update to that article.
>>
>> --
>> Joakim Erdfelt <joakim@xxxxxxxxxxx>
>> webtide.com - intalio.com/jetty
>> Expert advice, services and support from from the Jetty & CometD experts
>> eclipse.org/jetty - cometd.org
>>
>>
>> On Wed, Jan 15, 2014 at 2:05 PM, Ken OKABE <kenokabe@xxxxxxxxx> wrote:
>>>
>>> Hi Joakim Erdfelt,
>>>
>>> Thanks to your advice, I understand.
>>>
>>> Probably, I can get through this issue since every factor seems
>>> well-defined to me by your answer.
>>>
>>> During this research, I've read your article:
>>>
>>> http://webtide.intalio.com/2012/10/jetty-9-updated-websocket-api/
>>>
>>>
>>> Regards,
>>>
>>> Ken
>>>
>>>
>>>
>>> On Thu, Jan 16, 2014 at 5:15 AM, Joakim Erdfelt <joakim@xxxxxxxxxxx>
>>> wrote:
>>> > see a simple example at
>>> >
>>> >
>>> > http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/jetty-websocket/websocket-client/src/test/java/examples?id=jetty-9.1.1.v20140108
>>> >
>>> > There's no need to be mucking about with WebSocketSessionFactory,
>>> > EventDriver, or LogicalConnection.
>>> > Just keep it simple, use the socket you pass in as your communications
>>> > channel.
>>> > The Socket is configured by you to receive messages, and you use the
>>> > session
>>> > (obtained during socket open) to get information about the connection.
>>> > Use the session.getRemote() to send messages.
>>> >
>>> >
>>> > --
>>> > Joakim Erdfelt <joakim@xxxxxxxxxxx>
>>> > webtide.com - intalio.com/jetty
>>> > Expert advice, services and support from from the Jetty & CometD experts
>>> > eclipse.org/jetty - cometd.org
>>> >
>>> >
>>> > On Wed, Jan 15, 2014 at 12:54 PM, Ken OKABE <kenokabe@xxxxxxxxx> wrote:
>>> >>
>>> >> Hi, I'm new to Jerry, and trying to implement WebSocket Client on
>>> >> Jetty9.
>>> >>
>>> >> I saw an example on Jetty8.
>>> >>
>>> >> org.eclipse.jetty.websocket Class WebSocketClient
>>> >>
>>> >>
>>> >>
>>> >> http://archive.eclipse.org/jetty/8.0.0.v20110901/apidocs/org/eclipse/jetty/websocket/WebSocketClient.html
>>> >>
>>> >> to create a new instance of WebSocketClient is :
>>> >> //=====================================================
>>> >>    WebSocketClientFactory factory = new WebSocketClientFactory();
>>> >>    factory.start();
>>> >>
>>> >>    WebSocketClient client = factory.newWebSocketClient();
>>> >>    // Configure the client
>>> >>
>>> >>    WebSocket.Connection connection = client.open(new
>>> >> URI("ws://127.0.0.1:8080/"), new WebSocket.OnTextMessage()
>>> >>    {
>>> >>      public void onOpen(Connection connection)
>>> >>      {
>>> >>        // open notification
>>> >>      }
>>> >>
>>> >>      public void onClose(int closeCode, String message)
>>> >>      {
>>> >>        // close notification
>>> >>      }
>>> >>
>>> >>      public void onMessage(String data)
>>> >>      {
>>> >>        // handle incoming message
>>> >>      }
>>> >>    }).get(5, TimeUnit.SECONDS);
>>> >>
>>> >>    connection.sendMessage("Hello World");
>>> >> //===========================================================
>>> >>
>>> >> However, I've never seen a document for Jetty9 for this.
>>> >>
>>> >> So far, referring to
>>> >>
>>> >>
>>> >> http://download.eclipse.org/jetty/9.1.0.v20131115/apidocs/org/eclipse/jetty/websocket/common/SessionFactory.html#createSession%28java.net.URI,%20org.eclipse.jetty.websocket.common.events.EventDriver,%20org.eclipse.jetty.websocket.common.LogicalConnection%29
>>> >>
>>> >> //----------------------------------------------
>>> >> WebSocketSession createSession(URI requestURI,
>>> >>                              EventDriver websocket,
>>> >>                              LogicalConnection connection)
>>> >> //----------------------------------------------
>>> >>
>>> >>  I've tried
>>> >>
>>> >> //===========================================================
>>> >>          try
>>> >>             {
>>> >>                 WebSocketSession session = factory.createSession(uri,
>>> >> eventDriver, connection);
>>> >>                 RemoteEndpoint ep = session.getRemote();
>>> >>             }
>>> >>          catch (Exception ex)
>>> >>             {
>>> >>                 System.out.println("=ERROR= " + ex);
>>> >>                 //=ERROR= java.lang.NullPointerException
>>> >>             }
>>> >>
>>> >>         private EventDriver eventDriver = new EventDriver()
>>> >>         {
>>> >>             @Override
>>> >>             public WebSocketPolicy getPolicy()
>>> >>             {
>>> >>                 return null;
>>> >>             }
>>> >>
>>> >>             //......................................
>>> >>
>>> >>             @Override
>>> >>             public void incomingFrame(Frame frame)
>>> >>             {
>>> >>
>>> >>             }
>>> >>         };
>>> >>
>>> >>         private LogicalConnection connection = new LogicalConnection()
>>> >>         {
>>> >>             @Override
>>> >>             public void close()
>>> >>             {
>>> >>
>>> >>             }
>>> >>
>>> >>             //...............................
>>> >>
>>> >>
>>> >>             @Override
>>> >>             public void resume()
>>> >>             {
>>> >>
>>> >>             }
>>> >>         };
>>> >> //===========================================================
>>> >>
>>> >> but I've encounter  java.lang.NullPointerException
>>> >>
>>> >> How do we implement Jetty9 WebSocket Client ??
>>> >>
>>> >> Thanks for your advise.
>>> >>
>>> >> Ken
>>> >> _______________________________________________
>>> >> jetty-users mailing list
>>> >> jetty-users@xxxxxxxxxxx
>>> >> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>> >
>>> >
>>> >
>>> > _______________________________________________
>>> > jetty-users mailing list
>>> > jetty-users@xxxxxxxxxxx
>>> > https://dev.eclipse.org/mailman/listinfo/jetty-users
>>> >
>>> _______________________________________________
>>> jetty-users mailing list
>>> jetty-users@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>
>>
>>
>> _______________________________________________
>> jetty-users mailing list
>> jetty-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>


Back to the top