Showing results for 
Search instead for 
Did you mean: 
Showing results for 
Search instead for 
Did you mean: 

Java code to Download Content of WTDocument


Java code to Download Content of WTDocument

Hi All,

I am trying to download the content of WTDocument.

In Program i am getting

WARNING: The ManagerService is not initialized! This can be caused by:

1) Attempting to invoke a server only method from a remote client

2) Attempting to invoke a method on a service from the constructor or static initializer of another service

Exception in thread "main" java.lang.ExceptionInInitializerError

at ext.test.ExportWTDocumentNew.extractContent(

at ext.test.ExportWTDocumentNew.main(

Caused by: java.lang.NullPointerException

at wt.content.ContentServerHelper.<clinit>(

... 2 more


My Program is as Below, Please help me out.

import wt.doc.WTDocument;

import wt.fc.PersistenceHelper;

import wt.fc.QueryResult;

import wt.httpgw.GatewayAuthenticator;

import wt.method.RemoteMethodServer;

import wt.query.QueryException;

import wt.query.QuerySpec;

import wt.util.WTException;

public class ExportWTDocumentNew {


* @param args

* @throws WTException


public static void main(String[] args) throws WTException {

// TODO Auto-generated method stub

System.out.println("Program to Extarct the Content of WTDocument");

System.out.println("Provide the Output folder path");

String output = "C:\\abc\\Log\\test";

System.out.println("Given Output Directory is :: "+output);

RemoteMethodServer rms = RemoteMethodServer.getDefault();

GatewayAuthenticator auth = new GatewayAuthenticator();



System.out.println("Auth is done..");

WTDocument wtdoc= null;

QuerySpec qs = new QuerySpec(WTDocument.class);

QueryResult qr = PersistenceHelper.manager.find(qs);


System.out.println("Inside the While loop");

wtdoc = (WTDocument)qr.nextElement();




extractContent(wtdoc, output);


private static void extractContent( WTDocument wtDoc, String outputDir )




String errorMessage = "";

wt.content.ContentHolder syHold = null;

syHold = (wt.doc.WTDocument)wt.content.ContentHelper.service.getContents(((wt.content.ContentHolder)wtDoc));

System.out.println("Value of syHold:: "+syHold);

java.util.Vector vectorOfAppData = wt.content.ContentHelper.getContentListAll( syHold );

if( vectorOfAppData != null)


java.util.Iterator appIter = vectorOfAppData.iterator();

while (appIter.hasNext())


wt.content.ApplicationData syAppData = (wt.content.ApplicationData)(;

String docName = syAppData.getFileName();

long fileSize = syAppData.getFileSize();

String syContentFileName = outputDir + ((outputDir.endsWith("\\")) ? docName : "\\" + docName);

// Save the content file to disk on the Windchill server

wt.content.ContentServerHelper.service.writeContentStream(syAppData, syContentFileName);





errorMessage = "--> This primary business object has no primary content file. No file extracted.";




catch (Exception e)


System.out.println("--> WTException");







Tags (1)

Re: Java code to Download Content of WTDocument

If you are within windchill 10.1 or higher the simplest way would be to put your code into a jsp and execute it - In pdmlink 10 the servletengine is in the same context as the methodserver

Re: Java code to Download Content of WTDocument

Another option is to invoke your method on the methodserver:

import java.lang.reflect.InvocationTargetException;

import java.rmi.RemoteException;

import org.apache.log4j.Logger;

import wt.method.RemoteAccess;

import wt.method.RemoteMethodServer;

import wt.util.WTException;

public class InvokeTest implements RemoteAccess {

public static Logger logger = Logger.getLogger(InvokeTest.class.getName());

public static void myMethod() throws WTException,RemoteException{

// your code goes here


public static void main(String[] args) throws WTException, RemoteException, InvocationTargetException {

RemoteMethodServer.getDefault().invoke("myMethod", "", null,new Class[]{}, new Object[]{} );