[Solved] OOo 3.0.1: Bootstrap.bootstrap() problem

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
lenaz
Posts: 10
Joined: Thu May 07, 2009 9:19 am

[Solved] OOo 3.0.1: Bootstrap.bootstrap() problem

Post by lenaz »

Hi there!

I know, the bootstrap-method-problems are discussed very often, but I have not found a solution for my problem.

following situation:
we have a web-application, implemented as JSPs on a JETTY-Server (Win XP)(Linux should be supported too)
install-path of OOo 3: C:/fsales/OpenOffice.org3/ (without blank!)

a part of the jetty - configfile:

Code: Select all

wrapper.java.classpath.12=C:/fsales/OpenOffice.org3/URE/java/jurt.jar
wrapper.java.classpath.13=C:/fsales/OpenOffice.org3/Basis/program/classes/unoil.jar
wrapper.java.classpath.14=C:/fsales/OpenOffice.org3/URE/java/ridl.jar
wrapper.java.classpath.15=C:/fsales/OpenOffice.org3/URE/java/juh.jar
wrapper.java.classpath.16=C:/fsales/OpenOffice.org3/URE/java/bootstrapconnector.jar
wrapper.java.classpath.17=C:/fsales/OpenOffice.org3/program  //prevents the "no executable found!"-exception
now, the OOo - API is used in JSP-Files ... it worked perfectly with OOo 2, but with OOo 3, there comes this NoConnectException:

Code: Select all

INFO   | jvm 1    | 2009/05/06 17:19:07 | com.sun.star.comp.helper.BootstrapException: com.sun.star.connection.NoConnectException
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at com.sun.star.comp.helper.Bootstrap.bootstrap(Bootstrap.java:297)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.apache.jsp.oo_005fintegration_005fvon_005fkunde_005ffill_005fcreate_jsp._jspService(org.apache.jsp.oo_005fintegration_005fvon_005fkunde_005ffill_005fcreate_jsp:270)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:491)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:367)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:185)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:689)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:391)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.servlet.Dispatcher.include(Dispatcher.java:192)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.apache.jsp.oo_005fintegration_005fvon_005fkunde_005ffill_jsp._jspService(org.apache.jsp.oo_005fintegration_005fvon_005fkunde_005ffill_jsp:182)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:491)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1074)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:170)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1065)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1065)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:365)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:185)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:689)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:391)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:146)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.Server.handle(Server.java:285)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:457)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:751)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:500)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:209)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:357)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:329)
INFO   | jvm 1    | 2009/05/06 17:19:07 | 	at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:475)
thrown by the following statement:

Code: Select all

mxRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
following JSP-File fills an OOo Draft with data from a database and converts it to PDF
as said: it worked with OOo 2
here the lines of code (concerning OOo) of this JSP

Code: Select all

<%@page import="com.sun.star.awt.Point"%>
<%@page import="com.sun.star.awt.Size"%>
<%@page import="com.sun.star.awt.FontWeight"%>
<%@page import="com.sun.star.beans.PropertyState"%>
<%@page import="com.sun.star.beans.PropertyValue"%>
<%@page import="com.sun.star.beans.XPropertySet"%>
<%@page import="com.sun.star.beans.XPropertyState"%>
<%@page import="com.sun.star.bridge.XUnoUrlResolver"%>
<%@page import="com.sun.star.comp.servicemanager.ServiceManager"%>
<%@page import="com.sun.star.connection.*"%>
<%@page import="com.sun.star.frame.*"%>
<%@page import="com.sun.star.container.*"%>
<%@page import="com.sun.star.drawing.*"%>
<%@page import="com.sun.star.lang.*"%>
<%@page import="com.sun.star.style.*"%>
<%@page import="com.sun.star.table.XCell"%>
<%@page import="com.sun.star.text.*"%>
<%@page import="com.sun.star.uno.*"%>
<%@page import="com.sun.star.util.XRefreshable"%>
<%@page import="com.sun.star.view.XPrintable"%>

<%
System.out.println("Start opening Office-Connection");
try {
    XComponentContext mxRemoteContext = null;
    XMultiComponentFactory mxRemoteServiceManager = null;
    System.out.println("Create Hashtable with DataBaseComponents");
       Hashtable recipient = new Hashtable();
       /* filling hashtable .... */

System.out.println("Hashtable created");
        // load template with User fields and bookmark
	     
        java.io.File sourceFile = new java.io.File(application.getRealPath("/") +"/oo_vorlagen/kunde/" + request.getParameter("file"));
        StringBuffer sTemplateFileUrl = new StringBuffer("file:///");
        sTemplateFileUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));

        
	   if (mxRemoteContext == null && mxRemoteServiceManager == null) {
            // get the remote office context. If necessary a new office
            // process is started
			System.out.println("try to connect to a running office");
            //String oooExeFolder = "C:\\fsales\\OpenOffice/program";
            //mxRemoteContext = BootstrapSocketConnector.bootstrap(oooExeFolder);
            mxRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
            
            System.out.println("Connected to a running office ...");
            mxRemoteServiceManager = mxRemoteContext.getServiceManager();
            
            String available = (mxRemoteServiceManager != null ? "available" : "not available");
            System.out.println("remote ServiceManager is " + available);
        }
       mxRemoteServiceManager = mxRemoteServiceManager;            
        // retrieve the Desktop object, we need its XComponentLoader
        Object desktop = mxRemoteServiceManager.createInstanceWithContext(
            "com.sun.star.frame.Desktop", mxRemoteContext);
        XComponentLoader xComponentLoader = (XComponentLoader)
            UnoRuntime.queryInterface(XComponentLoader.class, desktop);
        
        // define load properties according to com.sun.star.document.MediaDescriptor
        // the boolean property AsTemplate tells the office to create a new document
        // from the given file
        PropertyValue[] loadProps = new PropertyValue[2];
        loadProps[0] = new PropertyValue();
        loadProps[0].Name = "AsTemplate";
        loadProps[1] = new PropertyValue();
        loadProps[0].Value = new Boolean(true); 
        loadProps[1].Name = "Hidden";
        loadProps[1].Value = new Boolean(false);
        // load
System.out.println("Load file: " + sTemplateFileUrl.toString());		
        XComponent xTemplateComponent =  xComponentLoader.loadComponentFromURL(sTemplateFileUrl.toString(), "_blank",  0, loadProps);        
			System.out.println("Office Document opened:" + sTemplateFileUrl.toString());		      
        // get XTextFieldsSupplier, XBookmarksSupplier interfaces
        XTextFieldsSupplier xTextFieldsSupplier = (XTextFieldsSupplier)
            UnoRuntime.queryInterface(XTextFieldsSupplier.class,
                                      xTemplateComponent);
        XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier)
            UnoRuntime.queryInterface(XBookmarksSupplier.class, xTemplateComponent);
        
        // access the TextFields and the TextFieldMasters collections
        XNameAccess xNamedFieldMasters = xTextFieldsSupplier.getTextFieldMasters();
        XEnumerationAccess xEnumeratedFields = xTextFieldsSupplier.getTextFields();
        
        // iterate over hashtable and insert values into field masters
        java.util.Enumeration keys = recipient.keys();
        while(keys.hasMoreElements()) {
            // get column name
            String key = (String)keys.nextElement();
            
            // access corresponding field master		Try to put the DB-Values
			try {
				Object fieldMaster = xNamedFieldMasters.getByName(
					"com.sun.star.text.FieldMaster.User." + key);
				
				// query the XPropertySet interface, we need to set the Content property
				XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(
					XPropertySet.class, fieldMaster);
				
				// insert the column value into field master
				xPropertySet.setPropertyValue("Content", recipient.get(key));
			} catch (java.lang.Exception e) {
                           // System.out.println("DB-Column: " + key + " not in Office-Form");
                        }
        }
        // afterwards we must refresh the textfields collection
        XRefreshable xRefreshable = (XRefreshable)UnoRuntime.queryInterface(
            XRefreshable.class, xEnumeratedFields);
        xRefreshable.refresh();

java.io.File targetFile = new java.io.File(application.getRealPath("/") +"/kontakt_anhaenge/" + koknr + ".pdf");
        StringBuffer sStoreFileUrl = new StringBuffer("file:///");
        sStoreFileUrl.append(targetFile.getCanonicalPath().replace('\\', '/'));  
        XComponent xDoc=xTemplateComponent;
		String storeUrl = sStoreFileUrl.toString();
		
        XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, xDoc); 

  XFrame xFrame = xModel.getCurrentController().getFrame(); 
  xFrame.activate(); 

        XStorable xStorable = (XStorable)UnoRuntime.queryInterface(
            XStorable.class, xDoc);
     //   PropertyValue[] storeProps = new PropertyValue[1];
       PropertyValue[] props = new PropertyValue[2]; 

        props[0] = new PropertyValue(); 
  props[0].Name = "FilterName"; 
  props[0].Value = "writer_pdf_Export"; 
  props[1] = new PropertyValue(); 
  props[1].Name = "CompressionMode"; 
  props[1].Value = "1"; 


        System.out.println("... store \"" + koknr + ".pdf\" .");
        xStorable.storeToURL(storeUrl, props);//storeProps);   
		
        xTemplateComponent.dispose();    

okay...i hope i didn't forget anything to say ... else just tell me...

does anyone have an idea?

greetings from austria
lenaz
Last edited by lenaz on Thu May 07, 2009 8:35 pm, edited 1 time in total.
lenaz
Posts: 10
Joined: Thu May 07, 2009 9:19 am

Re: OOo 3.0.1: Bootstrap.bootstrap() throws a NoConnectException

Post by lenaz »

Okay.. i got a step further!

i replaced following code

Code: Select all


            // get the remote office context. If necessary a new office
            // process is started
			System.out.println("try to connect to a running office");
            //String oooExeFolder = "C:\\fsales\\OpenOffice/program";
            //mxRemoteContext = BootstrapSocketConnector.bootstrap(oooExeFolder);
            mxRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
            
            System.out.println("Connected to a running office ...");
            mxRemoteServiceManager = mxRemoteContext.getServiceManager();
            
            String available = (mxRemoteServiceManager != null ? "available" : "not available");
            System.out.println("remote ServiceManager is " + available);
       
                 
        // retrieve the Desktop object, we need its XComponentLoader
        Object desktop = mxRemoteServiceManager.createInstanceWithContext(
            "com.sun.star.frame.Desktop", mxRemoteContext);
with the this one:

Code: Select all

System.out.println("xcomponentcontext");
  XComponentContext xcomponentcontext = Bootstrap.createInitialComponentContext(null);
  
  // create a connector, so that it can contact the office
  System.out.println("urlResolver");
  XUnoUrlResolver urlResolver = UnoUrlResolver.create(xcomponentcontext);

  System.out.println("initialObject");
  Object initialObject = urlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");


  System.out.println("xOfficeFactory");
  XMultiComponentFactory xOfficeFactory = (XMultiComponentFactory) UnoRuntime.queryInterface(
      XMultiComponentFactory.class, initialObject);

  // retrieve the component context as property (it is not yet exported from the office)
  // Query for the XPropertySet interface.
  XPropertySet xProperySet = (XPropertySet) UnoRuntime.queryInterface(
      XPropertySet.class, xOfficeFactory);

  // Get the default context from the office server.
  Object oDefaultContext = xProperySet.getPropertyValue("DefaultContext");

  // Query for the interface XComponentContext.
  XComponentContext xOfficeComponentContext = (XComponentContext) UnoRuntime.queryInterface(
      XComponentContext.class, oDefaultContext);

  // now create the desktop service
  // NOTE: use the office component context here!
  Object desktop = xOfficeFactory.createInstanceWithContext(
       "com.sun.star.frame.Desktop", xOfficeComponentContext);
now i have to start OpenOffice.org on the server this way:

Code: Select all

%OO_HOME%/program/soffice.exe -accept=socket,host=localhost,port=8100;urp
and everything is going well.

but now I don't want that OOo runs all the time, so i start the program in my JSP as soon as needed:

Code: Select all

Runtime.getRuntime().exec(System.getenv("OO_HOME").replace("\\", "/") + "/program/soffice \"-accept=socket,host=0,port=8100;urp\" \"-invisible\"");
but when i do it this way, i get this connection:

Code: Select all

INFO   | jvm 1    | 2009/05/07 15:30:56 | com.sun.star.connection.NoConnectException: java.net.ConnectException: Connection refused: connect
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at com.sun.star.lib.connections.socket.socketConnector.connect(socketConnector.java:166)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at com.sun.star.comp.connections.Connector.connect(Connector.java:141)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at com.sun.star.comp.urlresolver.UrlResolver$_UrlResolver.resolve(UrlResolver.java:128)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.apache.jsp.oo_005fintegration_005fvon_005fkunde_005ffill_005fcreate_jsp._jspService(org.apache.jsp.oo_005fintegration_005fvon_005fkunde_005ffill_005fcreate_jsp:304)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:491)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:367)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:185)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:689)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:391)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.servlet.Dispatcher.include(Dispatcher.java:192)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.apache.jsp.oo_005fintegration_005fvon_005fkunde_005ffill_jsp._jspService(org.apache.jsp.oo_005fintegration_005fvon_005fkunde_005ffill_jsp:182)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:491)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1074)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:170)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1065)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1065)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:365)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:185)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:689)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:391)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:146)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.Server.handle(Server.java:285)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:457)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:751)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:500)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:209)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:357)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:329)
INFO   | jvm 1    | 2009/05/07 15:30:56 | 	at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:475)
caused by this statement:

Code: Select all

Object initialObject = urlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
in the server's task manager i can see the process... so it's there ...
can someone help me?
OOo 3.0.X on Ms Windows XP + Linux
lenaz
Posts: 10
Joined: Thu May 07, 2009 9:19 am

Re: OOo 3.0.1: Bootstrap.bootstrap() throws a NoConnectException

Post by lenaz »

the JSP is working fine now... i had a permission issue with the jetty-service on the server-machine

topic-problem solved ... for further questions..just ask :)
OOo 3.0.X on Ms Windows XP + Linux
siggi
Posts: 5
Joined: Thu Jun 04, 2009 11:51 am

Re: [Solved] OOo 3.0.1: Bootstrap.bootstrap() problem

Post by siggi »

Hi,

I have a similiar problem with conversion an *.odt file to *.pdf using the OO-API Converting odt to pdf with the bootstrap.jar. I have a servlet in Eclipse (Java 1.6.0), OS: Windows XP, local Tomcat (Version 6.0). In Eclipse and local Tomcat-6.0 the conversion works successfully, no problems and no error messages.

But the same servlet on a Microsoft Windows Server 2003 with Tomcat Version 5.5 doesn't work successfully at the point, it stopps, where the following code comes:
...
mxRemoteContext = BootstrapSocketConnector.bootstrap(oooExeFolder);
...

Please look at complete code:

Code: Select all

XComponentContext mxRemoteContext = null;
			XComponentLoader xComponentLoader = null;
			XMultiComponentFactory xMultiCompFact = null;
			XStorable xStorable = null;
			XCloseable xCloseable = null;
			Object document = null;
			Object desktop = null;
			int lastDot = -1;
			PropertyValue[] loadProps = null;
			String loadUrlToString = null;
try {
String oooExeFolder = "C:/Programme/OpenOffice.org3/program/";
//[b]Attention!! At the following code the servlet stop without any error/exception message (in *.log file)[/b], Do you know why????
mxRemoteContext = BootstrapSocketConnector.bootstrap(oooExeFolder);


xMultiCompFact = mxRemoteContext.getServiceManager();
	      
	      // retrieve the Desktop object, we need its XComponentLoader
	      desktop = xMultiCompFact.createInstanceWithContext("com.sun.star.frame.Desktop", mxRemoteContext);
	      xComponentLoader = (XComponentLoader)UnoRuntime.queryInterface(XComponentLoader.class, desktop);
	      //the boolean property Hidden tells the office to open a file in hidden mode 
	      loadProps = new PropertyValue[1]; 
	      loadProps[0] = new PropertyValue(); 
	      loadProps[0].Name = "Hidden"; 
	      loadProps[0].Value = new Boolean(true);     
	      // load
	      //System.out.println("nach load:");    
		
		 //Open the document in Open Office
	     document =  xComponentLoader.loadComponentFromURL(loadUrlToString, "_blank", 0, loadProps);
	     // Get a reference to the document interface that can store files
	     xStorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, document);
	     PropertyValue[] aMediaDescriptor = new PropertyValue[2];
		 //Setting the flag for overwriting
	     aMediaDescriptor[0] = new com.sun.star.beans.PropertyValue();
	     aMediaDescriptor[0].Name = "Overwrite";
	     aMediaDescriptor[0].Value = new Boolean(true);
	     //Setting the filter name
	 	 aMediaDescriptor[1] = new PropertyValue();
	 	 aMediaDescriptor[1].Name = "FilterName";
	 	 aMediaDescriptor[1].Value = "writer_pdf_Export";
	 	 
//	 	 The converted file will have the same name with a PDF extension
	 	 String saveUrl = loadUrlToString.substring(0, lastDot) + ".pdf";
	 	
//	     Save the file
	 	 xStorable.storeToURL(saveUrl, aMediaDescriptor);
	 	
	 	
} catch (com.sun.star.comp.helper.BootstrapException e) {
			e.printStackTrace();
			System.out.println("BootstrapException in convertOOodtToPdf(...): "  + e.toString());
		} catch (Throwable e) {
			e.printStackTrace();
			System.out.println("Throwable in convertOOodtToPdf(...): "  + e.toString());
		}



Do you know an alternative program code?
Thanks for help in advance

P.S. Schöne Grüsse aus Bonn in Deutschland - die Antwort kann auch gerne in Deutsch sein

Siggi
OOo 3.0.X on Ms Windows XP
lenaz
Posts: 10
Joined: Thu May 07, 2009 9:19 am

Re: [Solved] OOo 3.0.1: Bootstrap.bootstrap() problem

Post by lenaz »

seawas Siggi ^^

[austrian mode on]
i schreib trotzdem auf englisch, wei wenn aundare leit a ähnliches problem haum, daun kennan se se a aus ;)
[austrian mode off]

[german mode on]
hast du verstanden, was ich da grad geschrieben hab? ^^
[german mode off]

lol, i'm a freak xD

okay, back to topic :D

in principle, you look for another way to get this "desktop"-object ... so try following code:

Code: Select all

XComponentContext xcomponentcontext = Bootstrap.createInitialComponentContext(null);
 
  // create a connector, so that it can contact the office
  XUnoUrlResolver urlResolver = UnoUrlResolver.create(xcomponentcontext);

  Object initialObject = urlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");


  XMultiComponentFactory xOfficeFactory = (XMultiComponentFactory) UnoRuntime.queryInterface(
      XMultiComponentFactory.class, initialObject);

  // retrieve the component context as property (it is not yet exported from the office)
  // Query for the XPropertySet interface.
  XPropertySet xProperySet = (XPropertySet) UnoRuntime.queryInterface(
      XPropertySet.class, xOfficeFactory);

  // Get the default context from the office server.
  Object oDefaultContext = xProperySet.getPropertyValue("DefaultContext");

  // Query for the interface XComponentContext.
  XComponentContext xOfficeComponentContext = (XComponentContext) UnoRuntime.queryInterface(
      XComponentContext.class, oDefaultContext);

  // now create the desktop service
  // NOTE: use the office component context here!
  Object desktop = xOfficeFactory.createInstanceWithContext(
       "com.sun.star.frame.Desktop", xOfficeComponentContext);

don't forget to start OpenOffice in "listening mode" before the java-code tries to connect (you can start the process in your java-code too, but make sure, that it's up and running, before the connection attempt... just build in some exception-handling ;) )

Code: Select all

%OO_HOME%/program/soffice -accept=socket,host=localhost,port=8100;urp
i tested this way on WindowsXP and Linux machines (both with JETTY Webserver) ... without problems

hav phun & best regards ^^
lenaz
OOo 3.0.X on Ms Windows XP + Linux
siggi
Posts: 5
Joined: Thu Jun 04, 2009 11:51 am

Re: [Solved] OOo 3.0.1: Bootstrap.bootstrap() problem

Post by siggi »

Hi lenaz,

Thanks for your answer.

I tested your code and i got the following error message ("Throwable" in Java) at code line:
...
Object initialObject = urlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
...

Code: Select all

com.sun.star.connection.NoConnectException: java.net.ConnectException: Connection refused: connect
	at com.sun.star.lib.connections.socket.socketConnector.connect(socketConnector.java:166)
	at com.sun.star.comp.connections.Connector.connect(Connector.java:141)
	at com.sun.star.comp.urlresolver.UrlResolver$_UrlResolver.resolve(UrlResolver.java:128)
	at odt.OdtExport.convertOOodtToPdf(OdtExport.java:98)
	at web.OdtServlet.doGet(OdtServlet.java:319)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Thread.java:619)
What could be cause for this "NoConnectException"? Are above the parameter for "host" and "port" ok?

By the way I didn't understand your comment and code in the last line in your reply: what should I do
in my code? What means to start OpenOffice in "listening mode", how should I do that?

"don't forget to start OpenOffice in "listening mode" before the java-code tries to connect (you can start the process in your java-code too, but make sure, that it's up and running, before the connection attempt... just build in some exception-handling )

Code: Select all Expand viewCollapse view
%OO_HOME%/program/soffice -accept=socket,host=localhost,port=8100;urp"

Thanks for answer in advance

best regards

Siggi
OOo 3.0.X on Ms Windows XP
lenaz
Posts: 10
Joined: Thu May 07, 2009 9:19 am

Re: [Solved] OOo 3.0.1: Bootstrap.bootstrap() problem

Post by lenaz »

Hi!

at this point:

Code: Select all

Object initialObject = urlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
your java code tries to connect to an existing OpenOffice - Instance on your Server Machine ( the parameters for host and port should be okay )

to start OpenOffice in "listening mode", just create a new Shortcut on the server with following target:
%OO_HOME%/program/soffice -accept=socket,host=localhost,port=8100;urp
you have to replace "%OO_HOME%" with the install path of your OpenOffice-Installation...
for example:

Code: Select all

C:\Program Files\OpenOffice.org 3\program\soffice -accept=socket,host=localhost,port=8100;urp
okay... double-click this shortcut and open a funky fresh command line (cmd.exe) and type in following command

Code: Select all

netstat -na | find "8100"
now you should see an entry like

Code: Select all

 TCP            127.0.0.1:8100             0.0.0.0.:0             ABHÖREN 
your OpenOffice is now "up and running in listening mode"

now try to run your java-code ... it should connect smoothly :)
if done successfully, we can go a step further ;)
if not, tell me what went wrong

till then,
lenaz
OOo 3.0.X on Ms Windows XP + Linux
siggi
Posts: 5
Joined: Thu Jun 04, 2009 11:51 am

Re: [Solved] OOo 3.0.1: Bootstrap.bootstrap() problem

Post by siggi »

Hi,

Thanks for your answer, but I think to start OpenOffice in "listening mode" with a new Shortcut on the server..., as you described, doesn't fit to the general requirements of my use case.

The requirements of my use case are (sorry, I forgot to tell you):

- someone/user clicks on a link e.g. "list of journals" on our public web site
- with this click a servlet is called up on our server and then everything should go automatically
- the servlet creates the Open Office file (*.odt) with the list of journals and then automatically converts this
*.odt file to pdf-file, which the user then see opened as the result of his click on the web link.

That means, that the connection to OpenOffice and all other steps concerning to your code should happen automatically, too. There are no additional human action, as I understand your hint to the server Shortcut, possible
respectively allowed.

What is your opinion to my requirements and a solution to start OpenOffice and so on automatically?

best regards

Siggi
OOo 3.0.X on Ms Windows XP
lenaz
Posts: 10
Joined: Thu May 07, 2009 9:19 am

Re: [Solved] OOo 3.0.1: Bootstrap.bootstrap() problem

Post by lenaz »

look at my words again ^^
now try to run your java-code ... it should connect smoothly :)
if done successfully, we can go a step further ;)
if not, tell me what went wrong
well...i see you can't await the next step...so here it is:

you can start OpenOffice from your java-code (like this):

Code: Select all

Runtime.getRuntime().exec(System.getenv("OO_HOME").replace("\\", "/") + "/program/soffice -accept=socket,host=localhost,port=8100;urp -invisible -nologo -headless -norestore -nofirststartwizard");

(just ignore the other arguments [invisible,nologo,...] for now, they aren't important yet)

okay, your Java-Code is now starting OpenOffice automatically, without human acting

but be aware! java-code goes on and finally comes to

Code: Select all

Object initialObject = urlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
but what happens, if the OO-Process is not already "up and running" ?
exactly: it comes to the NoConnectException again!
so you have to build in some exception handling

i did it this way:

Code: Select all

       Object objectInitial = null;
       boolean resolved=false;
       for(int z=1;z<12;z++){   //trying 11 times ... you can modify this of course ^^
              try{
                     objectInitial = xurlresolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");  //connection-attempt
                     resolved=true;  //if connected, resolved goes "true"
                     break;
                  }catch (java.lang.Exception jle){  
                         System.out.println("NoConnectException...trying again in 5 seconds(attempt: "+z +")"); 
                         Thread.sleep(5000);//if not connected, wait some seconds and then go on with next attempt
                  }
       }
       if(!resolved)
       {
              System.out.println("No Connection to Office");
              //<pdfid>_sync.error erstellen
              java.io.File pdfError = new java.io.File(application.getRealPath("/") + "/oo_vorlagen/" + id + "_sync.error");
              pdfError.createNewFile();
       }
hav phun ;)
lenaz
OOo 3.0.X on Ms Windows XP + Linux
siggi
Posts: 5
Joined: Thu Jun 04, 2009 11:51 am

Re: [Solved] OOo 3.0.1: Bootstrap.bootstrap() problem

Post by siggi »

Hi lenaz,

Thanks for your hints. With your code my servlet works now fine, but sometimes I get no connection at:

Code: Select all

Object initialObject = urlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
and then it goes to the Exception handling you mentioned in your email, but there were no new successful connection (attempt) built up, too. What is your experience with connection attempts in this exception handling?

A last question to the code:

Code: Select all

java.lang Process proc = Runtime.getRuntime().exec(System.getenv("OO_HOME").replace("\\", "/") + "/program/soffice -accept=socket,host=localhost,port=8100;urp -invisible -nologo -headless -norestore -nofirststartwizard");

If "proc" is not null and the rest of the programm, including connection to OO-Server, works successfully,
should I destroy the "proc" at he end of my programme with the following code?:

Code: Select all

proc.destroy();

Best regards

Siggi
OOo 3.0.X on Ms Windows XP
lenaz
Posts: 10
Joined: Thu May 07, 2009 9:19 am

Re: [Solved] OOo 3.0.1: Bootstrap.bootstrap() problem

Post by lenaz »

Hello again :)
siggi wrote: and then it goes to the Exception handling you mentioned in your email, but there were no new successful connection (attempt) built up, too. What is your experience with connection attempts in this exception handling?
humm... could you post your log?
build in some detailed output (and print the detailed exception-message too) .. and post it ..

my experience with this method:
this code should be adapted to the server-system... (Performance, OS!, and so on)
the Operating System is an IMPORTANT criterion!
on a Windows-XP-Server, my code needs 1 or 2 attempts to connect .. maximum!
on a Linux-Server, the NoConnect-Timeout is much less! so my code needed 9000 connection-attempts...

because of this, i built in the "Thread.sleep(5000);" in the catch-block ...

play a bit with the code .. try something new ..i know there can be a much better solution than mine is ^^
siggi wrote: A last question to the code:

Code: Select all

java.lang Process proc = Runtime.getRuntime().exec(System.getenv("OO_HOME").replace("\\", "/") + "/program/soffice -accept=socket,host=localhost,port=8100;urp -invisible -nologo -headless -norestore -nofirststartwizard");

If "proc" is not null and the rest of the programm, including connection to OO-Server, works successfully,
should I destroy the "proc" at he end of my programme with the following code?:

Code: Select all

proc.destroy();
i don't use java.lang.Process for the program-call (maybe i should..? ^^ )
... but if you do so, you can

Code: Select all

proc.destroy();
as soon as your java-code doesn't need OpenOffice anymore.. of course... why not ?

bye,
lenaz
OOo 3.0.X on Ms Windows XP + Linux
Post Reply