Teamcenter之SOA入门

1、 准备soa_client.zip,在下载的tc安装包里面(安装后的目录里面没有),下载需要西门子GTAC账号密码信息,可以找实施人员索取。
2、 soa_client\java\libs下即是soa开发所需的所有jar;soa_client\java\samples下即是示例工程,平时所有可参考HelloTeamcenter工程。
3、 直接新建Java工程MySoaProject,拷贝HelloTeamcenter工程的src到MySoaProject的src,将jar包引入。
4、打开hello
Teamcenter之SOA入门_第1张图片

=====================================================
我给AppXSession类加了个重载方法

public User login(String user,String pw)
    {
        // Get the service stub
        SessionService sessionService = SessionService.getService(connection);

        try
        {
            // Prompt for credentials until they are right, or until user
            // cancels
            String[] credentials = credentialManager.promptForCredentials(user,pw);
            while (true)
            {
                try
                {

                    // *****************************
                    // Execute the service operation
                    // *****************************
                    LoginResponse out = sessionService.login(credentials[0], credentials[1],
                            credentials[2], credentials[3],"", credentials[4]);

                    return out.user;
                }
                catch (InvalidCredentialsException e)
                {
                    credentials = credentialManager.getCredentials(e);
                }
            }
        }
        // User canceled the operation, don't need to tell him again
        catch (CanceledOperationException e) {}

        // Exit the application
        System.exit(0);
        return null;
    }

hello中进行登录

//==================================================
//
//  Copyright 2012 Siemens Product Lifecycle Management Software Inc. All Rights Reserved.
//
//==================================================

package com.teamcenter.hello;

import com.teamcenter.clientx.AppXSession;
import com.teamcenter.soa.client.model.strong.User;
import com.teamcenter.soa.exceptions.NotLoadedException;



/**
 * This sample client application demonstrates some of the basic features of the
 * Teamcenter Services framework and a few of the services.
 *
 * An instance of the Connection object is created with implementations of the
 * ExceptionHandler, PartialErrorListener, ChangeListener, and DeleteListeners
 * intefaces. This client application performs the following functions:
 * 1. Establishes a session with the Teamcenter server
 * 2. Display the contents of the Home Folder
 * 3. Performs a simple query of the database
 * 4. Create, revise, and delete an Item
 *
 */
public class Hello
{

    /**
     * @param args   -help or -h will print out a Usage statement
     */
    public static void main(String[] args)
    {
//    	args = new String[]{"-help"};
        if (args.length > 0)
        {
            if (args[0].equals("-help") || args[0].equals("-h"))
            {
                System.out.println("usage: java [-Dhost=http://server:port/tc] com.teamcenter.hello.Hello");
                System.exit(0);
            }
        }

        // Get optional host information
//        String serverHost = "http://localhost:7001/tc";
        String serverHost = "http://10.10.130.119:7001/tc";
//        String host = System.getProperty("host");
//        if (host != null && host.length() > 0)
//        {
//            serverHost = host;
//            System.out.println(serverHost);
//        }

        
    	

        AppXSession   session = new AppXSession(serverHost);
        HomeFolder   home = new HomeFolder();
        Query       query = new Query();
        DataManagement dm = new DataManagement();

        // Establish a session with the Teamcenter Server
        User user = session.login("hand123","hand123");
        System.out.println("user:"+user);

        // Using the User object returned from the login service request
        // display the contents of the Home Folder
        home.listHomeFolder(user);

        // Perform a simple query of the database
        query.queryItems();

        // Perform some basic data management functions
        dm.createReviseAndDelete();

        // Terminate the session with the Teamcenter server
        session.logout();

    }
}

你可能感兴趣的:(teamcenter)