Quantcast
Channel: PTC Community : Unanswered Discussions - Windchill
Viewing all articles
Browse latest Browse all 3592

Java code to Download Content of WTDocument

$
0
0

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(ExportWTDocumentNew.java:90)

  at ext.test.ExportWTDocumentNew.main(ExportWTDocumentNew.java:52)

Caused by: java.lang.NullPointerException

  at wt.content.ContentServerHelper.<clinit>(ContentServerHelper.java:62)

  ... 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();

 

  auth.setRemoteUser("wcadmin");

  rms.setAuthenticator(auth);

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

 

  WTDocument wtdoc= null;

  QuerySpec qs = new QuerySpec(WTDocument.class);

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

 

  while(qr.hasMoreElements()){

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

  wtdoc = (WTDocument)qr.nextElement();

  System.out.println(wtdoc.getName());

  System.out.println(wtdoc.getNumber());

  }

  extractContent(wtdoc, output);

  }

  private static void extractContent( WTDocument wtDoc, String outputDir )

  {

  try

  {

  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)(appIter.next());

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

  }

  }

  else

  {

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

  System.out.println("errorMessage");

  }

  }

  catch (Exception e)

  {

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

  e.printStackTrace();

  }

  }

}

 

 

Thanks,

Vivek


Viewing all articles
Browse latest Browse all 3592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>