001: /**
002: * $Id: IWAYJCAPropsConnection.java,v 1.2 2005/09/27 07:22:48 dh112019 Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.iwayutil.connection.jca;
014:
015: import java.util.Properties;
016: import com.sun.portal.iwayutil.connection.*;
017: import com.sun.portal.iwayutil.config.*;
018: import com.ibi.afjca.cci.*;
019: import com.ibi.afjca.spi.*;
020: import javax.resource.cci.*;
021: import com.sun.portal.iwayutil.logger.*;
022:
023: /**
024: * This is an implementation of an {@link IWayConnection} that
025: * can talk JCA.
026: *
027: * @author nk137934
028: * @see IWayConnection
029: * @see IWayConnectionFactory
030: */
031: public class IWAYJCAPropsConnection implements IWAYConnection {
032:
033: private IWAFManagedConnectionFactory managedFactory;
034: private ConnectionFactory connectionFactory;
035:
036: String iWayHome = null;
037: String iWayConfig = null;
038: String iWayLogLevel = null;
039: String iWayAdapter = null;
040: String iWayTarget = null;
041: String iWayURL = null;
042: String iWayUser = null;
043: String iWayPassword = null;
044:
045: /** Creates a new instance of IWAYJCAConnection */
046: public IWAYJCAPropsConnection(Properties props) {
047: initProperties(props);
048: initConnectionFactory();
049: }
050:
051: /**
052: *
053: * Implementation of the <code>getResponse</code> method of IWAYConnection interface
054: */
055: public IWAYResponse getResponse(IWAYRequest request)
056: throws IWAYConnectionException {
057: if (connectionFactory == null) {
058: throw new IWAYConnectionException(
059: "IWAFManagedConnectionFactory init failed");
060: }
061: try {
062: Connection con = connectionFactory
063: .getConnection(getConnectionSpec());
064: Interaction action = con.createInteraction();
065: IWAFInteractionSpec is = new IWAFInteractionSpec();
066: is.setFunctionName(IWAFInteractionSpec.PROCESS);
067: IndexedRecord inRec = connectionFactory.getRecordFactory()
068: .createIndexedRecord("input");
069: inRec.add(request.getRequestString());
070: IndexedRecord outRec = (IndexedRecord) action.execute(is,
071: inRec);
072: String outStr = (String) outRec.get(0);
073: //Cleanup
074: action.close();
075: con.close();
076: //
077: return new IWAYResponse(outStr);
078: } catch (Exception excp) {
079: System.out.println("Could not get Response");
080: System.out.println(excp.getMessage());
081: throw new IWAYConnectionException(excp);
082: }
083:
084: }
085:
086: private IWAFConnectionSpec getConnectionSpec() throws Exception {
087: IWAFConnectionSpec cs = new IWAFConnectionSpec();
088: cs.setAdapterName(iWayAdapter);
089: cs.setConfig(iWayTarget);
090: cs.setUserName(iWayUser);
091: cs.setPassword(iWayPassword);
092: cs.setLogLevel(iWayLogLevel);
093: return cs;
094: }
095:
096: /**
097: * This method creates a IWAFManagedConnectionFactory.
098: */
099: private void initConnectionFactory() {
100: try {
101: debug("initConnectionFactory",
102: "Getting IWAFManagedConnectionFactory");
103: managedFactory = new IWAFManagedConnectionFactory();
104: debug("initConnectionFactory", "setting iway home "
105: + iWayHome);
106: managedFactory.setIWayHome(iWayHome);
107: debug("initConnectionFactory", "setting iWayConfig "
108: + iWayConfig);
109: managedFactory.setIWayConfig(iWayConfig);
110: debug("initConnectionFactory", "setting iWayLogLevel "
111: + iWayLogLevel);
112: managedFactory.setLogLevel(iWayLogLevel);
113: debug("initConnectionFactory", "Getting Connection Factory");
114: connectionFactory = (ConnectionFactory) managedFactory
115: .createConnectionFactory();
116: debug("initConnectionFactory",
117: "Returning Connection Factory " + connectionFactory);
118: } catch (Exception excp) {
119: debug("initConnectionFactory",
120: "Exception in Initializing Connection Factory : "
121: + excp);
122: }
123: }
124:
125: private void initProperties(Properties props) {
126:
127: iWayHome = (String) props.get("iway.homeDir");
128: iWayConfig = (String) props.get("iway.configDir");
129: iWayLogLevel = (String) props.get("iway.logLevel");
130: iWayAdapter = (String) props.get("iway.adapterName");
131: iWayTarget = (String) props.get("iway.targetName");
132: iWayURL = (String) props.get("iway.repositoryURL");
133: iWayUser = (String) props.get("iway.userName");
134: iWayPassword = (String) props.get("iway.userPassword");
135: }
136:
137: private void debug(String methodName, String msg) {
138: EAILogger
139: .logMessage("com.sun.portal.iwayutil.connection.jca.IWAYJCAPropsConnection :"
140: + methodName + ":" + msg);
141: }
142: }
|