cq5/aem url rewriting or mapping dispatcher and apache web server - webserver

I am new to cq5/aem url re-writing with selectors. I have the following scenarios to achieve. Could you please help me how to do it.
I need to request an URL such as
http://localhost:4502/batteries/toyota/corolla/2011/LE/
which should convert to
http://localhost:4502/content/myprojectroot/project1/en/batteries/search-results.toyota.corolla.2011.LE.html
using apache web server/dispatcher configuration and cq5/aem (etc/map). Please help me how to achieve this.

If you define a node under /etc/map as follows, the filters on the publisher will re-route the request:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:Mapping"
sling:internalRedirect="[/content/myprojectroot/project1/en/batteries/search-results.$1.$2.$3.$4.html]"
sling:match=".+/batteries/(.*)/(.*)/(.*)/(.*)/"/>
This sling.match allows you to match groups, then use the $1 syntax to capture that match portion to use in the re-route URL.
Then you just need to ensure that the dispatcher allows the initial URL pattern. Once the dispatcher does its thing it sends the request to the publisher, and then on the publisher the map redirect will occur as the request is processed.
Also see https://docs.adobe.com/docs/en/aem/6-1/deploy/configuring/resource-mapping.html and https://docs.adobe.com/docs/en/dispatcher/disp-config.html

use apache mod_rewrite do modify the url hitting the dispachter!

Use Rewrite rule as below on your Vhost:
RewriteRule ^/batteries/toyota/corolla/2011/LE/ /content/myprojectroot/project1/en/batteries/search-results.toyota.corolla.2011.LE.html [R=301,L]

Related

Using Insomnia To Make Soap Calls

I am trying to use Insomnia to make soap calls - specifically trying to get post to succeed. I defined the URL as the end point and put the body type as XML with the SOAP contents (envelope, header, body). I defined the user id and password in the header. When I run I get 415 Unsupported Media Type. I can't really paste the soap contents because of all of the URL addressing in the envelope. I am using Insomnia to succeed in doing the REST call to get my information (for some crazy reason the gets are REST but the posts are SOAP) but can't get the insert to work. Is there something special I need, or does Insomnia not support SOAP post transactions? I googled and it appears in 2018 this was added. I don't have the WSDL available.
I appreciate this is not giving lots of information so guidance on what more I may provide to get assistance will also be helpful. Has anyone succeeded in using Insomnia to make SOAP calls?
All that was needed for me to make it work was:
Request method: POST.
Setting the Content-Type header to text/xml; charset=utf-8 (application/xml gave me the 415 response).
Wrapping request body in proper SOAP envelope.
You should be able to call GET on YourHandler.asmx to look up envelopes for requests you want to use. Envelope should look somewhat like this:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<HelloWorld xmlns="http://tempuri.org/">
<foo>
<Id>1</Id>
<Name>Bar</Name>
</foo>
</HelloWorld>
</soap:Body>
</soap:Envelope>
Credits for the guidance and envelope sample goes to this answer.
You can import the WSDL file, so that all methods, headers etc. will be created automatically. Click on:
Go to dashboard
Click Create
Choose URL (under import from)
Paste the WSDL URL and click Fetch and Import
As an example you can use the following URL: http://www.dneonline.com/calculator.asmx?wsdl
You will get this:
The problem as of writing this answer is, that there are two bugs:
Not all WSDL URLs are getting imported correctly (e.g. this one works in SOAP UI, but not in Insomnia http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL)
The methods are getting imported, but they don't work
You can submit and issue on Github, so that this is getting fixed: https://github.com/Kong/insomnia

Dispatcher returns wrong content-type

When I first access to any css file on my dispatcher Content-Type of request is "text/hml".
After I do a second request to this file the request has correct Content-Type "text/css"
How to fix this problem, because akamai caches first request with wrong content type?
Seems like dispatcher returns wrong css file, and caches normal variant.
It is necessary to add add the statement
ModMimeUsePathInfo
to Apache webserver configuration
See more at adobe forum

Using JMeter SOAP/XML-RPC Request to call ChemSpell Web Service

I'm trying to test the web service api for a free service called ChemSpell. I am trying to use JMeter's SOAP/XML-RPC Request option to test it. I am a bit new at this and not sure what to enter in. The call expects two parameters, which for testing purposes I want to set to the following:
Name = "formeldehyde"
Source = "All databases"
Based on their site I'm putting "http://chemspell.nlm.nih.gov:80/axis/SpellAid.jws" for the URL and "http://chemspell.nlm.nih.gov" in Send SOAPAction. I'm not sure how to configure the "Soap/XML-RPC Data" portion. I'm thinking the WSDL file they provide should give me everything I need to configure that section, but I'm not exactly sure how. Any help is much appreciated!
You need to create the xml that will be sent to the webservice, based on the wsdl, and paste it in the SOAP/XML-RPC data field.
The xml will describe the method call you wish to make and the data you wish to pass to it.
It will look like this (you will need to replace ? with data):
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:spel="http://chemspell.nlm.nih.gov/axis/SpellAid.jws/axis/SpellAid.jws">
<soapenv:Header/>
<soapenv:Body>
<spel:getSugList soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<name xsi:type="xsd:string">?</name>
<src xsi:type="xsd:string">?</src>
</spel:getSugList>
</soapenv:Body>
</soapenv:Envelope>
The easiest way to generate blank requests like the above is using SOAP UI. You just give the wsdl URL and it generates all possible requests for you. I copy and paste these over to JMeter.

How should I update a REST resource?

I'm not sure how I should go about updating individual properties of a REST resource. Consider the following example:
# HTTP GET to /users/1.xml
<?xml version="1.0" encoding="UTF-8" ?>
<response>
<user>
<id>1</id>
<name>John Doe</name>
<email>john#doe.com</email>
</user>
</response>
How should I facilitate for updating John's email? HTTP PUT comes to mind, but I'd be making it hard on my clients by requiring a complete XML (matching the HTTP GET response) to modify the resource.
The PUT method requests that the
enclosed entity be stored under the
supplied Request-URI. If the
Request-URI refers to an already
existing resource, the enclosed entity
SHOULD be considered as a modified
version of the one residing on the
origin server.
Is there any other way?
If your server framework is flexible enough to handle it, you can do:
Request:
PUT /users/1/email
Content-Type: text/plain
john#newemail.com
Response:
200 OK
Content-Location: /users/1
By using a URL to refer to the email as its own resource, you can PUT directly to it using a simple format like text/plain. In the response, the Content-Location url gives the client an indication that the change has had an impact on the user resource.
The PATCH method is also another way that you can do partial updates. This is a newly introduced method and as yet there are no standard formats for sending XML diff documents. So, if you take this approach you will not find much guidance.
The other thing to consider is that REST works best with large grained updates. If you find yourself needing to make these kinds of small changes, then maybe you need to rethink your distributed architecture.

IIS6 - How do I redirect users to another site for every page with a few exceptions?

I have a website setup in IIS 6, let's say it's called http://www.this.com.
I have setup a redirection for this website to http://www.that.com which maintains the directory structure and query parameters as follows:
http://www.that.com$S$Q - using the option "The exact URL entered above"
This works great, whenever someone requests, for example:
http://www.this.com/subfolder/page.aspx?Id=1
then they end up at:
http://www.that.com/subfolder/page.aspx?Id=1
Now, I have one page, actually a handler, http://www.this.com/image.axd, which I do not want to redirect.
What is the syntax for that? I've read the Redirection Using Wildcards section here, but I can't work out how to do what seems to be something straight forward.
Note that image.axd is a handler so I can't just "right click" on it and set the redirection properties as it doesn't physically exist.
I also have a couple of other pages in subfolders which I do not want to redirect, for example:
http://www.this.com/subfolder/donotredirectthispage.aspx
Any help would be appreciated.
Edit: A couple of people have mentioned using ISAPI_Rewrite, for which I'm grateful, but I really don't want to introduce another complexity into the website configuration. IIS seems to imply I can acheive what I want using the ! and 0 through 9 variables.
Is it really not possible to do this using IIS?
My current workaround is to set the redirection properties on ALL folders and pages that I want to redirect except those I do not, but this is a management nightmare.
You could implement a custom error page for the page not found error (404) that does the redirection for you. You'd turn off the redirection in IIS. Build the logic for the redirection in your custom error page. Then configure your web site so that 404 errors redirect to your error page.
If you can install software on your IIS server, I'd recommend using a tool to rewrite your request URLs.
For IIS 6.0 I've used ISAPI_Rewrite and it works really well. It's lightweight and very configurable. There's a "Lite" version available for free and will support your requirements.
You configure the program using a text file containing rules that match HTTP requests and then write actions to perform once a rule is matched. Your instance would probably require a general redirect rule (similar to the one in IIS) and rules for your exceptions.
You should look into the possibility of using a header rewrite module, for example ISAPI_rewrite. There is a free "lite" version available that is enough for your needs.
What this can do for you is the following: Before actual pages are executed on the server, the Request headers are rewritten (or HTTP 301/302 redirects are issued) based on a configurable set of rules. The underlying server sees the remaining requests as if the client really made them in that fashion.
The following rules would leave image.axd requests alone, while redirecting everything else.
# image.axd stays unchanged ("L" is the "last rule" flag)
RewriteCond Host: www.\this\.com
RewriteRule ^.*?\bimage\.axd\b.* $0 [L]
# all requests that have not been stopped by an earlier rule
# end up here ("RP" is the "permanent redirect" flag)
RewriteCond Host: www.\this\.com
RewriteRule .* http://www.that.com$0 [RP,L]