Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/253756-php-javabridgefatal-error-invoke-failed/
Share on other sites

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);
?>	

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.