Issue 3613 - Java Client code causes server to silently fail
Summary: Java Client code causes server to silently fail
Status: CLOSED FIXED
Alias: None
Product: udk
Classification: Code
Component: code (show other issues)
Version: 641
Hardware: PC Other OS
: P3 Trivial (vote)
Target Milestone: ---
Assignee: stephan.wunderlich
QA Contact: issues@udk
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-03-21 14:38 UTC by Unknown
Modified: 2003-02-21 12:35 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Unknown 2002-03-21 14:38:55 UTC
When I run the code to create an Impress presentation with TextShapes, 
populated with Text, I get the following behaviour.  The error comes from the  
** dispose ** method near the bottom of the code.  
The output file is created successfully (including the text on the TextShape)
The server shuts down, with a the following message “an unrecoverable error has 
occurred”, but with a return value of 0 The following output / error is 
returned by the client (return value 1)

[openoffice]
b4 createTextCursor
b4 gotoEnd
b4 queryInterface
b4 setString
b4 gotoEnd
b4 store, etc
got XStorable interface
set Save properties
stored as URL
got XComponent interface
java.io.IOException: com.sun.star.io.IOException: java.net.SocketException:
Connection reset by peer: JVM_recv in socket input stream read at 
com.sun.star.lib.uno.bridges.java_remote.XConnectionInputStream_Adapter.read
(XConnectionInputStream_Adapter.java:93)
at java.io.DataInputStream.readInt(DataInputStream.java:338)
at com.sun.star.lib.uno.protocols.urp.urp.readBlock(urp.java:489)
at com.sun.star.lib.uno.protocols.urp.urp.readMessage(urp.java:592)
at 
com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge$MessageDispatcher.in
voke(java_remote_bridge.java:183)
at 
com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge$MessageDispatcher.ru
n(java_remote_bridge.java:174)


If I comment out the Text section of code (commented in CAPS in the code), I 
get the following behaviour: 
The client runs ok (returns 0)
The output file is created (minus the text on the TextShape)
The server just shuts down, with a return value of 0 ??!!!!
Heres the code, which as u will see, is heavily based on the examples

import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.XComponentContext;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XStorable;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;

import com.sun.star.drawing.XDrawPagesSupplier;
import com.sun.star.drawing.XDrawPages;
import com.sun.star.drawing.XDrawPage;
import com.sun.star.drawing.XShapes;
import com.sun.star.drawing.XShape;

//import com.sun.star.drawing.*;

import com.sun.star.container.XIndexAccess;

import com.sun.star.text.XText;
import com.sun.star.text.XTextFrame;
import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextRange;

import com.sun.star.awt.Size;
import com.sun.star.awt.Point;

import java.io.File;
import java.io.FileFilter;

public class DocumentConverter {
  static XComponentLoader xcomponentloader = null;
  static String stringConvertType = "";
  static String stringExtension = "";
  static String indent = "";

  static void traverse( File fileDirectory ) {
    if ( !fileDirectory.isDirectory() ) {
      throw new IllegalArgumentException(
      "not a directory: " + fileDirectory.getName()
      );
    }

    System.out.println(indent + "[" + fileDirectory.getName() + "]");
    indent += "  ";

    // Getting all files and directories in the current directory
    File[] entries = fileDirectory.listFiles(
    new FileFilter() {
      public boolean accept( File pathname ) {
        return true;
      }
    }
    );

    // Iterating for each file and directory
    for ( int i = 0; i < entries.length; ++i ) {
      // Testing, if the entry in the list is a directory
      if ( entries[ i ].isDirectory() ) {
        // Recursive call for the new directory
        traverse( entries[ i ] );
      } else {
        // Converting the document to the favoured type
        try {
			Size size = new Size();
			Point position = new Point();

			PropertyValue propertyvalue [] = new PropertyValue [1];


			propertyvalue [0] = new PropertyValue ();
			propertyvalue [0].Name = "Hidden";
			propertyvalue [0].Value = new Boolean (true);

          // Composing the URL by replacing all backslashs
          String stringUrl = "file:///"
          + entries[ i ].getAbsolutePath().replace( '\\', '/' );

          // Loading the wanted document (invisibly, using the property values)
          Object objectDocumentToStore =
          DocumentConverter.xcomponentloader.loadComponentFromURL(
          stringUrl, "_blank", 0, propertyvalue );

          //TEST CODE, to add a text shape to the document

          XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 
UnoRuntime.queryInterface(XDrawPagesSupplier.class,objectDocumentToStore);
          XDrawPages oDPn = oDPS.getDrawPages();
          XIndexAccess oDPi = (XIndexAccess) UnoRuntime.queryInterface
(XIndexAccess.class,oDPn);
          XDrawPage oObj = (XDrawPage) oDPi.getByIndex(0);
          XShapes oShapes = (XShapes) UnoRuntime.queryInterface
(XShapes.class,oObj);

          XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
		  		UnoRuntime.queryInterface
(XMultiServiceFactory.class, objectDocumentToStore);

		  Object oInt = oDocMSF.createInstance
("com.sun.star.drawing.TextShape");
		  XShape oShape = (XShape)UnoRuntime.queryInterface( 
XShape.class, oInt );

		  size.Height = 10000;
		  size.Width = 10000;
		  position.X = 10000;
		  position.Y = 10000;
		  oShape.setSize(size);
		  oShape.setPosition(position);

		  XPropertySet oSPS = (XPropertySet)UnoRuntime.queryInterface( 
XPropertySet.class, oShape);

		  //fill with red, for the sake of visibility!
		  oSPS.setPropertyValue("FillColor",new Integer((255*65536)+
(0*256)+0));
		  oSPS.setPropertyValue("Shadow",new Boolean(true));
		  oSPS.setPropertyValue("TextAutoGrowWidth",new Boolean(true));

          oShapes.add(oShape);

//		START OF TEXT SECTION THAT CAUSES GRIEF


          XText xText = (XText)
				UnoRuntime.queryInterface( XText.class, 
oShape );
		  if (xText == null)
		  	{
			System.err.println ("Error getting Text handle on 
TextShape");
			}

			System.err.println ("b4 createTextCursor");
		  XTextCursor xTextCursor = xText.createTextCursor();

		  	System.err.println ("b4 gotoEnd");
		  xTextCursor.gotoEnd( false );

		  	System.err.println ("b4 queryInterface");
		  XTextRange xTextRange = (XTextRange)
				UnoRuntime.queryInterface( XTextRange.class, 
xTextCursor );

			System.err.println ("b4 setString");
		  xTextRange.setString( "This is the string.  It is a longish 
enough affair" );

		  	System.err.println ("b4 gotoEnd");
		  xTextCursor.gotoEnd( true );

		  System.err.println ("b4 store, etc");

//		END OF TEXT SECTION THAT CAUSES GRIEF

          // Getting an object that will offer a simple way to store a document 
to a URL.
          XStorable xstorable =
          ( XStorable ) UnoRuntime.queryInterface( XStorable.class,
          	objectDocumentToStore );

          		System.err.println ("got XStorable interface");

          // Preparing properties for converting the document
          propertyvalue = new PropertyValue[ 2 ];
          // Setting the flag for overwriting
          propertyvalue[ 0 ] = new PropertyValue();
          propertyvalue[ 0 ].Name = "Overwrite";
          propertyvalue[ 0 ].Value = new Boolean(true);
          // Setting the filter name
          propertyvalue[ 1 ] = new PropertyValue();
          propertyvalue[ 1 ].Name = "FilterName";
          propertyvalue[ 1 ].Value = DocumentConverter.stringConvertType;

          		System.err.println ("set Save properties");

          // Appending the favoured extension to the origin document name
          stringUrl = stringUrl + "." + DocumentConverter.stringExtension;

          // Storing and converting the document
          xstorable.storeAsURL( stringUrl, propertyvalue );

          		System.err.println ("stored as URL");

          // Getting the method dispose() for closing the document
          XComponent xcomponent =
          	( XComponent ) UnoRuntime.queryInterface( XComponent.class,
          	xstorable );

          		System.err.println ("got XComponent interface");

          // Closing the converted document
          xcomponent.dispose();

          		System.err.println ("DISPOSED of");
        }
        catch( Exception e ) {
          e.printStackTrace();
          System.exit (1);
        }

        System.out.println(indent + entries[ i ].getName());
      }
    }

    //indent = indent.substring(2);
  }

  public static void main( String args[] ) {
    try {
      if ( args.length < 4 ) {
        System.out.println(
        "usage: java -classpath .;<Office path>/program/classes/jurt.jar;" +
        "<Office path>/program/classes/ridl.jar;" +
        "<Office path>/program/classes/sandbox.jar;" +
        "<Office path>/program/classes/unoil.jar;" +
        "<Office path>/program/classes/juh.jar " +
        "DocumentConverter \"<connection>\" \"<directory to convert>\"" +
        " \"<type to convert to>\" \"<extension>\"" );
        System.out.println( "\ne.g.:" );
        System.out.println(
        "java -classpath .;d:/office60/program/classes/jurt.jar;" +
        "d:/office60/program/classes/ridl.jar;" +
        "d:/office60/program/classes/sandbox.jar;" +
        "d:/office60/program/classes/unoil.jar; " +
        "d:/office60/program/classes/juh.jar " +
        "DocumentConverter \"uno:socket,host=localhost,port=8100;urp;" +
        "StarOffice.ServiceManager\"" +
        " \"c:/myoffice\" \"swriter: MS Word 97\" \"doc\"" );
        System.exit(1);
      }

      XComponentContext xComponentContext =
      	com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( 
null );

      XMultiComponentFactory xMultiComponentFactory =
      	xComponentContext.getServiceManager();

      Object objectUrlResolver = 
xMultiComponentFactory.createInstanceWithContext(
      	"com.sun.star.bridge.UnoUrlResolver", xComponentContext );

      // Create a new url resolver
      XUnoUrlResolver xurlresolver = ( XUnoUrlResolver )
		  UnoRuntime.queryInterface( XUnoUrlResolver.class,
		  objectUrlResolver );

      // Resolves an object that is specified as follow:
      // uno:<connection description>;<protocol description>;<initial object 
name>
      Object objectInitial = xurlresolver.resolve( args[ 0 ] );

      // Create a service manager from the initial object
      xMultiComponentFactory = ( XMultiComponentFactory )
      	UnoRuntime.queryInterface( XMultiComponentFactory.class, 
objectInitial );

      // Query for the XPropertySet interface.
      XPropertySet xpropertysetMultiComponentFactory = ( XPropertySet )
      UnoRuntime.queryInterface( XPropertySet.class, xMultiComponentFactory );

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

      // Query for the interface XComponentContext.
      xComponentContext = ( XComponentContext ) UnoRuntime.queryInterface(
      	XComponentContext.class, objectDefaultContext );

      xcomponentloader = ( XComponentLoader )
      	UnoRuntime.queryInterface( XComponentLoader.class,
      	xMultiComponentFactory.createInstanceWithContext(
      	"com.sun.star.frame.Desktop", xComponentContext ) );

      // Getting the given starting directory
      File file = new File(args[ 1 ]);

      // Getting the given type to convert to
      stringConvertType = args[ 2 ];

      // Getting the given extension that should be appended to the origin 
document
      stringExtension = args[ 3 ];

      // Starting the conversion of documents in the given directory and 
subdirectories
      traverse( file );

      System.exit(0);
    }
    catch( Exception e ) {
      e.printStackTrace();
      System.exit (1);

    }
  }
}
Comment 1 Unknown 2002-03-21 20:28:28 UTC
This seems to be related to the line of code that says... 

XText xText = (XText)UnoRuntime.queryInterface( XText.class, oShape );

If I comment out the TEXT section from this line of code to the end 
of the block, (with some minor mods to scoping and the traverse 
function to make it work for a single file instead of a directory), 
it succeeds, with the server remaining up.

If even this one line from the text section is left in the code, the 
client causes the server to fall over.
Comment 2 kay.ramme 2002-03-26 12:12:24 UTC
Christian, please have a look at this.
Comment 3 clippka 2002-04-04 12:25:41 UTC
will have a look into this
Comment 4 clippka 2002-04-15 11:28:01 UTC
could not reproduce in a current developer build, will check against a  oo 641d
Comment 5 clippka 2002-11-27 10:27:58 UTC
can not reproduce the bug in a current build
Comment 6 clippka 2003-01-08 14:49:02 UTC
reopen to send back to qs
Comment 7 clippka 2003-01-08 15:17:43 UTC
Fixed in OOo1.1Beta
Comment 8 clippka 2003-01-08 15:18:02 UTC
changed resolution
Comment 9 stephan.wunderlich 2003-01-10 13:54:17 UTC
works as expected in srx644c,8484 => will be fixed in OOo1.1beta
Comment 10 stephan.wunderlich 2003-02-21 12:35:52 UTC
SW: works in Snapshot Developer Release 644_m1 => closed