https://bugs.eclipse.org/424734 - WebSocket / Expose Locale information
from ServletUpgradeRequest

Committed as
http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/commit/?id=118fc97fe132f4b80bd3e6f6e3e1d5effaa5cf5f

Also added: https://bugs.eclipse.org/424735 - WebSocket / Make
ServletUpgradeRequest implement HttpServletRequest
Will work on that tomorrow.


--
Joakim Erdfelt <[email protected]>
webtide.com <http://www.webtide.com/> - intalio.com/jetty
Expert advice, services and support from from the Jetty & CometD experts
eclipse.org/jetty - cometd.org


On Sun, Dec 29, 2013 at 9:14 AM, Nils Kilden-Pedersen <[email protected]>wrote:

> On Sun, Dec 29, 2013 at 12:47 PM, Nils Kilden-Pedersen 
> <[email protected]>wrote:
>
>> On Sun, Dec 29, 2013 at 12:54 AM, Joakim Erdfelt <[email protected]>wrote:
>>
>>> We fixed some of this with Jetty 9.1.x.
>>>
>>> There is now a 
>>> ServletUpgradeRequest<http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/websocket/servlet/ServletUpgradeRequest.html>that
>>>  is based on HttpServletRequest.
>>> Its directly referenced in 
>>> WebSocketCreator.createWebSocket(ServletUpgradeRequest
>>> req, ServletUpgradeResponse 
>>> resp)<http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/websocket/servlet/WebSocketCreator.html#createWebSocket(org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest,%20org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse)>
>>> ;
>>>
>>
>> Ok, this is great. I'll be upgrading to 9.1 soon anyway.
>>
>
> Just tried this. I guess I interpreted "based on" as "extends". I now see
> that it simply wraps an HttpServletRequest, but doesn't expose it.
>
> Any reason ServletUpgradeRequest doesn't either expose the underlying
> HttpServletRequest or is itself an HttpServletRequest?
>
> Or at least add the getLocales() method.
>
>
>
>>
>>
>>>
>>> However, its not accessible from within the 
>>> Session.getUpgradeRequest()<http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/websocket/api/Session.html#getUpgradeRequest()>
>>> .
>>> Know that UpgradeRequest is the exposed API, unwrapping and digging into
>>> the jetty specifics is not a long term, future-proof approach.
>>>
>>> You could do something like this (notice that this only uses java
>>> classes + websocket api classes + junit)
>>>
>>> package jetty.websocket;
>>>
>>> import java.util.ArrayList;
>>> import java.util.Collections;
>>> import java.util.Iterator;
>>> import java.util.List;
>>>
>>> import org.eclipse.jetty.websocket.api.util.QuoteUtil;
>>> import org.junit.Test;
>>>
>>> public class AcceptLanguagesTest
>>> {
>>>     public static class QualityValue implements Comparable<QualityValue>
>>>     {
>>>         public String value;
>>>         public double quality;
>>>
>>>         public QualityValue(String value, double quality)
>>>         {
>>>             this.value = value;
>>>             this.quality = quality;
>>>         }
>>>
>>>         @Override
>>>         public int compareTo(QualityValue o)
>>>         {
>>>             return (int)((o.quality * 100) - (this.quality * 100));
>>>         }
>>>
>>>         @Override
>>>         public String toString()
>>>         {
>>>             return String.format("%s [quality=%.1f]",value,quality);
>>>         }
>>>     }
>>>
>>>     @Test
>>>     public void testAcceptLanguages()
>>>     {
>>>         String acceptLangs = "tr-tr,tr;q=0.8,en-us;q=0.5,en;q=0.3";
>>>         System.out.printf("--] %s%n", acceptLangs);
>>>         List<QualityValue> values = parseQualityValues(acceptLangs);
>>>         for (QualityValue value : values)
>>>         {
>>>             System.out.println(value);
>>>         }
>>>     }
>>>
>>>     @Test
>>>     public void testAcceptLanguagesOdd()
>>>     {
>>>         String acceptLangs = "tr-tr,tr;q=0.2,en-us;q=0.9,en;q=0.3";
>>>         System.out.printf("--] %s%n", acceptLangs);
>>>         List<QualityValue> values = parseQualityValues(acceptLangs);
>>>         for (QualityValue value : values)
>>>         {
>>>             System.out.println(value);
>>>         }
>>>     }
>>>
>>>     private List<QualityValue> parseQualityValues(String raw)
>>>     {
>>>         List<QualityValue> ret = new ArrayList<>();
>>>         Iterator<String> parts = QuoteUtil.splitAt(raw,",");
>>>         while (parts.hasNext())
>>>         {
>>>             String part = parts.next();
>>>             String value = null;
>>>             double quality = 1.0;
>>>             Iterator<String> qs = QuoteUtil.splitAt(part,";");
>>>             while (qs.hasNext())
>>>             {
>>>                 String q = qs.next();
>>>                 if (q.startsWith("q"))
>>>                 {
>>>                     int idx = q.indexOf('=');
>>>                     if (idx > 0)
>>>                     {
>>>                         quality = Double.parseDouble(q.substring(idx +
>>> 1));
>>>                     }
>>>                 }
>>>                 else
>>>                  {
>>>                     value = q;
>>>                 }
>>>             }
>>>             if (value == null)
>>>             {
>>>                 value = part;
>>>             }
>>>             ret.add(new QualityValue(value,quality));
>>>         }
>>>         Collections.sort(ret);
>>>         return ret;
>>>      }
>>> }
>>>
>>> Output from this testcase ...
>>>
>>> --] tr-tr,tr;q=0.8,en-us;q=0.5,en;q=0.3
>>> tr-tr [quality=1.0]
>>> tr [quality=0.8]
>>> en-us [quality=0.5]
>>> en [quality=0.3]
>>> --] tr-tr,tr;q=0.2,en-us;q=0.9,en;q=0.3
>>> tr-tr [quality=1.0]
>>> en-us [quality=0.9]
>>> en [quality=0.3]
>>> tr [quality=0.2]
>>>
>>>
>>> Now, that being said, exposing either a ..
>>>
>>>       List<String> UpgradeRequest.getHeaderValues(String name)
>>> or   List<WeightedValue> UpgradeRequest.getWeightedHeaderValues(String
>>> name)
>>> or   List<String> UpgradeRequest.getUserLocales()
>>> or   List<WeightedValue> QuoteUtil.parseWeightedValues(String
>>> headervalue)
>>>
>>> sounds like a reasonable feature / enhancement request.
>>>
>>>
>>> --
>>> Joakim Erdfelt <[email protected]>
>>> webtide.com <http://www.webtide.com/> - intalio.com/jetty
>>> Expert advice, services and support from from the Jetty & CometD experts
>>> eclipse.org/jetty - cometd.org
>>>
>>>
>>> On Sat, Dec 28, 2013 at 12:57 PM, Nils Kilden-Pedersen <[email protected]
>>> > wrote:
>>>
>>>> I wanted to reuse the methods for extracting weighted header values.
>>>> More specifically, I'm trying to get the user locale(s) from the
>>>> UpgradeRequest on websocket creation.
>>>>
>>>>
>>>> On Sat, Dec 28, 2013 at 3:22 PM, Joakim Erdfelt <[email protected]>wrote:
>>>>
>>>>> the org.eclipse.jetty.http.HttpHeader is not exposed by Jetty's
>>>>> WebSocketServlet, what are you trying to do?
>>>>>
>>>>> --
>>>>> Joakim Erdfelt <[email protected]>
>>>>> webtide.com <http://www.webtide.com/> - intalio.com/jetty
>>>>> Expert advice, services and support from from the Jetty & CometD
>>>>> experts
>>>>> eclipse.org/jetty - cometd.org
>>>>>
>>>>>
>>>>> On Sat, Dec 28, 2013 at 5:20 AM, Nils Kilden-Pedersen <
>>>>> [email protected]> wrote:
>>>>>
>>>>>> Using 9.0.6, I’m referencing HttpHeader in my web socket servlet,
>>>>>> but apparently the http classes are not accessible to the servlet.
>>>>>>
>>>>>> java.lang.ClassNotFoundException: org.eclipse.jetty.http.HttpHeader
>>>>>>
>>>>>> How do I fix this?
>>>>>>
>>>>>> _______________________________________________
>>>>>> jetty-users mailing list
>>>>>> [email protected]
>>>>>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>>>>>
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> jetty-users mailing list
>>>>> [email protected]
>>>>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> jetty-users mailing list
>>>> [email protected]
>>>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>>>
>>>>
>>>
>>> _______________________________________________
>>> jetty-users mailing list
>>> [email protected]
>>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>>
>>>
>>
>
> _______________________________________________
> jetty-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
>
_______________________________________________
jetty-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to