简体   繁体   English

如何从PTC Windchill PDMLink中的Java Web服务指定凭据

[英]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. 我目前正在研究使用Java Web Service(如Windchill的Info * Engine文档所述)以检索有关零件的信息的可能性。 I am using Windchill version 10.1. 我正在使用Windchill版本10.1。

I have successfully deployed a web service, which I consume in a .Net application. 我已经成功部署了一个Web服务,该服务在.Net应用程序中使用。 Calls which do not try to access Windchill information complete successfully. 不尝试访问Windchill信息的呼叫成功完成。 However, when trying to retrieve part information, I get a wt.method.AuthenticationException. 但是,当尝试检索零件信息时,出现了wt.method.AuthenticationException。

Here is the code that runs within the webService (The web service method simply calls this method) 这是在webService中运行的代码(Web服务方法仅调用此方法)

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. 此代码可在服务器上部署的命令行应用程序中工作,但在Web服务中执行此操作时将失败,并出现wt.method.AuthenticationException。 I feel it fails because the use of RemoteMethodServer is not what I should be doing since the web service is within the MethodServer. 我觉得它失败了,因为Web服务在MethodServer中,所以我不应该使用RemoteMethodServer。

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. 一个额外的问题是如何从Web服务中进行日志记录,以及如何配置此日志记录。

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 如果您遵循了文档(windchill帮助中心),则您的Web服务应使用@WebServices和@WebMethod(operationName =“ getOnePart”)进行注释,并继承com.ptc.jws.servlet.JaxWsService

Also you have to take care to the policy used during deployment. 另外,您还必须注意部署期间使用的策略。 The default ant script is configured with 默认的ant脚本配置有

security.policy=userNameAuthSymmetricKeys

So you need to manage it when you consume your ws with .Net. 因此,当您使用.Net消耗ws时,需要对其进行管理。

For logging events, you just need to call the log4j logger instantiated by default with $log.debug("Hello") 对于事件记录,您只需要调用默认情况下用$log.debug("Hello")实例化的log4j记录器$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: 不确定什么是.Net等价物,但这适用于Java客户端:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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