Author |
Message
|
Jenum |
Posted: Mon Feb 18, 2013 8:05 am Post subject: XSL, xalan and base64 in WebSphere MessageBroker 7 |
|
|
Novice
Joined: 13 Nov 2012 Posts: 24
|
Good evening!
Firstly, I want to sorry for my english, because it is not my home language and this is terrible
I have some trouble while develop on message broker:
I need to transform base64-data by xslt (xsl-file). I create next files:
Encode.xsl:
Code: |
<xsl:stylesheet version="1.0"
xmlns:xsl="http : //www . w3 . org/1999/XSL/Transform"
xmlns:xalan="http : //xml . apache . org/xalan"
xmlns:BASE64Encoder="xalan : //sun . misc . BASE64Encoder"
xmlns:jString="xalan : //java . lang . String">
<xsl:template match="/">
<xsl:variable name="encoder" select="BASE64Encoder:new()" />
<xsl:variable name="byte_array" select="jString:getBytes(string(./root/a))" />
<xsl:variable name="str" select="BASE64Encoder:encodeBuffer($byte_array)" />
<root>
<b>
<xsl:value-of select="/root/a"/> =
<xsl:value-of select="$str"/>
</b>
</root>
</xsl:template>
</xsl:stylesheet> |
Decode.xsl:
Code: |
<xsl:stylesheet version="1.0"
xmlns:xsl="http : //www . w3 . org/1999/XSL/Transform"
xmlns:xalan="http : //xml . apache . org/xalan"
xmlns:BASE64Decoder="xalan : //sun . misc.BASE64Decoder"
xmlns:jString="xalan : //java . lang . String">
<xsl:template match="/">
<xsl:variable name="decoder" select="BASE64Decoder:new()" />
<xsl:variable name="b64" select="BASE64Decoder:decodeBuffer($decoder, string(./root/a))" />
<xsl:variable name="str" select="jString:new($b64)" />
<root>
<b>
<xsl:value-of select="/root/a"/> =
<xsl:value-of select="$str"/>
</b>
</root>
</xsl:template>
</xsl:stylesheet> |
If i use xalan-transform by xalan.jar
Code: |
%ProgramFiles%\IBM\SDPShared\plugins\com.ibm.ccl.xtt.xslt4j_2.7.14.v20101106_0116\lib\xalan.jar -IN test.xml -XSL TS.xsl -OUT result.xml |
then it have not errors and it is working. But if i use this xsl-files in message broker by xsl transform node it have some error:
"stylesheet does not found" or "error while compiling xsl". Ofcourse, Xsl-files deploying on the same group with message flow.
Please, say me: why this error is occure?
And how i can to transform base64-data by xslt?..
Thank you! |
|
Back to top |
|
 |
lancelotlinc |
Posted: Mon Feb 18, 2013 8:10 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
|
Back to top |
|
 |
kimbert |
Posted: Mon Feb 18, 2013 8:49 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
So you are using an XSL stylesheet to decode base64 data?
There is a much easier way to do that. You can use a Compute node and call the BASE64DECODE function. Or use a JavaCompute node and use a Java library for base64 processing. |
|
Back to top |
|
 |
Jenum |
Posted: Mon Feb 18, 2013 8:13 pm Post subject: |
|
|
Novice
Joined: 13 Nov 2012 Posts: 24
|
Ofcourse, it is easier. But it is external service for format transformation and i can not modify that. I only can add my xsl-files
Extra question:
Xalan-xslt allow to invoke java-class methods. So message broker uses xalan engine, can i use this features? I try to do that in my example, but it isn't work... May be, i do something wrong? |
|
Back to top |
|
 |
kimbert |
Posted: Tue Feb 19, 2013 12:37 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
But it is external service for format transformation and i can not modify that. I only can add my xsl-files |
Sorry - I cannot agree with that. You are the author of this message flow. You can decide how you solve the problem. If the message flow correctly transforms the input file then the service consumer will not care about the internals.
Quote: |
Xalan-xslt allow to invoke java-class methods. So message broker uses xalan engine, can i use this features? I try to do that in my example, but it isn't work... May be, i do something wrong? |
Your organisation has purchased WebSphere Message Broker, not WebSphere Application Server. Message Broker is not an application server - it is a message broker. You need to use the product in the correct way, otherwise the investment in WMB will not be fully realised.
Apart from that ( very important ) point, if you are allowed to invoke Java code from your stylesheet then why can you not invoke a base64 Java library from a JavaCompute node? |
|
Back to top |
|
 |
Jenum |
Posted: Wed Feb 20, 2013 7:57 am Post subject: |
|
|
Novice
Joined: 13 Nov 2012 Posts: 24
|
Quote: |
You are the author of this message flow. |
Unfortunately, i am not author of this message flow: there are only thing that i can do with this - deploy my xslt template.
Quote: |
Your organisation has purchased WebSphere Message Broker, not WebSphere Application Server. Message Broker is not an application server - it is a message broker. You need to use the product in the correct way, otherwise the investment in WMB will not be fully realised. |
I can own up - i don't understand this if you show me articles - i will read it with pleasure. My language level doesn't allow me discuss it with you now
Quote: |
Apart from that ( very important ) point, if you are allowed to invoke Java code from your stylesheet then why can you not invoke a base64 Java library from a JavaCompute node? |
I answered this above.
About my problem:
I searched mistake in xslt:
Code: |
<xsl:variable name="byte_array" select="jString:getBytes(string(./root/a))" /> |
XSLT String not equal java.lang.String. Moreover, ANY expression, which result in java.lang.String, automatic transform to XSLT String. So, i have error, that method "getBytes" required first argument as reference to java.lang.String object, but it have only XSLT String. Another way have same error:
Code: |
<xsl:variable name="s" select="jString:new(string(./root/a))" />
<xsl:variable name="byte_array" select="jString:getBytes($s)" /> |
And i have another question:
how i must deploy my java class and xslt-template to invoke method from my java-class in xslt-template?..
Another question:
Can i use xalan-features to write code in javascript in xslt (like this: http://xml.apache.org/xalan-j/extensions.html#basic-pattern)?.. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Feb 20, 2013 9:22 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Jenum wrote: |
Unfortunately, i am not author of this message flow: there are only thing that i can do with this - deploy my xslt template. |
So your position is that you are producing an XSLT sheet which will be placed in an existing WMB flow which will consume it and process it?
- Your original assertion that you are "developing on message broker" is false. You're developing XSLT with no WMB component except:
- Your organisation (if you're correct) is using WMB as an XSLT engine. This is a serious waste of the products capabilities and the organisation's money. You can process XSLT sheets for a fraction of what WMB costs.
You may want to mention this to your management so they can sack whoever wrote that flow for wasting so much money.
Jenum wrote: |
how i must deploy my java class and xslt-template to invoke method from my java-class in xslt-template?.. |
Ask whoever did author the flow how they've achieved that. It's implementation specific because you're not using the product the way any of us understand.
Another question for the flow's real author, for the reason I gave above. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
kimbert |
Posted: Wed Feb 20, 2013 9:40 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
OK - sorry for making an assumption there. We get a lot of message flow authors on this forum who have to follow a set of programming guidelines. I assumed that you were one of those.
So you are not modifying a message flow - you are just configuring the message flow by deploying an XSLT template. Your XSLT template needs to call out to some Java to perform the base64 decode. You cannot find a way to make the XSLT node use the deployed Java class.
At this point, I have to be honest - I don't know the answer.
Maybe somebody else can help? |
|
Back to top |
|
 |
goffinf |
Posted: Sun Feb 24, 2013 11:13 am Post subject: |
|
|
Chevalier
Joined: 05 Nov 2005 Posts: 401
|
kimbert wrote: |
.... Your XSLT template needs to call out to some Java to perform the base64 decode. You cannot find a way to make the XSLT node use the deployed Java class.
At this point, I have to be honest - I don't know the answer.
Maybe somebody else can help? |
Xalan supports the use of extension functions. These are Java methods that you define, typically as static (that's not an absolute requirement but usually the best way to go). Here's a DevWorks article that should get you started.
http://www.ibm.com/developerworks/xml/library/x-xalanextensions/index.html
If you want to play with the Message Broker message tree or global/local environments, then I would recommend writing a simple URI resolver. These are pretty easy too.
HTHs
Fraser. |
|
Back to top |
|
 |
|