tag:blogger.com,1999:blog-34020393.post2420523687336006608..comments2024-03-27T10:59:38.307-07:00Comments on Jim's PeopleSoft Journal: Using XQuery with PeopleSoftJim Marionhttp://www.blogger.com/profile/12995110203807924786noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-34020393.post-29903616828118554292013-09-25T06:30:25.235-07:002013-09-25T06:30:25.235-07:00No problem. You share so much with all of us, I f...No problem. You share so much with all of us, I feel obligated to share something every couple of years at least :).Jarod Merlehttps://www.blogger.com/profile/06363331883108943615noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-21934066780141652832013-09-24T15:07:55.148-07:002013-09-24T15:07:55.148-07:00Nice! Thanks for sharing!!Nice! Thanks for sharing!!Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-19894537726231125012013-09-24T10:40:32.709-07:002013-09-24T10:40:32.709-07:00Jim, you saved the day for me again :). From your...Jim, you saved the day for me again :). From your comments here regarding how to cast a Java Object to a different type in PeopleCode, I was able to successfully write code to hit a URL to retrieve employee photos and load them into the PS database. If you're interested in what I did, I posted it on stackoverflow, where I'd ask a Java question. I didn't get an answer so I answered it myself for the sake of documentation:<br /><br />http://stackoverflow.com/questions/18921658/retrieve-image-from-ashx-url-using-java-in-peoplesoft-peoplecode/18988293#18988293Jarod Merlehttps://www.blogger.com/profile/06363331883108943615noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-7666275117119876572009-04-03T12:23:00.000-07:002009-04-03T12:23:00.000-07:00Hi Jim,Thanks for your reply. I did have a look at...Hi Jim,<BR/><BR/>Thanks for your reply. I did have a look at that post, but I'm unable to figure why it still fails with that error.<BR/>The error Text - Java Exception: java.lang.NoSuchMethodException:<BR/>com.peoplesoft.pt.tokengenerator.internal.PeopleSoftTokenGenerator.generateToken(com.peoplesoft.pt.tokengenerator.internal.PeopleSoftTokenGenerator);<BR/>during call of java.lang.getDeclaredMethod.<BR/><BR/>Thanks for helping me out with this.<BR/><BR/>Thanks!<BR/>PrashantCiphersbakhttps://www.blogger.com/profile/01586158446874473262noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-9260381359099090222009-03-31T21:01:00.000-07:002009-03-31T21:01:00.000-07:00@Prashant, your code looks good to me. What errors...@Prashant, your code looks good to me. What errors are you getting? Take a look at Chris Heller's post <A HREF="http://blog.greysparling.com/2006/08/java-and-peoplecode-tips-and-tricks.html" REL="nofollow">Java and PeopleCode Tips and Tricks - Part 3</A>. Chris's example is the best I've seen on PeopleCode Java Reflection.Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-4365219191711049942009-03-27T01:07:00.000-07:002009-03-27T01:07:00.000-07:00Hi Jim,Need your help to solve this one. i was gng...Hi Jim,<BR/><BR/>Need your help to solve this one. i was gng thru ur blogs for Reflection, but I cant figure out what needs to be done here...<BR/><BR/>&jClass = GetJavaClass("java.lang.Class");<BR/>Local JavaObject &tokenPS_ = CreateJavaObject("com.peoplesoft.pt.tokengenerator.internal.PeopleSoftTokenGenerator");<BR/>Local JavaObject &jReadArgTypes = CreateJavaObject("java.lang.Class[]", GetJavaClass("com.peoplesoft.pt.tokengenerator.internal.PeopleSoftTokenGenerator"));<BR/>Local JavaObject &jReadMethod = &tokenPS_.getClass().getDeclaredMethod("generateToken", &jReadArgTypes);<BR/> Local JavaObject &jReadArgs = CreateJavaObject("java.lang.Object[]", CreateJavaObject("com.peoplesoft.pt.tokengenerator.internal.PeopleSoftTokenGenerator", &targetSTR));<BR/>Local JavaObject &jBufImage = &jReadMethod.invoke(&tokenPS_, &jReadArgs);<BR/><BR/>Thanks for your help<BR/>PrashantCiphersbakhttps://www.blogger.com/profile/01586158446874473262noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-38328588385599796322008-09-12T10:56:00.000-07:002008-09-12T10:56:00.000-07:00@HH, "how to use type casting in Peoplecode.....@HH, "how to use type casting in Peoplecode... It appears that one cannot cast objects."<BR/><BR/>You are right. You can't. Notice that I used reflection with the &jExp object to execute the "run" method. That is because the prior call to "invoke" returns an Object. Once a Java object reference becomes an Object, the only way to call its methods is through reflection. Yes, this is a pain. As you already stated, you have 2 options:<BR/><BR/>1. Create wrappers/helpers<BR/>2. Use reflection<BR/><BR/>I think creating wrappers is easiest and cleanest. You don't need to modify the delivered API. You just need a class with a static method like<BR/><BR/>public static XXX objectToXXX(Object o){<BR/>if (o instanceof XXX) {<BR/>return (XXX) o;<BR/>} else {<BR/>return o;<BR/>}<BR/>}<BR/><BR/>This is basically, a static cast method.<BR/><BR/>Chris Heller just wrote a post on Casting and PeopleCode: <A HREF="http://blog.greysparling.com/2008/07/casting-java-objects-in-peoplecode.html" REL="nofollow">Casting Java objects in PeopleCode</A><BR/><BR/>If you need to revert to Java Reflection in PeopleCode, both Chris and I have examples. Here is a list of my posts that use reflection: <A HREF="http://jjmpsj.blogspot.com/search/label/Java%20Reflection" REL="nofollow">Java Reflection</A>.<BR/><BR/>I am sorry for the bad news. If you are a customer, I strongly encourage you to log into Customer Connection and put in a request for a PeopleCode Java cast method.Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-19828630994092939682008-09-11T23:03:00.000-07:002008-09-11T23:03:00.000-07:00Jim,My question is a little off topic but I am hop...Jim,<BR/><BR/>My question is a little off topic but I am hoping you can spare some time.<BR/><BR/>Can you please shed some light on how to use type casting in Peoplecode.<BR/><BR/>It appears that one cannot cast objects.<BR/><BR/>For e.g. if a method call returns a type of object but contains an instance of a class say ClassA.<BR/><BR/>In java, one can easily cast it like so<BR/> ( ClassA ) &ObjHndle<BR/><BR/>However, this does not work.<BR/><BR/>Another option would be to create a wrapper method in the class which casts the object handle to ClassA and return the ClassA object.<BR/><BR/>However, since we are talking about vendor delivered classes, we are looking for way simpler ways.<BR/><BR/>How can this be achieved ?HHhttps://www.blogger.com/profile/00055400658574605438noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-71828729828431707282008-07-31T07:38:00.000-07:002008-07-31T07:38:00.000-07:00@Andrew, yes the resulting page is supposed to hav...@Andrew, yes the resulting page is supposed to have HTML tags. The XQuery file converts RSS to HTML.<BR/><BR/>Thanks for the feedback! I am delighted that it worked for you.Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-49503789104173859772008-07-31T04:46:00.000-07:002008-07-31T04:46:00.000-07:00Hi Jim,How silly of me, I should have realised it ...Hi Jim,<BR/><BR/>How silly of me, I should have realised it was connecting to the internet! I added the proxy info in and it worked this time. <BR/><BR/>Although the page that was displayed had html tags in it. Perhpas the page had a problem writing the html?<BR/><BR/>Anyway it worked and I like how you can bring that in.<BR/><BR/>Thanks a lot.<BR/><BR/>AndrewAndrewhttps://www.blogger.com/profile/08987673876836931227noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-26457139211651664952008-07-30T08:54:00.000-07:002008-07-30T08:54:00.000-07:00@andrew, InvocationTargetException is thrown by th...@andrew, InvocationTargetException is thrown by the java.lang.reflect.Method.invoke method when the "invoked" method throws an Exception. Basically, this is just a wrapper around a different Exception. It appears that the <I>run</I> method of the <I>XQueryExpression</I> object threw an Exception. It would be great if we could see the Java nested exception, the cause of the InvocationTargetException. Unfortunately, I don't know how to extract the nested Java exception. Did you copy and paste the code from this post directly into a Record Field FieldFormula event? If so, the first thing I would check is your app server's proxy settings. Does your app server need to use a proxy server to connect to the internet? If so, make sure you have <B>Proxy Host</B> and <B>Proxy Port</B> defined in your psappsrv.cfg file.<BR/><BR/>If you look at the Saxon documentation, you will notice you can actually run an XQuery from the command line. Try running your XQuery from the command line. You will find the Saxon docs in the sourceforge download saxon-resources8-9.zip from <A HREF="http://sourceforge.net/project/showfiles.php?group_id=29872&package_id=21888" REL="nofollow">http://sourceforge.net/project/showfiles.php?group_id=29872&package_id=21888</A>. To run your XQuery from your app server's command line, run<BR/><BR/>%PS_HOME%\jre\bin\java -cp %PS_HOME%\class\saxon8.jar;%PS_HOME%\class\saxon8-xqj.jar c:\temp\rss2_html_obj.xq<BR/><BR/>Where c:\temp\rss2_html_obj.xq is a copy of the XQuery from my repository. Of course, if your app server is on Unix, then use $PS_HOME/, etc. If you run this and get an error, then you should be able to get a better understanding of the error that Saxon is throwing. Another way to debug this is to write a Java wrapper that takes an XQuery file as its only parameter. Then you could catch the Java Exception and log it to a file or place it in a field that you can check after calling the method. Actually, now that I think about it, rather than posting this ugly Java reflection code embedded in PeopleCode, I should have written a Java wrapper and posted that.<BR/><BR/>Try out these options and let me know what you find.Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-90276086403276584502008-07-30T04:26:00.000-07:002008-07-30T04:26:00.000-07:00Hi Jim,I was trying this out as I thought it might...Hi Jim,<BR/><BR/>I was trying this out as I thought it might be interesting to see how it works, what it does etc.<BR/><BR/>But when my iscript invokes the ExecXQuery function I get an error - ErrorReturn-> 763 - Java Exception: java.lang.reflect.InvocationTargetException: during call of java.lang.reflect.Method.invoke. (2,763) WEBLIB_CSS_SAXN.ISCRIPT1.FieldFormula Name:ExecXQuery PCPC:3291 Statement:27<BR/><BR/>Called from:WEBLIB_CSS_SAXN.ISCRIPT1.FieldFormula Name:IScript_ExecXQuery Statement:31<BR/><BR/>I traced the PeopleCode and it errors on <BR/>&jExpressionRunMethod.invoke(&jExp, CreateJavaObject("java.lang.Object[]", &jDynamicContext, &jStreamResult, &jOutputProperties));<BR/><BR/>Can I use this just directly from an iscript CREF? Or did I just not do everything. <BR/><BR/>I appended -Djavax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl to the JVM options. I have 8.48.09 installed.<BR/><BR/>Thanks,<BR/><BR/>AndrewAndrewhttps://www.blogger.com/profile/08987673876836931227noreply@blogger.com