In Pax Web 8 I'll try to make it clear "what is alias"? I think it comes from (correct me if I'm wrong) ... https://httpd.apache.org/docs/2.4/mod/mod_alias.html#alias meaning a "place in URI namespace accessible via HTTP". Http Service spec (chapter 102 of OSGi CMPN) confuses "name", "alias" and "URI pattern" heavily...
When I was fixing some bugs in Pax Web some time ago, I found that alias SHOULD BE just specialized, single-element array of URI patterns. It helped with the tests and general comprehension, but I didn't notice this aliasAsUrlPattern() method... regards Grzegorz czw., 6 lut 2020 o 13:44 Miroslav Beranič <[email protected]> napisał(a): > Hi Grzegorz, > > so yes, this was it. > > It can be used: > > props.put(ExtenderConstants.PROPERTY_URL_PATTERNS, new > String[]{"/sl/zdravo", "/en/hello", "/de/halo"}); > > or > > props.put(ExtenderConstants.PROPERTY_ALIAS, "/sl/zdravo"); > > but can not use both. But, now Alias is missing in the Karaf http:list and > some other internal logic, dependant on the alias is also not working, but > ... I guess I can work around it. > > OK, this kind of solved the problem for now. But why it is not allowed to > have both? I guess you would want to have alias and n other url patterns > for the Servlet, or not? > > > Kind regards, > Miroslav > > > > V V čet., 6. feb. 2020 ob 13:38 je oseba Miroslav Beranič < > [email protected]> napisala: > >> Hi Grzegorz, >> >> I've followed the example provided at GitHub: >> >> >> https://github.com/ops4j/org.ops4j.pax.web/blob/master/samples/whiteboard/src/main/java/org/ops4j/pax/web/extender/samples/whiteboard/internal/Activator.java >> >> Thank you for the notice. >> >> Kind regards, >> Miroslav >> >> >> V V čet., 6. feb. 2020 ob 13:27 je oseba Grzegorz Grzybek < >> [email protected]> napisala: >> >>> Hello >>> >>> I've checked >>> org.ops4j.pax.web.extender.whiteboard.internal.tracker.ServletTracker#createWebElement() >>> and indeed - it takes "alias" from "alias" property and may take patterns >>> from "urlPatterns" or "osgi.http.whiteboard.servlet.pattern" - but you >>> CAN'T specify "alias" property to do it. >>> >>> Please don't use: >>> >>> props.put(ExtenderConstants.PROPERTY_ALIAS, "/hello"); >>> >>> regards >>> Grzegorz >>> >>> czw., 6 lut 2020 o 13:07 Miroslav Beranič <[email protected]> >>> napisał(a): >>> >>>> Hi JB, >>>> >>>> Took the code from: >>>> >>>> https://github.com/ops4j/org.ops4j.pax.web/tree/master/samples/whiteboard >>>> >>>> to be able to use ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID => Virtual >>>> hosts "feature" of Jetty. >>>> >>>> { >>>> Dictionary<String, Object> props; >>>> props = new Hashtable<>(); >>>> >>>> props.put(ExtenderConstants.PROPERTY_ALIAS, "/hello"); >>>> props.put(ExtenderConstants.PROPERTY_HTTP_CONTEXT_ID, >>>> "virtualhost"); >>>> >>>> // Fail with Exception: from inside constructor of class >>>> org.ops4j.pax.web.extender.whiteboard.internal.element.ServletWebElement >>>> // props.put(ExtenderConstants.PROPERTY_URL_PATTERNS, "/hello"); >>>> >>>> props.put(ExtenderConstants.DEFAULT_INIT_PREFIX_PROP + >>>> "exactUrlPattern", Boolean.TRUE); >>>> >>>> servletReg = bundleContext.registerService(Servlet.class, new >>>> WhiteboardServlet("/hello"), props); >>>> } >>>> >>>> Kind Regards, >>>> Miroslav >>>> >>>> >>>> Dne četrtek, 06. februar 2020 12.50.17 UTC+1 je oseba Jean-Baptiste >>>> Onofré napisala: >>>>> >>>>> Hi >>>>> >>>>> Can you please share how you register the servlet ? Via the >>>>> httpService.register, Servlet service registration or whiteboard ? >>>>> >>>>> Thanks, >>>>> Regards >>>>> JB >>>>> >>>>> On Thu, Feb 6, 2020 at 12:14 PM Miroslav Beranič < >>>>> [email protected]> wrote: >>>>> >>>>>> Hi all, >>>>>> >>>>>> I work with Pax Web on Karaf 4.3.0. I am trying to register Servlet >>>>>> with exact url, but I see url pattern is auto-generated from alias. >>>>>> I look at the current master branch - version 8.0.0-SNAPSHOT. Class: >>>>>> >>>>>> org.ops4j.pax.web.service.spi.model.ServletModel >>>>>> >>>>>> >>>>>> constructor: >>>>>> #ServletModel(org.ops4j.pax.web.service.spi.model.ContextModel, >>>>>> javax.servlet.Servlet, java.lang.String, java.lang.String[], >>>>>> java.lang.String, java.util.Dictionary<java.lang.String,?>, >>>>>> java.lang.Integer, java.lang.Boolean, >>>>>> javax.servlet.MultipartConfigElement) >>>>>> >>>>>> >>>>>> it calles method ( private static ) >>>>>> new String[]{aliasAsUrlPattern(alias)} >>>>>> >>>>>> >>>>>> private static String aliasAsUrlPattern(final String alias) { >>>>>> String urlPattern = alias; >>>>>> if (urlPattern != null && !urlPattern.equals("/") >>>>>> && !urlPattern.contains("*")) { >>>>>> if (urlPattern.endsWith("/")) { >>>>>> urlPattern = urlPattern + "*"; >>>>>> } else { >>>>>> urlPattern = urlPattern + "/*"; >>>>>> } >>>>>> } >>>>>> return urlPattern; >>>>>> } >>>>>> >>>>>> >>>>>> so it always creates a url pattern, as I guess the name suggest, but >>>>>> why? I would like to register exact URL, not the pattern. As it looks >>>>>> now, >>>>>> this is not possible to do - as there is no argument to pass in to >>>>>> control >>>>>> the flow. >>>>>> >>>>>> As it looks from the git history/log this is quite "old" code - from >>>>>> 2008 - 2013, so I guess this is not new and I guess everybody are ok with >>>>>> this? So in this case, what is the usecase for it? As for my usecase - >>>>>> this >>>>>> is not the required behavior. >>>>>> >>>>>> For example, Servlet, registered with /hello, also matches /hello/1, >>>>>> but I want /hello/1 to return HTTP 404. >>>>>> >>>>>> >>>>>> So for now, only really question is - is this expected behavior or is >>>>>> there a room to change this? If so, how can one, with existing solution, >>>>>> register Servlet with exact URL? >>>>>> >>>>>> Exact strack of calls looks like this: >>>>>> >>>>>> <init>:53, ServletModel (org.ops4j.pax.web.service.spi.model) >>>>>> registerServlet:224, HttpServiceStarted >>>>>> (org.ops4j.pax.web.service.internal) >>>>>> registerServlet:210, HttpServiceStarted >>>>>> (org.ops4j.pax.web.service.internal) >>>>>> registerServlet:69, HttpServiceProxy >>>>>> (org.ops4j.pax.web.service.internal) >>>>>> register:97, ServletWebElement >>>>>> (org.ops4j.pax.web.extender.whiteboard.internal.element) >>>>>> registerWebElement:392, WebApplication >>>>>> (org.ops4j.pax.web.extender.whiteboard.internal) >>>>>> addWebElement:188, WebApplication >>>>>> (org.ops4j.pax.web.extender.whiteboard.internal) >>>>>> addingService:193, AbstractTracker >>>>>> (org.ops4j.pax.web.extender.whiteboard.internal.tracker) >>>>>> addingService:46, AbstractTracker >>>>>> (org.ops4j.pax.web.extender.whiteboard.internal.tracker) >>>>>> customizerAdding:941, ServiceTracker$Tracked (org.osgi.util.tracker) >>>>>> customizerAdding:870, ServiceTracker$Tracked (org.osgi.util.tracker) >>>>>> trackAdding:256, AbstractTracked (org.osgi.util.tracker) >>>>>> track:229, AbstractTracked (org.osgi.util.tracker) >>>>>> serviceChanged:901, ServiceTracker$Tracked (org.osgi.util.tracker) >>>>>> invokeServiceListenerCallback:990, EventDispatcher >>>>>> (org.apache.felix.framework) >>>>>> fireEventImmediately:838, EventDispatcher (org.apache.felix.framework) >>>>>> fireServiceEvent:545, EventDispatcher (org.apache.felix.framework) >>>>>> fireServiceEvent:4595, Felix (org.apache.felix.framework) >>>>>> registerService:3587, Felix (org.apache.felix.framework) >>>>>> registerService:348, BundleContextImpl (org.apache.felix.framework) >>>>>> registerService:355, BundleContextImpl (org.apache.felix.framework) >>>>>> >>>>>> I've changed this in my branch, added additional method with same >>>>>> name and initParams: >>>>>> >>>>>> private static String aliasAsUrlPattern(final String alias, final >>>>>> Dictionary<String, ?> initParams) { >>>>>> final Object exactUrlPatternFromAliasParam = >>>>>> initParams.get("exactUrlPattern"); >>>>>> Boolean exactUrlPatternFromAlias = Boolean.FALSE; >>>>>> if (null != exactUrlPatternFromAliasParam) { >>>>>> if (exactUrlPatternFromAliasParam instanceof String) { >>>>>> final String flag = ((String) >>>>>> exactUrlPatternFromAliasParam).toLowerCase(); >>>>>> exactUrlPatternFromAlias = Boolean.parseBoolean(flag); >>>>>> } else if(exactUrlPatternFromAliasParam instanceof Boolean) { >>>>>> final Boolean flag = (Boolean) exactUrlPatternFromAliasParam; >>>>>> exactUrlPatternFromAlias = flag; >>>>>> } else if (exactUrlPatternFromAliasParam instanceof >>>>>> Serializable) { >>>>>> final String flag = >>>>>> exactUrlPatternFromAliasParam.toString().toLowerCase(); >>>>>> exactUrlPatternFromAlias = Boolean.parseBoolean(flag); >>>>>> } >>>>>> } >>>>>> final String result; >>>>>> if (Boolean.TRUE.equals(exactUrlPatternFromAlias)) { >>>>>> // Break the reference >>>>>> result = alias.toString(); >>>>>> } else { >>>>>> result = aliasAsUrlPattern(alias); >>>>>> } >>>>>> return result; >>>>>> } >>>>>> >>>>>> >>>>>> This calls original unmodified version of method aliasAsUrlPattern. >>>>>> >>>>>> Caller has to pass additional init parameter "exactUrlPattern". I >>>>>> usually call it with Boolean.TRUE. I guess flag could/should be added >>>>>> into >>>>>> org.ops4j.pax.web.extender.whiteboard.ExtenderConstants. >>>>>> >>>>>> To note one other thing -- this is " one of the use cases ", I as see >>>>>> there is also construction, that allows to pass in defined url patterns, >>>>>> but I did not find how to call it. The call I am using is: >>>>>> >>>>>> props.put(ExtenderConstants.DEFAULT_INIT_PREFIX_PROP + >>>>>> "exactUrlPattern", Boolean.TRUE); >>>>>> bundleContext.registerService(Servlet.class, new >>>>>> WhiteboardServlet("/hello"), props); >>>>>> >>>>>> Could be, that if HttpService interface is used, this is not the case. >>>>>> >>>>>> I've tried to solve this using >>>>>> >>>>>> props.put(ExtenderConstants.PROPERTY_URL_PATTERNS, "/hello"); >>>>>> >>>>>> This is illegal state as implemented by the constructor of class: >>>>>> >>>>>> >>>>>> org.ops4j.pax.web.extender.whiteboard.internal.element.ServletWebElement >>>>>> >>>>>> if (alias != null && urlPatterns != null && urlPatterns.length != 0) { >>>>>> LOG.warn("Registered servlet [{}] cannot have both alias and url >>>>>> patterns.", getServiceID()); >>>>>> valid = false; >>>>>> } >>>>>> >>>>>> >>>>>> I did not look into this yet, but why is this implemented like so? If >>>>>> this would be changed, it would make use of existing constants. >>>>>> >>>>>> >>>>>> Kind Regards, >>>>>> Miroslav >>>>>> >>>>>> >>>>>> -- >>>>>> -- >>>>>> ------------------ >>>>>> OPS4J - http://www.ops4j.org - [email protected] >>>>>> >>>>>> --- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "OPS4J" group. >>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>> send an email to [email protected]. >>>>>> To view this discussion on the web visit >>>>>> https://groups.google.com/d/msgid/ops4j/179c33ab-fdd3-451f-b4ff-57f2fc934a04%40googlegroups.com >>>>>> <https://groups.google.com/d/msgid/ops4j/179c33ab-fdd3-451f-b4ff-57f2fc934a04%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>>> . >>>>>> >>>>> -- >>>> -- >>>> ------------------ >>>> OPS4J - http://www.ops4j.org - [email protected] >>>> >>>> --- >>>> You received this message because you are subscribed to the Google >>>> Groups "OPS4J" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/ops4j/9016e27b-4059-4c2d-83ad-1ae42d5083c5%40googlegroups.com >>>> <https://groups.google.com/d/msgid/ops4j/9016e27b-4059-4c2d-83ad-1ae42d5083c5%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> -- >>> -- >>> ------------------ >>> OPS4J - http://www.ops4j.org - [email protected] >>> >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "OPS4J" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/ops4j/CAAdXmhoCKVNaxKmy51dWFE2uMBmSbSZHBKb3azGJ9PwJ%2BrPVGg%40mail.gmail.com >>> <https://groups.google.com/d/msgid/ops4j/CAAdXmhoCKVNaxKmy51dWFE2uMBmSbSZHBKb3azGJ9PwJ%2BrPVGg%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> >> >> >> -- >> Miroslav Beranič >> MIBESIS >> [email protected] >> https://www.mibesis.si >> > > > -- > Miroslav Beranič > MIBESIS > [email protected] > https://www.mibesis.si > > -- > -- > ------------------ > OPS4J - http://www.ops4j.org - [email protected] > > --- > You received this message because you are subscribed to the Google Groups > "OPS4J" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ops4j/CA%2B3Fds4h7EpEq_hQi1y_g1deGTokj6z4h06myo%2BUR9R%3DZpV5KQ%40mail.gmail.com > <https://groups.google.com/d/msgid/ops4j/CA%2B3Fds4h7EpEq_hQi1y_g1deGTokj6z4h06myo%2BUR9R%3DZpV5KQ%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- -- ------------------ OPS4J - http://www.ops4j.org - [email protected] --- You received this message because you are subscribed to the Google Groups "OPS4J" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/CAAdXmhqnAZQC4jEEP-cbNi_0U_BcBAoYxCY4s3AUN4UHuNLwtg%40mail.gmail.com.
