001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2002 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "WSIF" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 2001, 2002, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057: package org.apache.wsif.providers.jca;
058:
059: import javax.resource.*;
060: import org.apache.wsif.logging.*;
061: import org.apache.wsif.providers.*;
062: import org.apache.wsif.*;
063: import org.apache.wsif.base.*;
064: import org.apache.wsif.util.*;
065: import javax.resource.*;
066: import javax.resource.cci.*;
067: import javax.wsdl.extensions.*;
068: import javax.wsdl.*;
069: import java.net.URL;
070: import java.util.*;
071: import javax.resource.cci.*;
072: import java.io.Serializable;
073: import java.util.*;
074:
075: /**
076: * The WSIFOperation_JCA class is an implementation of the WSIFOperation interface,
077: * which is used to execute interactions with the EIS.
078: *
079: * @author Michael Beisiegel
080: * @author Piotr Przybylski <piotrp@ca.ibm.com>
081: * @author John Green
082: */
083: public class WSIFOperation_JCA implements WSIFOperation {
084:
085: private static final long serialVersionUID = 1L;
086: protected Connection fieldConnection;
087: protected InteractionSpec fieldInteractionSpec;
088: protected Definition fieldDefinition;
089: protected Binding fieldBinding;
090: protected String fieldOperationName;
091: protected String fieldInputName;
092: protected String fieldOutputName;
093: protected Operation fieldOperation;
094: protected WSIFProviderJCAExtensions fieldFactory = null;
095: private final static String crlf = System
096: .getProperty("line.separator");
097: private org.apache.wsif.providers.WSIFDynamicTypeMap fieldTypeMap;
098: private Port fieldPort;
099: private Service fieldService;
100: private WSIFPort_JCA fieldJcaPort;
101:
102: /**
103: * The WSIFOperation_JCA constructor.
104: * @param aDefinition
105: * @param aBinding
106: * @param aOperationName
107: * @param aInputName
108: * @param aOutputName
109: * @param aConnection
110: * @param aInteractionSpec
111: * @param aFactory
112: * @param typeMap
113: * @param aPort
114: * @param aService
115: * @param jcaPort
116: */
117: public WSIFOperation_JCA(Definition aDefinition, Service aService,
118: Port aPort, String aOperationName, String aInputName,
119: String aOutputName,
120: org.apache.wsif.providers.WSIFDynamicTypeMap typeMap,
121: WSIFPort_JCA jcaPort, WSIFProviderJCAExtensions aFactory,
122: Connection aConnection, InteractionSpec aInteractionSpec) {
123:
124: super ();
125: this .fieldDefinition = aDefinition;
126: this .fieldInteractionSpec = aInteractionSpec;
127: this .fieldConnection = aConnection;
128: this .fieldFactory = aFactory;
129: this .fieldBinding = aPort.getBinding();
130: this .fieldOperationName = aOperationName;
131: this .fieldInputName = aInputName;
132: this .fieldOutputName = aOutputName;
133: this .fieldTypeMap = typeMap;
134: this .fieldPort = aPort;
135: this .fieldService = aService;
136: this .fieldJcaPort = jcaPort;
137: }
138:
139: /**
140: * Invokes the request/response operation. This method
141: * <ul>
142: * <li>Updates the InteractionSpec using data from the input message.
143: * <li>If a Connection is not currently available creates one, where a
144: * ConnectionSpec can be created using data from the input message and then
145: * used when creating the Connection.
146: * <li>Uses the Connection to create a javax.resource.cci.Interaction.
147: * <li>Invokes the Interaction execute method.
148: * <li>Closes the interaction.
149: * <li>Updates the output message with InteractionSpec properties.
150: * </ul>
151: */
152: public boolean executeRequestResponseOperation(WSIFMessage input,
153: WSIFMessage output, WSIFMessage fault) throws WSIFException {
154:
155: Trc.entry(this , input, output, fault);
156: if (!input.getParts().hasNext())
157: input = null;
158: try {
159: fieldFactory.updateInteractionSpec(input, fieldBinding,
160: fieldOperationName, fieldInputName,
161: fieldOutputName, fieldInteractionSpec);
162: if (this .fieldConnection == null) {
163: this .fieldConnection = this .fieldFactory
164: .createConnection(input, this .fieldDefinition,
165: this .fieldService, this .fieldPort,
166: this .fieldTypeMap, this .fieldBinding,
167: this .fieldOperationName,
168: this .fieldInputName,
169: this .fieldOutputName);
170: fieldJcaPort.setConnection(fieldConnection);
171: }
172: Interaction interaction = this .fieldConnection
173: .createInteraction();
174: interaction.execute(this .fieldInteractionSpec,
175: (javax.resource.cci.Record) input,
176: (javax.resource.cci.Record) output);
177: interaction.close();
178: if (output instanceof WSIFMessage_JCA) {
179: ((WSIFMessage_JCA) output)
180: .setInteractionSpec(this .fieldInteractionSpec);
181: }
182: fieldFactory.updateOutputMessage(output, fieldBinding,
183: fieldOperationName, fieldInputName,
184: fieldOutputName, fieldInteractionSpec);
185: } catch (ResourceException exn1) {
186: WSIFException newExn = new WSIFException(WSIFResource_JCA
187: .get("WSIF1000E"));
188: newExn.setTargetException(exn1);
189: Trc.exception(exn1);
190: throw newExn;
191: } catch (Throwable exn3) {
192: WSIFException newExn = new WSIFException(WSIFResource_JCA
193: .get("WSIF1008E", exn3.getLocalizedMessage()));
194: newExn.setTargetException(exn3);
195: Trc.exception(newExn);
196: throw newExn;
197: }
198: Trc.exit();
199: return true;
200: }
201:
202: /**
203: * Invokes input only operation. This method
204: * <ul>
205: * <li>Updates the InteractionSpec using data from the input message.
206: * <li>If a Connection is not currently available creates one, where a
207: * ConnectionSpec can be created using data from the input message and then
208: * used when creating the Connection.
209: * <li>Uses the Connection to create a javax.resource.cci.Interaction.
210: * <li>Invokes the Interaction execute method.
211: * <li>Closes the interaction.
212: * </ul>
213: */
214: public void executeInputOnlyOperation(WSIFMessage input)
215: throws WSIFException {
216:
217: Trc.entry(this , input);
218: if (!input.getParts().hasNext())
219: input = null;
220: try {
221: fieldFactory.updateInteractionSpec(input, fieldBinding,
222: fieldOperationName, fieldInputName,
223: fieldOutputName, fieldInteractionSpec);
224: if (fieldConnection == null) {
225: fieldConnection = this .fieldFactory.createConnection(
226: input, this .fieldDefinition, this .fieldService,
227: this .fieldPort, this .fieldTypeMap,
228: this .fieldBinding, this .fieldOperationName,
229: this .fieldInputName, this .fieldOutputName);
230: fieldJcaPort.setConnection(fieldConnection);
231: }
232: Interaction interaction = fieldConnection
233: .createInteraction();
234: interaction.execute(fieldInteractionSpec,
235: (javax.resource.cci.Record) input);
236: interaction.close();
237: } catch (ResourceException exn1) {
238: WSIFException newExn = new WSIFException(WSIFResource_JCA
239: .get("WSIF1000E"));
240: Trc.exception(exn1);
241: newExn.setTargetException(exn1);
242: throw newExn;
243: } catch (Throwable exn3) {
244: WSIFException newExn = new WSIFException(WSIFResource_JCA
245: .get("WSIF1008E", exn3.getLocalizedMessage()));
246: newExn.setTargetException(exn3);
247: Trc.exception(newExn);
248: throw newExn;
249: }
250: Trc.exit();
251: }
252:
253: /**
254: * This method creates the fault message. It first attempts to use Resource Adapter specific class
255: * to create the message. If this fails (i.e. the Resource Adapter does not require specialized messages),
256: * the method creates and returns <code>WSIFMessage_JCAStreamable</code> message.
257: */
258:
259: public WSIFMessage createFaultMessage() {
260:
261: Trc.entry(this );
262: WSIFMessage message = this .fieldFactory.createFaultMessage(
263: this .fieldDefinition, this .fieldBinding,
264: this .fieldOperationName, this .fieldInputName,
265: this .fieldOutputName);
266: if (message != null)
267: return message;
268: return new WSIFMessage_JCAStreamable(this .fieldDefinition,
269: this .fieldBinding, this .fieldOperationName,
270: this .fieldInputName, this .fieldOutputName,
271: WSIFMessage_JCA.FAULT_MESSAGE);
272: }
273:
274: /**
275: * This method creates the fault message with specific name. It first attempts to use Resource Adapter specific class
276: * to create message. If this fails (i.e. the Resource Adapter does not require specialized messages),
277: * the method creates and returns <code>WSIFMessage_JCAStreamable</code> message.
278: */
279: public WSIFMessage createFaultMessage(String name) {
280:
281: Trc.entry(this , name);
282:
283: WSIFMessage message = this .fieldFactory.createFaultMessage(
284: this .fieldDefinition, this .fieldBinding,
285: this .fieldOperationName, this .fieldInputName,
286: this .fieldOutputName);
287: if (message != null) {
288: message.setName(name);
289: return message;
290: }
291: message = new WSIFMessage_JCAStreamable(this .fieldDefinition,
292: this .fieldBinding, this .fieldOperationName,
293: this .fieldInputName, this .fieldOutputName,
294: WSIFMessage_JCA.FAULT_MESSAGE);
295: message.setName(name);
296: return message;
297: }
298:
299: /**
300: * This method creates the input message. It first attempts to use Resource Adapter specific class
301: * to create message. If this fails (i.e. the Resource Adapter does not require specialized messages),
302: * the method creates and returns <code>WSIFMessage_JCAStreamable</code> message.
303: */
304: public WSIFMessage createInputMessage() {
305:
306: Trc.entry(this );
307: WSIFMessage message = this .fieldFactory.createInputMessage(
308: this .fieldDefinition, this .fieldBinding,
309: this .fieldOperationName, this .fieldInputName,
310: this .fieldOutputName);
311: if (message != null)
312: return message;
313: return new WSIFMessage_JCAStreamable(this .fieldDefinition,
314: this .fieldBinding, this .fieldOperationName,
315: this .fieldInputName, this .fieldOutputName,
316: WSIFMessage_JCA.INPUT_MESSAGE);
317: }
318:
319: /**
320: * This method creates the input message with specific name. It first attempts to use Resource Adapter specific class
321: * to create message. If this fails (i.e. the Resource Adapter does not require specialized messages),
322: * the method creates and returns <code>WSIFMessage_JCAStreamable</code> message.
323: */
324: public WSIFMessage createInputMessage(String name) {
325:
326: Trc.entry(this , name);
327: WSIFMessage message = this .fieldFactory.createInputMessage(
328: this .fieldDefinition, this .fieldBinding,
329: this .fieldOperationName, this .fieldInputName,
330: this .fieldOutputName);
331: if (message != null) {
332: message.setName(name);
333: return message;
334: }
335: message = new WSIFMessage_JCAStreamable(this .fieldDefinition,
336: this .fieldBinding, this .fieldOperationName,
337: this .fieldInputName, this .fieldOutputName,
338: WSIFMessage_JCA.INPUT_MESSAGE);
339: message.setName(name);
340: return message;
341: }
342:
343: /**
344: * This method creates the output message. It first attempts to use Resource Adapter specific class
345: * to create message. If this fails (i.e. the Resource Adapter does not require specialized messages),
346: * the method creates and returns <code>WSIFMessage_JCAStreamable</code> message.
347: */
348: public WSIFMessage createOutputMessage() {
349:
350: Trc.entry(this );
351: WSIFMessage message = this .fieldFactory.createOutputMessage(
352: this .fieldDefinition, this .fieldBinding,
353: this .fieldOperationName, this .fieldInputName,
354: this .fieldOutputName);
355: if (message != null)
356: return message;
357: return new WSIFMessage_JCAStreamable(this .fieldDefinition,
358: this .fieldBinding, this .fieldOperationName,
359: this .fieldInputName, this .fieldOutputName,
360: WSIFMessage_JCA.OUTPUT_MESSAGE);
361: }
362:
363: /**
364: * This method creates the output message with specific name. It first attempts to use Resource Adapter specific class
365: * to create message. If this fails (i.e. the Resource Adapter does not require specialized messages),
366: * the method creates and returns <code>WSIFMessage_JCAStreamable</code> message.
367: */
368: public WSIFMessage createOutputMessage(String name) {
369:
370: Trc.entry(this , name);
371: WSIFMessage message = this .fieldFactory.createOutputMessage(
372: this .fieldDefinition, this .fieldBinding,
373: this .fieldOperationName, this .fieldInputName,
374: this .fieldOutputName);
375: if (message != null) {
376: message.setName(name);
377: return message;
378: }
379: message = new WSIFMessage_JCAStreamable(this .fieldDefinition,
380: this .fieldBinding, this .fieldOperationName,
381: this .fieldInputName, this .fieldOutputName,
382: WSIFMessage_JCA.OUTPUT_MESSAGE);
383: message.setName(name);
384: return message;
385: }
386:
387: /**
388: * Returns the interactionSpec.
389: * @return Returns a InteractionSpec
390: */
391: public InteractionSpec getInteractionSpec() {
392: return fieldInteractionSpec;
393: }
394:
395: /**
396: * Sets the interactionSpec.
397: * @param interactionSpec The interactionSpec to set
398: */
399: public void setInteractionSpec(InteractionSpec interactionSpec) {
400: fieldInteractionSpec = interactionSpec;
401: }
402:
403: public String toString() {
404:
405: StringBuffer buffer = new StringBuffer();
406: buffer.append(crlf + "[JCAOperation" + crlf);
407: try {
408: if (fieldConnection != null)
409: buffer.append("\tConnection: "
410: + fieldConnection.toString() + crlf);
411: else
412: buffer.append("\tConnection: null" + crlf);
413:
414: if (fieldInteractionSpec != null)
415: buffer.append("\tInteractionSpec: "
416: + fieldInteractionSpec.toString() + crlf);
417: else
418: buffer.append("\tInteractionSpec: null" + crlf);
419:
420: if (fieldBinding != null)
421: buffer.append("\tBinding: "
422: + fieldBinding.toString() + crlf);
423: else
424: buffer.append("\tBinding: null" + crlf);
425:
426: if (fieldOperation != null)
427: buffer.append("\tOperation: "
428: + fieldOperation.toString() + crlf);
429: else
430: buffer.append("\tOperation: null" + crlf);
431:
432: if (fieldFactory != null)
433: buffer.append("\tFactory: "
434: + fieldFactory.toString() + crlf);
435: else
436: buffer.append("\tFactory: null" + crlf);
437:
438: if (fieldOperationName != null)
439: buffer.append("\tOperationName: "
440: + fieldOperationName + crlf);
441: else
442: buffer.append("\tOperationName: null" + crlf);
443:
444: if (fieldInputName != null)
445: buffer.append("\tInputName: " + fieldInputName
446: + crlf);
447: else
448: buffer.append("\tInputName: null" + crlf);
449:
450: if (fieldOutputName != null)
451: buffer.append("\tOutputName: " + fieldOutputName
452: + crlf);
453: else
454: buffer.append("\tOutputName: null" + crlf);
455:
456: buffer.append("]" + crlf);
457: } catch (Throwable exn) {
458: }
459: return buffer.toString();
460: }
461:
462: /**
463: * Method not supported.
464: */
465: public WSIFCorrelationId executeRequestResponseAsync(
466: WSIFMessage input, WSIFResponseHandler handler)
467: throws WSIFException {
468: return null;
469: }
470:
471: /**
472: * Method not supported.
473: */
474: public WSIFCorrelationId executeRequestResponseAsync(
475: WSIFMessage input) throws WSIFException {
476: return null;
477: }
478:
479: /**
480: * Method not supported.
481: */
482: public void fireAsyncResponse(Object response) throws WSIFException {
483:
484: }
485:
486: /**
487: * Method not supported.
488: */
489: public boolean processAsyncResponse(Object response,
490: WSIFMessage output, WSIFMessage fault) throws WSIFException {
491: return false;
492: }
493:
494: /**
495: * Method not supported.
496: */
497: public void setContext(WSIFMessage context) {
498:
499: }
500:
501: /**
502: * Method not supported.
503: */
504: public WSIFMessage getContext() {
505:
506: return null;
507: }
508:
509: }
|