on 08-11-2009 5:52 PM
Hello,
I have a scenario where a message should be sent to an HTTP server using the HTTP receiver CC. In the message itself no special HTML characters such as <, > or / should be used but they should be replaced with special character entities such as < for < .
Is there an easy way to do this as it is quite a common requirement? Is there an adapter module available for this or must this be done in the mapping itself?
Thank you for your advice.
Edited by: Florian Guppenberger on Aug 11, 2009 6:54 PM
Edited by: Florian Guppenberger on Aug 11, 2009 6:55 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I also checked the link to the other trhead. So obviously the conversion to HTML character entities, just like < has to be done using a Java mapping.
Is there any sample code available? I think this is a common feature and there should be some kind of java template available.
This would be very helpful.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
try{
int c;
while ((c = in.read()) != -1) {
switch (c){
case '&': out.write("&".getBytes()); break;
case '\"': out.write(""".getBytes()); break;
case '\'': out.write("'".getBytes()); break;
case '<': out.write("<".getBytes()); break;
case '>': out.write(">".getBytes()); break;
default: out.write(c);
}
}
} catch (IOException e) {
throw new StreamTransformationException(e.getMessage());
}
}
If that works for you, you can put this to wiki
> public void execute(InputStream in, OutputStream out)
> throws StreamTransformationException {
> try{
> int c;
> while ((c = in.read()) != -1) {
> switch (c){
> case '&': out.write("& ;".getBytes()); break;
> case '<': out.write("< ;".getBytes()); break;
> case '>': out.write("> ;".getBytes()); break;
> default: out.write(c);
> }
>
> }
> } catch (IOException e) {
> throw new StreamTransformationException(e.getMessage());
> }
>
>
> }
The SDN forum does not allow html escape sequences, so I put a space before the ; which you have to remove in your code.
' and " need not to be escaped, so I removed that lines.
Edited by: Stefan Grube on Aug 16, 2009 11:06 PM
Thank you for the code sample! What I was just thinking about is, that this should be done automatically when receiving the proxy, shouldn't it?
Otherwise it would not be valid XML on the integration server I guess.
And how would the code distinguish between "real" XML tags and content of elements? We will make a test and I let you know about the outcome.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
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.