source: EDIS/tags/ed/tracking-server-vista/src/test/java/gov/va/med/edp/springframework/security/userdetails/vistalink/Foo.java@ 1240

Last change on this file since 1240 was 1240, checked in by George Lilly, 13 years ago

new version from the VA

File size: 5.5 KB
Line 
1package gov.va.med.edp.springframework.security.userdetails.vistalink;
2
3import gov.va.med.edp.vistalink.ConnectionFactoryLocator;
4import gov.va.med.edp.vistalink.VistaLinkTemplate;
5import gov.va.med.edp.springframework.security.userdetails.vistalink.VistaLinkAccessVerifyConnectionSpec;
6import gov.va.med.vistalink.adapter.cci.VistaLinkConnection;
7import gov.va.med.vistalink.adapter.spi.EMAdapterEnvironment;
8import gov.va.med.vistalink.adapter.spi.VistaLinkManagedConnectionFactory;
9import gov.va.med.vistalink.rpc.RpcRequest;
10import gov.va.med.vistalink.rpc.RpcRequestFactory;
11import gov.va.med.vistalink.rpc.RpcResponse;
12import org.springframework.dao.DataAccessException;
13import org.springframework.dao.DataAccessResourceFailureException;
14import org.springframework.jca.cci.core.CciTemplate;
15import org.springframework.jca.cci.core.ConnectionCallback;
16import org.springframework.jca.support.LocalConnectionFactoryBean;
17import org.springframework.util.Assert;
18
19import javax.resource.ResourceException;
20import javax.resource.cci.Connection;
21import javax.resource.cci.ConnectionFactory;
22import java.net.InetAddress;
23import java.sql.SQLException;
24import java.util.ArrayList;
25import java.util.List;
26
27public class Foo {
28 private static final String RPC_CONTEXT = "XUS KAAJEE WEB LOGON";
29 private static final String GET_USER_INFO_RPC = "XUS KAAJEE GET USER INFO";
30 private static final String LOGOUT_RPC_NAME = "XUS KAAJEE LOGOUT";
31
32 public static void main(String[] args) throws Exception {
33 VistaLinkManagedConnectionFactory mcf = new VistaLinkManagedConnectionFactory() {
34 protected String getPrimaryStation() {
35 return "442";
36 }
37 };
38 mcf.setNonManagedHostIPAddress("vhaislbll2.vha.med.va.gov");
39 mcf.setNonManagedHostPort(8014);
40 mcf.setNonManagedAccessCode("7eGAcrar");
41 mcf.setNonManagedVerifyCode("wU67YUhe.");
42 mcf.setAdapterEnvironment(EMAdapterEnvironment.J2EE);
43
44 LocalConnectionFactoryBean cfb = new LocalConnectionFactoryBean();
45 cfb.setManagedConnectionFactory(mcf);
46 cfb.afterPropertiesSet();
47
48 final ConnectionFactory cf = (ConnectionFactory) cfb.getObject();
49
50 // login
51 CciTemplate t = new CciTemplate(cf, new VistaLinkAccessVerifyConnectionSpec("442", "10VEHU", "VEHU20", InetAddress.getLocalHost().getHostAddress()));
52 RpcResponse response = (RpcResponse) t.execute(new ConnectionCallback() {
53 public Object doInConnection(Connection connection, ConnectionFactory connectionFactory) throws ResourceException, SQLException, DataAccessException {
54 Assert.isInstanceOf(VistaLinkConnection.class, connection);
55 VistaLinkConnection conn = (VistaLinkConnection) connection;
56
57 try {
58 RpcRequest vReq = RpcRequestFactory.getRpcRequest();
59 vReq.setRpcContext(RPC_CONTEXT);
60 vReq.setRpcClientTimeOut(600);
61 vReq.setUseProprietaryMessageFormat(true);
62 vReq.setRpcName(GET_USER_INFO_RPC);
63 vReq.getParams().setParam(1, "string", InetAddress.getLocalHost().getHostAddress());
64 vReq.getParams().setParam(2, "string,", "EDIS Tracking Board");
65 return conn.executeRPC(vReq);
66 } catch (Exception e) {
67 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
68 return null;
69 }
70 }
71 });
72 /*
73 * ; Result(0) is the users DUZ.
74 * ; Result(1) is the user name from the .01 field.
75 * ; Result(2) is the users full name from the name standard file.
76 * ; Result(3) is the FAMILY (LAST) NAME (or ^ if null)
77 * ; Result(4) is the GIVEN (FIRST) NAME (or ^ if null)
78 * ; Result(5) is the MIDDLE NAME (or ^ if null)
79 * ; Result(6) is the PREFIX (or ^ if null)
80 * ; Result(7) is the SUFFIX (or ^ if null)
81 * ; Result(8) is the DEGREE (or ^ if null)
82 * ; Result(9) is station # of the division that the user is working in.
83 * ; Result(10) is the station # of the parent facility for the login division
84 * ; Result(11) is the station # of the computer system "parent" from the KSP file.
85 * ; Result(12) is the IEN of the signon log entry
86 * ; Result(13) = # of permissible divisions
87 * ; Result(14-n) are the permissible divisions for user login, in the format:
88 * ; IEN of file 4^Station Name^Station Number^default? (1 or 0)
89 */
90 System.out.println("<-->");
91 System.out.println(response.getRawResponse());
92 System.out.println("<-->");
93 String result = response.getResults();
94 String[] results = result.split("\n");
95 System.out.println(results[0] + ":" + results[9] + ":" + results[12]);
96
97 // call an RPC
98 VistaLinkTemplate t2 = new VistaLinkTemplate(new ConnectionFactoryLocator() {
99 public ConnectionFactory getConnectionFactory(String stationNumber) throws DataAccessResourceFailureException {
100 return cf;
101 }
102 });
103// System.out.println(t2.rpcAsUser("442", "20012", "", ""));
104
105 // logout
106 t2.setTimeOut(600);
107 List params = new ArrayList();
108 params.add(results[12]);
109 t2.rpcAsUser("442", "20012", RPC_CONTEXT, LOGOUT_RPC_NAME, params);
110 }
111}
Note: See TracBrowser for help on using the repository browser.