HI All,
I am constructing page url from the below lines of code and displaying in mail template but it has broken displaying in the mail template.
Construction of page in service:
final String pagepath = externalizer.authorLink(resourceResolver, payload);
Mail template(output):
Hi ContentReviewer,
This page/document http://100.66.0.19:4502/content/dam/briggs/documents/Copy of AEM defects - Priority.xlsx has been required approval to publish.
Please check the inbox to complete the task.
http://100.66.0.19:4502/inbox
Regards,
Your local friendly CQ5 Admin
Construction of page in service:
final String pagepath = externalizer.authorLink(resourceResolver, payload);
Can please some one help me to how to fix this issue.
Thanks in advance.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi
As mentioned by Kunal, you need to encode names before using it.
Example :-
Option 1:-
URL :-http://example.com/query?q= random word £500 bank $
It should be encoded to :- http://example.com/query?q=random%20word%20%A3500%20bank%20%24
URLEncoder should be the way to go. You only need to keep in mind to encode only the individual query string parameter name and/or value, not the entire URL, for sure not the query string parameter separator character & nor the parameter name-value separator character =.
String q = "random word £500 bank $";
String url = "http://example.com/query?q=" + URLEncoder.encode(q, "UTF-8");
Option 2:-
Use of Java.net.URI Class
The java.net.URI class can help; in the documentation of URL you find
Note, the URI class does perform escaping of its component fields in certain circumstances. The recommended way to manage the encoding and decoding of URLs is to use an URI
Use one of the constructors with more than one argument, like:
URI uri = new URI(
"http",
"search.barnesandnoble.com",
"/booksearch/first book.pdf",
null);
URL url = uri.toURL();
//or String request = uri.toString();
Some Reference Links:-
1. http://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters
2. http://stackoverflow.com/questions/724043/http-url-address-encoding-in-java
3. http://www.mkyong.com/java/how-to-encode-a-url-string-or-form-parameter-in-java/
4. http://www.java2novice.com/java_networking/url_encode/
I hope this would help you.
Thanks and Regards
Kautuk Sahni
Views
Replies
Total Likes
Views
Replies
Total Likes
You should encode the page name before using it in the URL. Check the following link - http://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters
Views
Replies
Total Likes
Hi
As mentioned by Kunal, you need to encode names before using it.
Example :-
Option 1:-
URL :-http://example.com/query?q= random word £500 bank $
It should be encoded to :- http://example.com/query?q=random%20word%20%A3500%20bank%20%24
URLEncoder should be the way to go. You only need to keep in mind to encode only the individual query string parameter name and/or value, not the entire URL, for sure not the query string parameter separator character & nor the parameter name-value separator character =.
String q = "random word £500 bank $";
String url = "http://example.com/query?q=" + URLEncoder.encode(q, "UTF-8");
Option 2:-
Use of Java.net.URI Class
The java.net.URI class can help; in the documentation of URL you find
Note, the URI class does perform escaping of its component fields in certain circumstances. The recommended way to manage the encoding and decoding of URLs is to use an URI
Use one of the constructors with more than one argument, like:
URI uri = new URI(
"http",
"search.barnesandnoble.com",
"/booksearch/first book.pdf",
null);
URL url = uri.toURL();
//or String request = uri.toString();
Some Reference Links:-
1. http://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters
2. http://stackoverflow.com/questions/724043/http-url-address-encoding-in-java
3. http://www.mkyong.com/java/how-to-encode-a-url-string-or-form-parameter-in-java/
4. http://www.java2novice.com/java_networking/url_encode/
I hope this would help you.
Thanks and Regards
Kautuk Sahni
Views
Replies
Total Likes
what are you getting when you directly hitting the URL i.e.
http://100.66.0.19:4502/content/dam/briggs/documents/Copy of AEM defects - Priority.xlsx
is it resolving or throwing any error.
Thanks,
Kishore
Views
Replies
Total Likes
@Kishor,
It should work because browser encode the URL and matches the resource. It won't throw any exception if such file exists. Link is not formed correctly because of the name of the file.
Kishore@CQ wrote...
what are you getting when youdirectly hitting the URL i.e.
http://100.66.0.19:4502/content/dam/briggs/documents/Copy of AEM defects - Priority.xlsx
is it resolving or throwing any error.
Thanks,
Kishore
Views
Replies
Total Likes
@Tomar
Might work but want to know before suggesting further on this issue.
Views
Replies
Total Likes
Hi All,
Thanks for help and option is working fine but take the url using URIobj.toASCIIString().
URL url= new URL("url");
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
String finalpage=uri.toASCIIString();
Thanks,
Venkatesham
Views
Replies
Total Likes