phpcodder Posted December 23, 2011 Share Posted December 23, 2011 Hi , I am tring to call user define function of java which parse xsl & xml and executing it using php but it is giving me following error. Versions i am using JDK 1.5,Php 5.3,JavaBridge. Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: Invoke failed: [[o:PhpJBridge]]->XMLXSL((o:String)[o:String], (o:String)[o:String]). Cause: javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet VM: 1.5.0_18@http://java.sun.com/" at: #-12 com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(Unknown Source) #-11 com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(Unknown Source) #-10 PhpJBridge.XMLXSL(SaxonTest.java:88) #-9 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) #-8 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) #-7 sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) #-6 java.lang.reflect.Method.invoke(Unknown Source) #-5 php.java.bridge.JavaBridge.Invoke(JavaBridge.java:1049) #-4 php.java.bridge.Request.handleRequest(Request.java:415) #-3 php.java.bridge.Request.handleRequests(Request.java:491) #-2 php.java.bridge.http.ContextRunner.run(ContextRunner.java:145) #-1 p in http://localhost:8080/EchoServer/java/Java.inc on line 117 Quote Link to comment https://forums.phpfreaks.com/topic/253756-php-javabridgefatal-error-invoke-failed/ Share on other sites More sharing options...
Maq Posted December 23, 2011 Share Posted December 23, 2011 Looks like your XSL sheet is invalid. Open it in an IDE to make sure there are no errors or post it here and we'll take a look. Quote Link to comment https://forums.phpfreaks.com/topic/253756-php-javabridgefatal-error-invoke-failed/#findComment-1300877 Share on other sites More sharing options...
phpcodder Posted December 23, 2011 Author Share Posted December 23, 2011 It is working fine when i am calling it on CLI , but when i am calling it from php at the same time it gives me error.Here is the code snippet. PhpJBridge.java import net.sf.saxon.*; import net.sf.saxon.lib.FeatureKeys; import net.sf.saxon.lib.OutputURIResolver; import net.sf.saxon.dom.NodeOverNodeInfo; import net.sf.saxon.om.Axis; import net.sf.saxon.om.DocumentInfo; import net.sf.saxon.om.NodeInfo; import net.sf.saxon.pattern.NodeKindTest; import net.sf.saxon.sxpath.XPathExpression; import net.sf.saxon.tree.tiny.TinyBuilder; import net.sf.saxon.xpath.XPathEvaluator; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.xml.sax.*; import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.XMLFilterImpl; import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.sax.SAXResult; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import java.net.URL; import java.util.Properties; import java.io.*; import org.xml.sax.SAXException; public class PhpJBridge{ public static void main(String argv[]) {} public static void XMLXSL(String sourceID, String xslID) throws TransformerException { // Create a transform factory instance. TransformerFactory tfactory = TransformerFactory.newInstance(); // Create a transformer for the stylesheet. Transformer transformer = tfactory.newTransformer(new StreamSource(xslID)); // Transform the source XML to System.out. StreamResult sr = new StreamResult(new File("C:/result.xml")); transformer.transform(new StreamSource(sourceID), sr); } public static void callhello() { System.out.println("In"); } private static void handleException(Exception ex) { System.out.println("EXCEPTION: " + ex); ex.printStackTrace(); if (ex instanceof TransformerConfigurationException) { System.out.println(); System.out.println("Test failed"); Throwable ex1 = ((TransformerConfigurationException) ex).getException(); if (ex1!=null) { ex1.printStackTrace(); if (ex1 instanceof SAXException) { Exception ex2 = ((SAXException) ex1).getException(); System.out.println("Internal sub-exception: "); ex2.printStackTrace(); } } } } } PhpJB.php <?php require_once("http://localhost:8080/EchoServer/java/Java.inc"); $axml="books.xml"; $axsl="books.xsl"; exec("javac PhpJBridge.java"); exec("jar cvf PhpJBridge.jar PhpJBridge.class"); java_require(PhpJBridge.jar'); $saz= new java("PhpJBridge"); echo (String)$saz->XMLXSL$axsl); ?> Quote Link to comment https://forums.phpfreaks.com/topic/253756-php-javabridgefatal-error-invoke-failed/#findComment-1300889 Share on other sites More sharing options...
Maq Posted December 23, 2011 Share Posted December 23, 2011 Is this a mistype? You're missing the first single quote: java_require(PhpJBridge.jar'); And I think this line should be: echo (String)($saz->XMLXSL$axsl); Quote Link to comment https://forums.phpfreaks.com/topic/253756-php-javabridgefatal-error-invoke-failed/#findComment-1300903 Share on other sites More sharing options...
phpcodder Posted December 23, 2011 Author Share Posted December 23, 2011 Thanks but java_require('PhpJBridge.jar'); was a typing mistake. at this line -> echo (String)($saz->XMLXSL$axsl); i have to pass two arguments to java function Quote Link to comment https://forums.phpfreaks.com/topic/253756-php-javabridgefatal-error-invoke-failed/#findComment-1300911 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.