In this post I am trying to share the Windchill command line utility skeleton which uses RemoteMethodServer.
package com.blogspot.maheshmhetre.windchill.utilities; import java.lang.reflect.InvocationTargetException; import java.rmi.RemoteException; import wt.method.RemoteAccess; import wt.method.RemoteMethodServer; import wt.session.SessionHelper; import wt.util.WTException; public class WindchillCustomUtilitySkeleton { //START of inner class - Server public static class Server implements RemoteAccess { public static void methodOne(String param1, String param2) { try { //Get login credentials SessionHelper.manager.getPrincipal(); //Call core processing method WindchillCustomUtilitySkeleton utility = new WindchillCustomUtilitySkeleton(); utility.doOperation(param1, param2); } catch (Exception e) { e.printStackTrace(); } return; } } //END of inner class - Server private void doOperation(String param1, String param2) throws WTException{ //TODO execute your utility logic System.out.println("This sysout will be available in method server log."); } public static void main(String[] args) { //TODO get utility input parameters //TODO basic validation System.out.println("This sysout will be available on console from where the utility is running."); //prepare input params //data types will depends on your method parameters and can be any valid object type Class argTypes[] = {String.class, String.class};//add all remote method parameter data types Object argValues[] = {"param_1_value", "param_2_value"};//respective data value //call remote method - pass inner class name, method name, arg types and arg values try { RemoteMethodServer.getDefault().invoke("methodOne", "com.blogspot.maheshmhetre.windchill.utilities.WindchillCustomUtilitySkeleton$Server", null, argTypes, argValues); } catch (RemoteException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } Runtime.getRuntime().exit(0); } }
Please share your thoughts to improve this skeleton.
2 comments:
Looking through the Javadoc for Windchill, I am having trouble finding anything that would allow me to upload a file to a known location in an existing Windchill database. This is my first foray into Windchill, and I may be using the wrong terminology or looking in the wrong place. Would you have any advice/recommendations as to where to look/what to use?
Hi Mahesh,
In the below code, i have to hard code username and Password which is not a best practice.
RemoteMethodServer rms = wt.method.RemoteMethodServer.getDefault();
rms.setUserName(user);
rms.setPassword(pwd);
Any workaround to avoid this?
Post a Comment