You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Neil Martin <ns...@gmail.com> on 2013/10/26 17:34:20 UTC
Tomcat 8 Websockets configuration
Hi,
I've just started looking at the javax.websocket implementation in tomcat 8 and I have a question about how one integrates an endpoint with application code. Using servlets as an analogy, web.xml allows configuration information to be passed to servlets when they are initialized. Is there an equivalent in the javax.websocket world? If not, are there any suggested practices for achieving this?
Neil
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat 8 Websockets configuration
Posted by Niki Dokovski <ni...@gmail.com>.
On сб, окт. 26, 2013 at 18:35, Neil Martin <nsmnsm@gmail.com="mailto:nsmnsm@gmail.com">> wrote:
Hi,
I've just started looking at the javax.websocket implementation in tomcat 8 and I have a question about how one integrates an endpoint with application code. Using servlets as an analogy, web.xml allows configuration information to be passed to servlets when they are initialized. Is there an equivalent in the javax.websocket world? If not, are there any suggested practices for achieving this?
One source of introduction material is Java EE 7 tutorial http://docs.oracle.com/javaee/7/tutorial/doc/websocket.htm
Neil
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat 8 Websockets configuration
Posted by Johan Compagner <jc...@servoy.com>.
On 27 October 2013 16:09, Niki Dokovski <ni...@gmail.com> wrote:
> On Sun, Oct 27, 2013 at 4:46 PM, Neil Martin <ns...@gmail.com> wrote:
>
> > Thanks for the replies Mark.
> >
> > It does seem to me that most developers using websockets under tomcat are
> > going to want that integration with the J2EE container. Maybe I'm wrong,
> > but it seems like the plumbing to make the servlet context available to
> the
> > EndpoingConfig will be messy because the websockets framework has been
> > designed to be divorced from its environment.
> >
> > From this perspective, the tomcat 7 websockets implementation seems
> easier
> > to work with; at least for developers who are looking to use websocket
> > endpoints as a replacement for servlets. Does this make sense?
> >
>
> Perhaps, such request can be posted on EG mail list [1] or JIRA issue
> tracker [2]
>
> [1] jsr356-experts@websocket-spec.java.net
> [2] http://java.net/jira/browse/WEBSOCKET_SPEC
I guess what would be nice is that an end point just needs to implement 1
interface "IContextAware" that has one method:
"setServletContext(ServletContext)"
that is then called by the container at the moment the endpoint does
implement that interface..
Now i guess the only way to get it through the http session that is gotten
through the ServerEndpoint:
http://stackoverflow.com/questions/17936440/accessing-httpsession-from-httpservletrequest-in-a-web-socket-socketendpoint
But is there always directly a HttpSession? Because if that is not the case
(i only hit the server with the ws:// url) then i can't get to the context
at all.
johan
Re: Tomcat 8 Websockets configuration
Posted by Niki Dokovski <ni...@gmail.com>.
On Sun, Oct 27, 2013 at 4:46 PM, Neil Martin <ns...@gmail.com> wrote:
> Thanks for the replies Mark.
>
> It does seem to me that most developers using websockets under tomcat are
> going to want that integration with the J2EE container. Maybe I'm wrong,
> but it seems like the plumbing to make the servlet context available to the
> EndpoingConfig will be messy because the websockets framework has been
> designed to be divorced from its environment.
>
> From this perspective, the tomcat 7 websockets implementation seems easier
> to work with; at least for developers who are looking to use websocket
> endpoints as a replacement for servlets. Does this make sense?
>
Perhaps, such request can be posted on EG mail list [1] or JIRA issue
tracker [2]
[1] jsr356-experts@websocket-spec.java.net
[2] http://java.net/jira/browse/WEBSOCKET_SPEC
>
> Neil
>
> Sent from my iPad
>
> > On Oct 27, 2013, at 8:04, Mark Thomas <ma...@apache.org> wrote:
> >
> > On 27/10/2013 12:36, Johan Compagner wrote:
> >>>> and i have a follow up question about this, with a servlet or a filter
> >>> you
> >>>> can do: getServletContext() then you have access to the resources of
> the
> >>>> web application and stuff like that
> >>>> How is that possible in an websocket endpoint?
> >>>
> >>> The ServerEndpointConfig will have the modifyHandshake() method called
> >>> where you have access to elements of the request and response. You need
> >>> to copy any data you need at this point.
> >>
> >> i was not talking about (http)request or response objects.
> >> But purely the ServletContext to access stuff of the web app itself.
> >
> > You'd have to put the ServletContext into the EndpointConfig.
> >
> >>>> If i want to load in a file that is in the current webapps WEB-INF dir
> >>> how
> >>>> do i do that? How do i get an url or inputstream (getResource() call)
> to
> >>>> that file?
> >>>
> >>> Calls via the class loader will continue to work.
> >> It's not a resource in the WEB-INF/classes or a resource in a jar file
> >> I am talking about a normal resource anywhere in a war file itself
> (thats
> >> not in jars/classes)
> >> So for example i just want to get the content of the index.html in the
> root
> >> of the myapp.war
> >> Or i want a special properties file that i have in the
> >> myapp.war/WEB-INF/my.properties
> >>
> >>
> >> in a filter or servlet:
> >>
> >> getServletContext().getResource("WEB-INF/my.properties");
> >>
> >> what is the line of code in a web socket endpoint to do the same?
> >> It seems that it is impossible to get the context of the webapp the
> socket
> >> is in..
> >
> > It isn't exposed via the API because WebSockets were designed to
> > be implementable independently from a J2EE container. You can do it via
> > the EndpointConfig but you have to do your own plumbing.
> >
> > Mark
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: Tomcat 8 Websockets configuration
Posted by Neil Martin <ns...@gmail.com>.
Thanks for the replies Mark.
It does seem to me that most developers using websockets under tomcat are going to want that integration with the J2EE container. Maybe I'm wrong, but it seems like the plumbing to make the servlet context available to the EndpoingConfig will be messy because the websockets framework has been designed to be divorced from its environment.
From this perspective, the tomcat 7 websockets implementation seems easier to work with; at least for developers who are looking to use websocket endpoints as a replacement for servlets. Does this make sense?
Neil
Sent from my iPad
> On Oct 27, 2013, at 8:04, Mark Thomas <ma...@apache.org> wrote:
>
> On 27/10/2013 12:36, Johan Compagner wrote:
>>>> and i have a follow up question about this, with a servlet or a filter
>>> you
>>>> can do: getServletContext() then you have access to the resources of the
>>>> web application and stuff like that
>>>> How is that possible in an websocket endpoint?
>>>
>>> The ServerEndpointConfig will have the modifyHandshake() method called
>>> where you have access to elements of the request and response. You need
>>> to copy any data you need at this point.
>>
>> i was not talking about (http)request or response objects.
>> But purely the ServletContext to access stuff of the web app itself.
>
> You'd have to put the ServletContext into the EndpointConfig.
>
>>>> If i want to load in a file that is in the current webapps WEB-INF dir
>>> how
>>>> do i do that? How do i get an url or inputstream (getResource() call) to
>>>> that file?
>>>
>>> Calls via the class loader will continue to work.
>> It's not a resource in the WEB-INF/classes or a resource in a jar file
>> I am talking about a normal resource anywhere in a war file itself (thats
>> not in jars/classes)
>> So for example i just want to get the content of the index.html in the root
>> of the myapp.war
>> Or i want a special properties file that i have in the
>> myapp.war/WEB-INF/my.properties
>>
>>
>> in a filter or servlet:
>>
>> getServletContext().getResource("WEB-INF/my.properties");
>>
>> what is the line of code in a web socket endpoint to do the same?
>> It seems that it is impossible to get the context of the webapp the socket
>> is in..
>
> It isn't exposed via the API because WebSockets were designed to
> be implementable independently from a J2EE container. You can do it via
> the EndpointConfig but you have to do your own plumbing.
>
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat 8 Websockets configuration
Posted by Mark Thomas <ma...@apache.org>.
On 27/10/2013 12:36, Johan Compagner wrote:
>>> and i have a follow up question about this, with a servlet or a filter
>> you
>>> can do: getServletContext() then you have access to the resources of the
>>> web application and stuff like that
>>> How is that possible in an websocket endpoint?
>>
>> The ServerEndpointConfig will have the modifyHandshake() method called
>> where you have access to elements of the request and response. You need
>> to copy any data you need at this point.
>>
>
> i was not talking about (http)request or response objects.
> But purely the ServletContext to access stuff of the web app itself.
You'd have to put the ServletContext into the EndpointConfig.
>>> If i want to load in a file that is in the current webapps WEB-INF dir
>> how
>>> do i do that? How do i get an url or inputstream (getResource() call) to
>>> that file?
>>
>> Calls via the class loader will continue to work.
>>
>>
> It's not a resource in the WEB-INF/classes or a resource in a jar file
> I am talking about a normal resource anywhere in a war file itself (thats
> not in jars/classes)
> So for example i just want to get the content of the index.html in the root
> of the myapp.war
> Or i want a special properties file that i have in the
> myapp.war/WEB-INF/my.properties
>
>
> in a filter or servlet:
>
> getServletContext().getResource("WEB-INF/my.properties");
>
> what is the line of code in a web socket endpoint to do the same?
> It seems that it is impossible to get the context of the webapp the socket
> is in..
It isn't exposed via the API because WebSockets were designed to
be implementable independently from a J2EE container. You can do it via
the EndpointConfig but you have to do your own plumbing.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat 8 Websockets configuration
Posted by Johan Compagner <jc...@servoy.com>.
> > and i have a follow up question about this, with a servlet or a filter
> you
> > can do: getServletContext() then you have access to the resources of the
> > web application and stuff like that
> > How is that possible in an websocket endpoint?
>
> The ServerEndpointConfig will have the modifyHandshake() method called
> where you have access to elements of the request and response. You need
> to copy any data you need at this point.
>
i was not talking about (http)request or response objects.
But purely the ServletContext to access stuff of the web app itself.
> > If i want to load in a file that is in the current webapps WEB-INF dir
> how
> > do i do that? How do i get an url or inputstream (getResource() call) to
> > that file?
>
> Calls via the class loader will continue to work.
>
>
It's not a resource in the WEB-INF/classes or a resource in a jar file
I am talking about a normal resource anywhere in a war file itself (thats
not in jars/classes)
So for example i just want to get the content of the index.html in the root
of the myapp.war
Or i want a special properties file that i have in the
myapp.war/WEB-INF/my.properties
in a filter or servlet:
getServletContext().getResource("WEB-INF/my.properties");
what is the line of code in a web socket endpoint to do the same?
It seems that it is impossible to get the context of the webapp the socket
is in..
johan
Re: Tomcat 8 Websockets configuration
Posted by Mark Thomas <ma...@apache.org>.
On 26/10/2013 16:44, Johan Compagner wrote:
> I've just started looking at the javax.websocket implementation in tomcat 8
>> and I have a question about how one integrates an endpoint with application
>> code. Using servlets as an analogy, web.xml allows configuration
>> information to be passed to servlets when they are initialized. Is there
>> an equivalent in the javax.websocket world? If not, are there any
>> suggested practices for achieving this?
There is no direct link from web.xml since WebSockets were designed to
be implementable independently from a J2EE container.
You can provide EndpointConfig instance that contain user defined
properties.
> and i have a follow up question about this, with a servlet or a filter you
> can do: getServletContext() then you have access to the resources of the
> web application and stuff like that
> How is that possible in an websocket endpoint?
The ServerEndpointConfig will have the modifyHandshake() method called
where you have access to elements of the request and response. You need
to copy any data you need at this point.
> If i want to load in a file that is in the current webapps WEB-INF dir how
> do i do that? How do i get an url or inputstream (getResource() call) to
> that file?
Calls via the class loader will continue to work.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat 8 Websockets configuration
Posted by Johan Compagner <jc...@servoy.com>.
I've just started looking at the javax.websocket implementation in tomcat 8
> and I have a question about how one integrates an endpoint with application
> code. Using servlets as an analogy, web.xml allows configuration
> information to be passed to servlets when they are initialized. Is there
> an equivalent in the javax.websocket world? If not, are there any
> suggested practices for achieving this?
>
and i have a follow up question about this, with a servlet or a filter you
can do: getServletContext() then you have access to the resources of the
web application and stuff like that
How is that possible in an websocket endpoint?
If i want to load in a file that is in the current webapps WEB-INF dir how
do i do that? How do i get an url or inputstream (getResource() call) to
that file?
johan