简体   繁体   中英

How to specify credentials from a Java Web Service in PTC Windchill PDMLink

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM