0

I am currently investigating the possibility of using a Java Web Service (as described by the Info*Engine documentation of Windchill) in order to retrieve information regarding parts. I am using Windchill version 10.1.

I have successfully deployed a web service, which I consume in a .Net application. Calls which do not try to access Windchill information complete successfully. However, when trying to retrieve part information, I get a wt.method.AuthenticationException.

Here is the code that runs within the webService (The web service method simply calls this method)

public static String GetOnePart(String partNumber) throws WTException
{
    WTPart part=null;

    RemoteMethodServer server  =  RemoteMethodServer.getDefault();   
    server.setUserName("theUsername");   
    server.setPassword("thePassword");

    try {
        QuerySpec qspec= new QuerySpec(WTPart.class);
        qspec.appendWhere(new SearchCondition(WTPart.class,WTPart.NUMBER,SearchCondition.LIKE,partNumber),new int[]{0,1});

        // This fails.
        QueryResult qr=PersistenceHelper.manager.find((StatementSpec)qspec);
        while(qr.hasMoreElements())
        {
            part=(WTPart) qr.nextElement();
            partName = part.getName();
        }
    } catch (AuthenticationException e) {
        // Exception caught here.
        partName = e.toString();
    }

    return partName;
}

This code works in a command line application deployed on the server, but fails with a wt.method.AuthenticationException when performed from within the web service. I feel it fails because the use of RemoteMethodServer is not what I should be doing since the web service is within the MethodServer.

Anyhow, if anyone knows how to do this, it would be awesome. A bonus question would be how to log from within the web service, and how to configure this logging.

Thank you.

Ldblanchet
  • 3
  • 1
  • 3

2 Answers2

1

You don't need to authenticate on the server side with this code

RemoteMethodServer server  =  RemoteMethodServer.getDefault();   
server.setUserName("theUsername");   
server.setPassword("thePassword");

If you have followed the documentation (windchill help center), your web service should be something annotated with @WebServices and @WebMethod(operationName="getOnePart") and inherit com.ptc.jws.servlet.JaxWsService

Also you have to take care to the policy used during deployment. The default ant script is configured with

security.policy=userNameAuthSymmetricKeys

So you need to manage it when you consume your ws with .Net.

For logging events, you just need to call the log4j logger instantiated by default with $log.debug("Hello")

Julien Boulay
  • 1,164
  • 7
  • 15
  • Yes, I have an annotation like that for my methods, but the "credentials" I used to perform the call in .Net don't seem to carry to Windchill. For example, I kinda managed to get it working by doing this very ugly code : WTUser user = new WTUser(); user.setName("wcadmin"); SessionContext.setEffectivePrincipal(user); I would have thought that this context would have been properly propagated from the WebService to Windchill... It probably should be, but I haven't been able to find out what's wrong with my setup. – Ldblanchet Jan 24 '14 at 20:23
0

You can't pre-authenticate server side.

You can write the auth into your client tho. Not sure what the .Net equivilent is, but this works for Java clients:

private static final String USERNAME = "admin";
private static final String PASSWORD = "password";

static {

    java.net.Authenticator.setDefault(new java.net.Authenticator() {

        @Override
        protected java.net.PasswordAuthentication getPasswordAuthentication() {
            return new java.net.PasswordAuthentication(USERNAME, PASSWORD.toCharArray());
        }
    });
}