001: /**
002: * $Id: IWAYJCAConnection.java,v 1.1 2005/03/14 09:21:17 nk137934 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 com.sun.portal.iwayutil.connection.*;
016: import com.sun.portal.iwayutil.config.*;
017: import com.ibi.afjca.cci.*;
018: import com.ibi.afjca.spi.*;
019: import javax.resource.cci.*;
020: import java.util.logging.*;
021:
022: /**
023: * This is an implementation of an {@link IWayConnection} that
024: * can talk JCA.
025: *
026: * @author nk137934
027: * @see IWayConnection
028: * @see IWayConnectionFactory
029: */
030: public class IWAYJCAConnection implements IWAYConnection {
031:
032: private IWAFManagedConnectionFactory managedFactory;
033: private ConnectionFactory connectionFactory;
034: Logger logger = Logger.getLogger("com.sun.portal.iwayutil");
035:
036: /** Creates a new instance of IWAYJCAConnection */
037: public IWAYJCAConnection() {
038: initConnectionFactory();
039: }
040:
041: /**
042: *
043: * Implementation of the <code>getResponse</code> method of IWAYConnection interface
044: */
045: public IWAYResponse getResponse(IWAYRequest request)
046: throws IWAYConnectionException {
047: if (connectionFactory == null) {
048: throw new IWAYConnectionException(
049: "IWAFManagedConnectionFactory init failed");
050: }
051: try {
052: Connection con = connectionFactory
053: .getConnection(getConnectionSpec());
054: Interaction action = con.createInteraction();
055: IWAFInteractionSpec is = new IWAFInteractionSpec();
056: is.setFunctionName(IWAFInteractionSpec.PROCESS);
057: IndexedRecord inRec = connectionFactory.getRecordFactory()
058: .createIndexedRecord("input");
059: inRec.add(request.getRequestString());
060: IndexedRecord outRec = (IndexedRecord) action.execute(is,
061: inRec);
062: String outStr = (String) outRec.get(0);
063: //Cleanup
064: action.close();
065: con.close();
066: //
067: return new IWAYResponse(outStr);
068: } catch (Exception excp) {
069: logger.warning("Could not get Response");
070: logger.warning(excp.getMessage());
071: throw new IWAYConnectionException(excp);
072: }
073:
074: }
075:
076: private IWAFConnectionSpec getConnectionSpec() throws Exception {
077: IWAFConnectionSpec cs = new IWAFConnectionSpec();
078: cs.setAdapterName(IWAYConfiguration.getIWAYAdapterName());
079: cs.setConfig(IWAYConfiguration.getIWAYTargetName());
080: cs.setUserName(IWAYConfiguration.getIWAYUserName());
081: cs.setPassword(IWAYConfiguration.getIWAYUserPassword());
082: cs.setLogLevel(IWAYConfiguration.getIWAYDebugLevel());
083: return cs;
084: }
085:
086: /**
087: * This method creates a IWAFManagedConnectionFactory.
088: */
089: private void initConnectionFactory() {
090: try {
091: managedFactory = new IWAFManagedConnectionFactory();
092: managedFactory.setIWayHome(IWAYConfiguration
093: .getIWAYHomeDir());
094: managedFactory.setIWayConfig(IWAYConfiguration
095: .getIWAYConfigDir());
096: managedFactory.setLogLevel(IWAYConfiguration
097: .getIWAYDebugLevel());
098: connectionFactory = (ConnectionFactory) managedFactory
099: .createConnectionFactory();
100: } catch (Exception excp) {
101: logger
102: .severe("Exception in Initializing Connection Factory : "
103: + excp);
104: }
105:
106: }
107: }
|