How does sw-toolbox router rule order/priority work? - router

In my service worker (which uses sw-toolbox library) I have setup two routes as follows:
toolbox.router.any("/user/*", toolbox.networkOnly);
toolbox.router.any("/user/logout", toolbox.logoutHandler);
I assumed that the second rule which is specific to the "/user/logout" path, would act as an exception to the first rule (which is a blanket rule for the path "/user/*") however, I can confirm that it does not.
Am I using this sw-toolbox route config correctly?

I think the rules are independent, first matching rule wins. So this should works:
toolbox.router.any("/user/logout", toolbox.logoutHandler);
toolbox.router.any("/user/*", toolbox.networkOnly);
See Jeff's comment on this issues: "The routing to handlers should match in the order they're registered"

Related

Apache Sling Resource Mapping in CQ 5.6.1

I've been taking several hours fiddling this Resource Mapping for no luck. I have put a new node in /etc/map/http named GoogleAnalyticsMap. It had the following properties:
Name: jcr:primaryType
Type: Name
Value: sling:Mapping
Name: sling:internalRedirect
Type: String
Value: /content/dam/website/Common/my_google_analytics_key.html
Name: sling:match
Type: String
Value: [^/]+/[^/]+/my_google_analytics_key.html
Funnily, when i checked to /system/console/jcrresolver or Adobe CQ Web Console Sling Resource Resolver. It resolves into the following
Pattern: ^http/[^/]+/[^/]+/my_google_analytics_key.html
Replacement: /content/dam/website/Common/my_google_analytics_key.html
Redirect: internal
I have no idea how they could register ^[^/]+/[^/]+/welcome$ as shown in the example and did not have the 'http' there. Nevertheless, whenever i try to hit the pattern locally (i.e. http://localhost:4502/my_google_analytics_key.html) it only shows resource not found. Also checked through the Configuration test section that available in Adobe CQ Web Console Sling Resource Resolver it says that it can't resolve. Did i miss something?
, type=sling:nonexisting, path=/my_google_analytics_key.html, resource=[NonExistingResource, path=/my_google_analytics_key.html]
Thank you for the help.
p.s. i've checked the Sling documentation also, however, it baffles me that i can't add sling:alias, perhaps its also something to do with the sling version. Nevertheless, i should ask this as second question later, once the sling:match is working properly.
Edit: fiddling a bit, changing the sling:match to localhost.4502/google.html does let it to redirect localhost:4502/google.html to the desired DAM item. Well, i'm still asking for 'domain-free' matching though.. so i have no trouble when using the mapping for all environment i have..
Edit, Updates:
Apparently due to me put the new sling:Mapping under http folder it will always prefix the path with http. Perhaps the example is meant to be put not under http folder.
Next item is, it will always assume the matching item will be protocols, domain, and port separated by dots (yes, even \. is not a valid input and CQ or rather sling will sanitize it somehow). Something like *.(4502|4503|80|443)/my_google_analytics_key.html will accept any domains and those designated ports. I do wonder if it really the case, since they says regex but it does not feel so much regex.
Some says that sling:internalRedirect should be a String[] - yes i know the docs says String. I have not test this further and take it as it is..

How do you use the serviceNameFilter when calling QueryClient.GetServiceListAsync

I'm using Azure Service Fabric with stateless services. I have a list of services deployed under an application, and there's a naming convention used with those service names. I'd like to get a list of services that match a filter expression.
Here is a link to a screenshot of my service fabric explorer. I don't have the reputation points to post an image.
Service Fabric Explorer screenshot
In this example, the name of my application is SFApp1, and the name of my service is HelloWorldStateless. I'd like to query the service fabric cluster to locate all services with the name "HelloWorldSt*" (under the SFApp1 application of course).
I know I can query to find all services with the application name "fabric:/SFApp1", and it'll return all services under that application. This overload of GetServiceListAsync takes just an application URI.
FabricClient client = new FabricClient();
ServiceList serviceList = client.QueryManager.GetServiceListAsync(new Uri("fabric:/SFApp1")).Result;
I also know I can query to find a specific service. This overload takes an application URI AND a service URI and will return a single-item list.
FabricClient client = new FabricClient();
ServiceList serviceList = client.QueryManager.GetServiceListAsync(new Uri("fabric:/SFApp1"), new Uri("fabric:/SFApp1/HelloWorldStateless")).Result;
What I'm trying to find out is if there's any way to do something like a wildcard search.
FabricClient client = new FabricClient();
ServiceList serviceList = client.QueryManager.GetServiceListAsync(new Uri("fabric:/SFApp1"), new Uri("fabric:/SFApp1/HelloWorldSt*")).Result;
The name of the parameter where the service name is specified is serviceNameFilter, and the method returns a list. I'm wondering why they would return a list for this overload if the result was always going to be a single-item list. Also, the parameter name "serviceNameFilter" suggests (to me at least) that there's the ability to supply some kind of expression to narrow down your list.
Here's what I've tried already. I've tried the code above, where I chop off a few characters and put an asterisk. I've tried without the asterisk to see if it was a substring match. I've tried SQL-style, with a percent symbol. I've tried a question mark. All of those attempts returned an empty list.
My current workaround is just to ask for all services under that application, and I'll filter them on the client code end with a linq expression. That'll work, but I worry about performance if my list of services gets really big.
Would be nice if I could inspect the source code to answer this myself.
Is there a way to do what I'm trying to do, or am I just misinterpreting what "serviceNameFilter" means, and it just means you have to put the entire service URI that you're looking for?
Thanks for any help you can provide!
Unfortunately that API parameter is terribly named. It's not really a filter at all, it's just the name of the service (since there's no other query that just returns one service, this is how you "filter" from all the services in an application down to just one in particular).
The nearest thing to what you're looking for is EnumerateSubnames. It's not a wildcard search, but you can get all the names that exist "underneath" a given name (for example, all of the service names that exist within an application, or all names with some specific prefix). Depending on the structure of how you create your service names this could work for you.
// System.Fabric.FabricClient.PropertyManagementClient
public Task<NameEnumerationResult> EnumerateSubNamesAsync(Uri name, NameEnumerationResult previousResult, bool recursive)
For example: Presume the following names exist in the cluster:
fabric:/SomeApplication/Zone1/Service1
fabric:/SomeApplication/Zone1/Service2
fabric:/SomeApplication/Zone2/Service1
Note that in this case the application would have been created with the name "fabric:/SomeApplication" and then the services with the detailed names above incorporating the "Zone" segment.
If you now EnumerateSubnames("fabric:/SomeApplication/Zone1", null, true) you'd get back a result that gave you the full names that matched (1 & 2 above).

General rule for what can be inside of a chain in Spring Integration

I need to use a JPA retrieving outbound gateway and I would like to chain it with a header enricher. Trying to do this I went over the documentation to understand if there is a general rule to know if an endpoint could be inside of a chain or not. I couldn't find the rule of thumb on what can be or not.
My particular case I'm trying to do this:
<int:chain input-channel="audTrailRetrievalChannel" output-channel="updateResponseForTestSent">
<int-jpa:retrieving-outbound-gateway id="getAudTrail" jpa-query="select e.details from AudTrail e where e.audTrailRecId = :id" entity-manager-factory="auditEntityManager">
<int-jpa:parameter name="id" expression="payload?.body?.response?.responseInformation?.communicationVariables?.variable.?[variableName=='audTrailRecId'][0]?.variableValue"/>
</int-jpa:retrieving-outbound-gateway>
<int:header-enricher>
<int:header name="registerMethod" value="registerAuditTrail" overwrite="true"/>
</int:header-enricher>
</int:chain>
You can put anything within a chain but an outbound channel adapter or router (anything that does not have an output channel - implement MessageProducer) must be the last element.
http://docs.spring.io/spring-integration/reference/html/messaging-routing-chapter.html#chain

Zend Framework hostname routing

I have the following code:
$route = new Zend_Controller_Router_Route_Hostname("test", array('controller'=>'mycontroller'));
This works fine, and redirects requests to the index action in 'mycontroller'.
What I need to do is to be able to call the following url:
http://test/myaction
Where the action called is mycontroller->myaction
Does anyone have a clue?
Thanks.
From the documentation
Hostname routes can, but never should be used as is. The reason behind that is, that a hostname route alone would match any path. So what you have to do is to chain a path route to the hostname route. This is done like in the example by calling $hostnameRoute->chain($pathRoute);. By doing this, $hostnameRoute isn't modified, but a new route (Zend_Controller_Router_Route_Chain) is returned, which can then be given to the router.
Given there are no actual variable components in your hostname route, it's quite redundant. You're better off just sticking with a Zend_Controller_Router_Route or Zend_Controller_Router_Route_Static if there are no variable parts to your routes.

Fiddler: how to make a subnet-based filter?

I would like Fiddler2's host filter to keep sessions to all hosts on 192.168.2.*
The docs say that e.g. fiddler2.com filter would catch all *.fiddler2.com but I can't figure how to do the same kind of filtering for IP subnets instead of hostnames.
Is there a specific syntax? Should I use a custom rule?
TIA.
You need to write a custom rule. Inside OnBeforeResponse, look at the m_hostIP property on the session and use that to set the UI-HIDE flag if it doesn't match the site you care about.