on 07-28-2006 9:49 AM
hello,
we have a LinkToURL element, wherein we have the following reference:
mailto:x@y.com?subject=PO Number:4500000010 Material Number:00001
of course this doesnt work because it needs to be escaped to the following:
mailto:x@y.com?subject=PO%20Number:4500000010%20Material%20Number:00001
how does one do the escaping in WebDynpro ? We couldnt find a relevant method in backend ABAP (the cl_http_utility) methods do not escape the string.
thanks and regards,
parag.
Hi,
@Armin,URLEncoder encodes spaces as "+". I don't think the subject line will appear as needed.
But maybe you can do something like this:
String urlString = URLEncoder.encode("po number:4500000010 material number:00001");
String finalURL = "mailto:x@y.com?subject=" + urlString.replaceAll("[+]","%20");
wdComponentAPI.getMessageManager().reportSuccess(finalURL);
Regards,
Satyajit.
Message was edited by: Satyajit Chakraborty
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good point!
Just check it via placing the following in browser location bar:
javascript:void( window.open("mailto:bgates@microsoft.com?subject=RegardingInternetExplorer", "_blank") )
Both IE & Firefox opens new message with incorrect subject line.
However, the following work correctly:
javascript:void( window.open("mailto:bgates@microsoft.com?subject=Regarding%20Internet%20Explorer", "_blank") );
So in fact you need to encode parameter with URLEncoder and then call paramStr.replaceAll("+", "%20");
It should be safe enough while any "" that really means "" are encode by URLEncoder.
VS
I think you all missed the point. Its not about space.
Lets assume there are other characters in the string. How do we escape those characters ? We cannot be doing a replaceAll for all special characters that are possible (+, -, #, etc).
What you are suggesting is URL esacping and this is not the solution. The ABAP CL_HTTP_UTILITY method ESACPE_URL also does the same.
Is there a generic way to escape such a string which can have any special characters ?
Regards, Parag.
Parag,
What I have suggested is only for the space character. That is because, if you go through the javadocs for URLEncoder you will find this:
+When encoding a String, the following rules apply:
The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same.
The special characters ".", "-", "*", and "_" remain the same.
The space character " " is converted into a plus sign "+".
All other characters are unsafe and are first converted into one or more bytes using some encoding scheme. Then each byte is represented by the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the byte. The recommended encoding scheme to use is UTF-8. However, for compatibility reasons, if an encoding is not specified, then the default encoding of the platform is used.
For example using UTF-8 as the encoding scheme the string "The string ü@foo-bar" would get converted to "Thestring%C3%BC%40foo-bar"+
So you see, the probability of too many unsafe characters remaining in your URL string is low. They will all be encoded according to the following rule.
If you are still not convinced, can you cite an example where you think this will fail?
Regards,
Satyajit.
Oops! Looks like i touched a wrong chord.
What I meant about ABAP part is that there are two ways to do it. The first option is to do it in the backend in ABAP using the class i had mentioned and second one is to do it in WebDynpro (Java). The ABAP utility is also a URL encoder and functions the same way as the method you guys have mentioned.
The issue is with the LinkToURL element of WD. Lets take another example. I would like to have the following mailto link:
mailto:x@y.com?subject=PO Number:4500000010 Material Number:SS-HALB1
According to what Satyajit has reproduced, the character "-" doesnt need special encoding and the following should work.
mailto:x@y.com?subject=PO%20Number:4500000010%20Material%20Number:SS-HALB1
You are absolultely right that the browser understands this encoding and handles it correctly. Unfortunately, the WD element doesnt like the hypen and dumps at runtime.
If i give the following mailto, WD is happy.
mailto:x@y.com?subject=PO%20Number:4500000010%20Material%20Number:SS%2DHALB1
Note that i had to give %2D instead of hypen.
Now, the question again is, how can i convert all special characters like hypen, asterix, and so on to ensure that WD doesnt dump.
Regards,
Parag.
P.S: I am using NSP, with SP16.
WD Runtime Exception.
com.sap.tc.webdynpro.services.exceptions.InvalidUrlRuntimeException: Invalid URL=mailto:x@y.com?subject=PO%20Number:4500000010%20Material%20Number:
at com.sap.tc.webdynpro.serverimpl.core.url.AbstractURLGenerator.checkURL(AbstractURLGenerator.java:601)
at com.sap.tc.webdynpro.services.sal.url.core.URLGeneratorInternal.checkURL(URLGeneratorInternal.java:303)
at com.sap.tc.webdynpro.clientserver.uielib.standard.impl.LinkToURL.getReference(LinkToURL.java:221)
at com.sap.tc.webdynpro.clientimpl.html.uielib.standard.uradapter.LinkToURLAdapter.getReference(LinkToURLAdapter.java:235)
at com.sap.tc.webdynpro.clientimpl.html.renderer.uielements.ie6.LinkRenderer.render(LinkRenderer.java:45)
Yes, you are right, my mistake, I thought "mailto:" would be forbidden by default (in fact, it was forbidden when URL checker had been introduced, I stumbled over that in a sample app).
So you should probably complain (open an OSS message) about the URL checking algorithm, if your URL is valid and the checker throws an exception.
Armin
Hi,
If you are using the URLEncoder class, you will need to take care of five characters really. These are ".", "-", "*", "_" and "space" of course. That's because URLEncoder doesn't encode these.
So the choice is really upto you whether you want to go ahead with URLEncoder and do a replaceAll() for these 5 characters.
Regards,
Satyajit.
See java.net.URLEncoder.
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.