001: // Copyright (c) 2004-2005 Sun Microsystems Inc., All Rights Reserved.
002:
003: /*
004: * MessageProcessor.java
005: *
006: * SUN PROPRIETARY/CONFIDENTIAL.
007: * This software is the proprietary information of Sun Microsystems, Inc.
008: * Use is subject to license terms.
009: *
010: */
011: package com.sun.jbi.binding.file;
012:
013: import com.sun.jbi.binding.file.framework.Command;
014: import com.sun.jbi.binding.file.util.ConfigData;
015: import com.sun.jbi.binding.file.util.FileBindingUtil;
016: import com.sun.jbi.binding.file.util.StringTranslator;
017:
018: import org.w3c.dom.Element;
019:
020: import java.io.File;
021: import java.io.FileOutputStream;
022: import java.io.PrintWriter;
023:
024: import java.net.URI;
025:
026: import java.text.DateFormat;
027: import java.text.SimpleDateFormat;
028:
029: import java.util.Calendar;
030: import java.util.Date;
031: import java.util.GregorianCalendar;
032: import java.util.logging.Logger;
033:
034: import javax.jbi.messaging.DeliveryChannel;
035: import javax.jbi.messaging.ExchangeStatus;
036: import javax.jbi.messaging.Fault;
037: import javax.jbi.messaging.InOnly;
038: import javax.jbi.messaging.InOut;
039: import javax.jbi.messaging.MessageExchange;
040: import javax.jbi.messaging.MessagingException;
041: import javax.jbi.messaging.NormalizedMessage;
042: import javax.jbi.messaging.RobustInOnly;
043:
044: import javax.xml.namespace.QName;
045: import javax.xml.transform.Transformer;
046: import javax.xml.transform.TransformerFactory;
047: import javax.xml.transform.stream.StreamResult;
048:
049: /**
050: * Message Processor which parses the message received from NMR.
051: *
052: * @author Sun Microsystems, Inc.
053: */
054: public class MessageProcessor implements Command, FileBindingResources {
055: /**
056: * In Only MEP.
057: */
058: public static final String IN_ONLY = "http://www.w3.org/2004/08/wsdl/in-only";
059:
060: /**
061: * In Out MEP.
062: */
063: public static final String IN_OUT = "http://www.w3.org/2004/08/wsdl/in-out";
064:
065: /**
066: * In Optional Out MEP.
067: */
068: public static final String IN_OPTIONAL_OUT = "http://www.w3.org/2004/08/wsdl/in-opt-out";
069:
070: /**
071: * Robust In Only MEP.
072: */
073: public static final String ROBUST_IN_ONLY = "http://www.w3.org/2004/08/wsdl/robust-in-only";
074:
075: /**
076: * Out Only MEP.
077: */
078: public static final String OUT_ONLY = "http://www.w3.org/2004/08/wsdl/out-only";
079:
080: /**
081: * Out In MEP.
082: */
083: public static final String OUT_IN = "http://www.w3.org/2004/08/wsdl/out-in";
084:
085: /**
086: * Out Optional In MEP.
087: */
088: public static final String OUT_OPTIONAL_IN = "http://www.w3.org/2004/08/wsdl/out-opt-in";
089:
090: /**
091: * Robust Out Only MEP.
092: */
093: public static final String ROBUST_OUT_ONLY = "http://www.w3.org/2004/08/wsdl/robust-out-only";
094:
095: /**
096: * Out-only MEP.
097: */
098: private static final String OUTONLY = "provider";
099:
100: /**
101: * String representing property name in exchange
102: */
103: private static final String FILENAME_PROPERTY = "FILENAME";
104:
105: /**
106: * String representing property name in exchange
107: */
108: private static final String FILEEXTENSION_PROPERTY = "FILEEXTENSION";
109:
110: /**
111: * String representing default prefix
112: */
113: private static final String DEFAULT_PREFIX = "out";
114:
115: /**
116: * String representing default extension
117: */
118: private static final String DEFAULT_EXTENSION = "xml";
119:
120: /**
121: * Channel for this binding.
122: */
123: private DeliveryChannel mChannel;
124:
125: /**
126: * Registry for storing active deployments.
127: */
128: private DeploymentRegistry mRegistry;
129:
130: /**
131: * Endpoint Bean for the exhange being processed
132: */
133: private EndpointBean mEndpointBean;
134:
135: /**
136: * Excpetion.
137: */
138: private Exception mException;
139:
140: /**
141: * Logger object.
142: */
143: private Logger mLog;
144:
145: /**
146: * Message exchange object.
147: */
148: private MessageExchange mExchange;
149:
150: /**
151: * Name of file to be written out
152: */
153: private String mFileName;
154:
155: /**
156: *
157: */
158:
159: /**
160: *
161: */
162: private String mOperation;
163:
164: /**
165: * Helper for i18n.
166: */
167: private StringTranslator mTranslator;
168:
169: /**
170: * Creates a new MessageProcessor object.
171: *
172: * @param chnl binding channel.
173: * @param exchange message exchange.
174: */
175: public MessageProcessor(DeliveryChannel chnl,
176: MessageExchange exchange) {
177: mChannel = chnl;
178: mRegistry = DeploymentRegistry.getInstance();
179: mExchange = exchange;
180: mLog = FileBindingContext.getInstance().getLogger();
181: mTranslator = new StringTranslator();
182: }
183:
184: /**
185: * Util method to return current date.
186: *
187: * @return date
188: */
189: public String getDate() {
190: Calendar cal = new GregorianCalendar();
191: Date dt = cal.getTime();
192: DateFormat format = new SimpleDateFormat("ddHHmmssSS");
193: String sdate = format.format(dt);
194:
195: return sdate;
196: }
197:
198: /**
199: * Command pattern for executing in a thread pool.
200: */
201: public void execute() {
202: URI pattern = mExchange.getPattern();
203: String pat = pattern.toString().trim();
204: mOperation = mExchange.getOperation().toString();
205: setBean();
206:
207: if (mEndpointBean == null) {
208: mLog.severe(mTranslator.getString(
209: FBC_START_DEPLOYMENT_FAILED_BEANNULL, mExchange
210: .getExchangeId()));
211:
212: return;
213: }
214:
215: int role = mEndpointBean.getRole();
216:
217: if (pat.trim().equals(IN_OUT.trim())) {
218: mLog.info(mTranslator.getString(FBC_RECEIVED_INOUT,
219: mExchange.getExchangeId()));
220:
221: if (role == ConfigData.CONSUMER) {
222: processInOut((InOut) mExchange);
223: } else if (role == ConfigData.PROVIDER) {
224: mLog.info(mTranslator.getString(FBC_RECEIVED_OUTIN,
225: mExchange.getExchangeId()));
226: }
227: } else if (pat.trim().equals(IN_ONLY.trim())) {
228: mLog.info(mTranslator.getString(FBC_RECEIVED_INONLY,
229: mExchange.getExchangeId()));
230:
231: if (role == ConfigData.CONSUMER) {
232: processInOnly((InOnly) mExchange);
233: } else if (role == ConfigData.PROVIDER) {
234: processOutOnly((InOnly) mExchange);
235: }
236: } else if (pat.trim().equals(ROBUST_IN_ONLY.trim())) {
237: mLog.info(mTranslator.getString(FBC_RECEIVED_ROBUSTINONLY,
238: mExchange.getExchangeId()));
239:
240: if (role == ConfigData.CONSUMER) {
241: processRobustInOnly((RobustInOnly) mExchange);
242: } else if (role == ConfigData.PROVIDER) {
243: processRobustOutOnly((RobustInOnly) mExchange);
244: }
245: } else if (pat.trim().equals(IN_OPTIONAL_OUT.trim())) {
246: mLog.info(mTranslator.getString(FBC_RECEIVED_INOPTIONALOUT,
247: mExchange.getExchangeId()));
248: } else {
249: mLog.info(mTranslator.getString(
250: FBC_RECEIVED_UNSUPPORTED_MEP, mExchange
251: .getExchangeId()));
252: }
253: }
254:
255: /**
256: * Processes inonly message.
257: *
258: * @param inonly inony message.
259: */
260: public void processInOnly(InOnly inonly) {
261: try {
262: move();
263:
264: if (canTerminate()) {
265: return;
266: } else {
267: mLog.severe(mTranslator
268: .getString(FBC_INVALID_MESSAGE_STATE));
269: }
270: } catch (Exception me) {
271: mLog.severe(mTranslator
272: .getString(FBC_PROCESS_INONLY_FAILED));
273: mLog.severe(me.getMessage());
274: }
275: }
276:
277: /**
278: * Processes in-out message.
279: *
280: * @param inout inout message.
281: */
282: public void processInOut(InOut inout) {
283: /* This must be a response, cannot be a request , so set status
284: * and send
285: */
286: try {
287: move();
288:
289: if (canTerminate()) {
290: return;
291: }
292:
293: NormalizedMessage outmsg = inout.getOutMessage();
294: Fault fault = inout.getFault();
295: updateFileName();
296:
297: if (outmsg != null) {
298: if (writeOutMessage(outmsg)) {
299: inout.setStatus(ExchangeStatus.DONE);
300: } else {
301: inout.setStatus(ExchangeStatus.ERROR);
302: }
303: } else if (fault != null) {
304: if (writeFaultMessage(fault)) {
305: inout.setStatus(ExchangeStatus.DONE);
306: } else {
307: inout.setStatus(ExchangeStatus.ERROR);
308: }
309: } else {
310: mLog.severe(mTranslator
311: .getString(FBC_INVALID_MESSAGE_STATE));
312:
313: return;
314: }
315:
316: mChannel.send(inout);
317: } catch (MessagingException me) {
318: mLog
319: .severe(mTranslator
320: .getString(FBC_PROCESS_INOUT_FAILED));
321: mLog.severe(me.getMessage());
322: me.printStackTrace();
323: }
324: }
325:
326: /**
327: * Processes out only message.
328: *
329: * @param outonly outonly message.
330: */
331: public void processOutOnly(InOnly outonly) {
332: try {
333: if (canTerminate()) {
334: return;
335: }
336:
337: QName operation = outonly.getOperation();
338:
339: String mep = mEndpointBean.getMEP(operation.toString());
340:
341: if ((mep == null) || (!mep.trim().equals(IN_ONLY))) {
342: mLog.severe(mTranslator
343: .getString(FBC_INCONSISTENT_OPERATION)
344: + "MEP "
345: + mep
346: + " Operation : "
347: + operation.toString());
348: outonly.setError(new Exception(mTranslator
349: .getString(FBC_INCONSISTENT_OPERATION)));
350: outonly.setStatus(ExchangeStatus.ERROR);
351: } else {
352: NormalizedMessage outmsg = outonly.getInMessage();
353: updateFileName();
354:
355: if (writeOutMessage(outmsg)) {
356: outonly.setStatus(ExchangeStatus.DONE);
357: } else {
358: outonly.setStatus(ExchangeStatus.ERROR);
359: }
360: }
361:
362: mChannel.send(outonly);
363: } catch (MessagingException me) {
364: mLog.severe(mTranslator
365: .getString(FBC_PROCESS_OUTONLY_FAILED));
366: mLog.severe(me.getMessage());
367: } catch (RuntimeException re) {
368: mLog.severe(mTranslator
369: .getString(FBC_PROCESS_OUTONLY_FAILED));
370: mLog.severe(re.getMessage());
371: }
372: }
373:
374: /**
375: * Processes robust inonly messages.
376: *
377: * @param robustinonly robustinonly exchange.
378: */
379: public void processRobustInOnly(RobustInOnly robustinonly) {
380: /* This must be a response, cannot be a request , so set status
381: * and send
382: */
383: try {
384: move();
385:
386: if (canTerminate()) {
387: return;
388: }
389:
390: updateFileName();
391:
392: Fault fault = robustinonly.getFault();
393:
394: if (fault != null) {
395: if (writeFaultMessage(fault)) {
396: robustinonly.setStatus(ExchangeStatus.DONE);
397: } else {
398: robustinonly.setStatus(ExchangeStatus.ERROR);
399: }
400:
401: mChannel.send(robustinonly);
402: }
403: } catch (MessagingException me) {
404: mLog.severe(mTranslator
405: .getString(FBC_PROCESS_ROBUSTINONLY_FAILED));
406: mLog.severe(me.getMessage());
407: }
408: }
409:
410: /**
411: * Writes a error message into file.
412: *
413: * @param ex exception message.
414: *
415: * @return true if successfull, false otherwise.
416: */
417: public boolean writeErrorMessage(Exception ex) {
418: StringBuffer sb = new StringBuffer();
419: StackTraceElement[] stckTrElem = null;
420: FileOutputStream out = null;
421:
422: try {
423: out = new FileOutputStream(mFileName);
424:
425: if (ex == null) {
426: sb.append("Unknown error occurred");
427: } else {
428: sb.append(ex.getMessage());
429: stckTrElem = ex.getStackTrace();
430:
431: if (stckTrElem != null) {
432: for (int i = 0; i < stckTrElem.length; i++) {
433: String stckTrace = stckTrElem[i].toString();
434: sb.append(stckTrace);
435: sb.append("\n");
436: }
437: }
438: }
439:
440: out.write(sb.toString().getBytes());
441: out.close();
442:
443: return true;
444: } catch (Exception e) {
445: mLog.info(mTranslator.getString(FBC_FILE_WRITE_FAILED,
446: mFileName));
447: e.printStackTrace();
448: mException = e;
449:
450: return false;
451: } finally {
452: try {
453: if (out != null) {
454: out.close();
455: }
456: } catch (Exception e1) {
457: mLog.severe(mTranslator.getString(FBC_CLOSE_FAILED, e1
458: .getMessage()));
459: }
460: }
461: }
462:
463: /**
464: * Writes a fault message into file.
465: *
466: * @param msg fault message.
467: *
468: * @return true if successfull, false otherwise.
469: */
470: public boolean writeFaultMessage(Fault msg) {
471: if (msg == null) {
472: return false;
473: }
474:
475: javax.xml.transform.Source doc = msg.getContent();
476:
477: if (doc == null) {
478: mLog.severe(mTranslator.getString(FBC_CONTENT_NULL));
479:
480: return false;
481: }
482:
483: return writeMessage(doc);
484: }
485:
486: /**
487: * Writes a sucess response message into file.
488: *
489: * @param doc normalized message.
490: *
491: * @return true if successfull, false otherwise.
492: */
493: public boolean writeMessage(javax.xml.transform.Source doc) {
494: Element ele = null;
495: FileOutputStream out = null;
496: PrintWriter pw = null;
497: File f = new File(mFileName);
498:
499: try {
500: out = new FileOutputStream(f);
501:
502: TransformerFactory tFactory = TransformerFactory
503: .newInstance();
504: Transformer trans = tFactory.newTransformer();
505: trans
506: .setOutputProperty(
507: javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION,
508: "yes");
509:
510: StreamResult result = new StreamResult(out);
511: trans.transform(doc, result);
512: out.close();
513:
514: return true;
515: } catch (Exception e) {
516: mLog.severe(mTranslator.getString(FBC_FILE_WRITE_FAILED,
517: mFileName));
518: mLog.severe(e.getMessage());
519: mException = e;
520: mFileName = getBaseName(mFileName) + "."
521: + ConfigData.ERROR_EXTENSION;
522: writeErrorMessage(e);
523:
524: try {
525: if (out != null) {
526: out.close();
527: }
528:
529: f.delete();
530: } catch (Exception e1) {
531: mLog.severe(mTranslator.getString(FBC_CLOSE_FAILED, e1
532: .getMessage()));
533: }
534:
535: return false;
536: } finally {
537: try {
538: if (out != null) {
539: out.close();
540: }
541: } catch (Exception e1) {
542: mLog.severe(mTranslator.getString(FBC_CLOSE_FAILED, e1
543: .getMessage()));
544: }
545: }
546: }
547:
548: /**
549: * Writes an output message into file.
550: *
551: * @param msg normalized message.
552: *
553: * @return true if successfull, false otherwise.
554: */
555: public boolean writeOutMessage(NormalizedMessage msg) {
556: if (msg == null) {
557: return false;
558: }
559:
560: javax.xml.transform.Source doc = msg.getContent();
561:
562: if (doc == null) {
563: mLog.severe(mTranslator.getString(FBC_CONTENT_NULL));
564:
565: return false;
566: }
567:
568: return writeMessage(doc);
569: }
570:
571: /**
572: * Util method to get base name of file.
573: *
574: * @param fname file name
575: *
576: * @return base name
577: */
578: private String getBaseName(String fname) {
579: int k = fname.lastIndexOf('.');
580:
581: if (k == -1) {
582: return fname;
583: }
584:
585: if (k == 0) {
586: return "";
587: }
588:
589: return fname.substring(0, k);
590: }
591:
592: /**
593: * Finds a bean object from the message exchange parameters.
594: */
595: private void setBean() {
596: String sname = mExchange.getEndpoint().getServiceName()
597: .toString();
598: String epname = mExchange.getEndpoint().getEndpointName();
599: QName intername = mExchange.getInterfaceName();
600:
601: if ((sname == null) || (epname == null)) {
602: mLog.severe(mTranslator.getString(
603: FBC_START_DEPLOYMENT_FAILED_BEANNULL, mExchange
604: .getExchangeId()));
605:
606: return;
607: }
608:
609: // try for a provider endpoint first
610: if (mExchange.getRole().equals(MessageExchange.Role.PROVIDER)) {
611: mEndpointBean = mRegistry.findEndpoint(sname + epname);
612: } else {
613: mEndpointBean = mRegistry.findEndpoint(sname);
614:
615: /**
616: * There is a possiblity that the message was routed initially
617: * with the interface name and not the service name
618: * So we have to try an endpoint with interface name now
619: */
620:
621: if (mEndpointBean == null) {
622: if (intername != null) {
623: mEndpointBean = mRegistry
624: .findEndpointByInterface(intername
625: .toString().trim());
626: }
627: }
628: }
629:
630: if (mEndpointBean == null) {
631: mLog
632: .severe(mTranslator.getString(
633: FBC_START_DEPLOYMENT_FAILED_BEANNULL, sname
634: + " " + epname + " "
635: + mExchange.getExchangeId()));
636: }
637: }
638:
639: /**
640: * Util method to check for termination of exhcange.
641: *
642: * @return true of exchange can be terminated false othrewise.
643: */
644: private boolean canTerminate() {
645: Exception exc;
646: String sname = mExchange.getEndpoint().getServiceName()
647: .toString();
648: String epname = mExchange.getEndpoint().getEndpointName();
649:
650: if (mEndpointBean == null) {
651: mLog.severe(mTranslator.getString(
652: FBC_START_DEPLOYMENT_FAILED_BEANNULL, mExchange
653: .getExchangeId()));
654:
655: return true;
656: }
657:
658: if (mExchange.getStatus() == ExchangeStatus.DONE) {
659: mLog.info(mTranslator.getString(FBC_EXCHANGE_DONE,
660: mExchange.getExchangeId()));
661:
662: if (!mExchange.getPattern().toString().trim()
663: .equals(OUT_IN)) {
664: updateFileName();
665: writeSuccessMessage();
666: }
667:
668: return true;
669: }
670:
671: if (mExchange.getStatus() == ExchangeStatus.ERROR) {
672: mLog.info(mTranslator.getString(FBC_EXCHANGE_ERROR,
673: mExchange.getExchangeId()));
674: exc = mExchange.getError();
675: updateFileName();
676:
677: if (writeErrorMessage(exc)) {
678: mLog.info(mTranslator
679: .getString(FBC_WRITE_ERROR_SUCCESS));
680: } else {
681: mLog
682: .info(mTranslator
683: .getString(FBC_WRITE_ERROR_FAILED));
684: }
685:
686: return true;
687: }
688:
689: return false;
690: }
691:
692: /**
693: *
694: */
695: private void move() {
696: String trk = null;
697: String fn = null;
698: String ext = null;
699: QName operation = null;
700:
701: try {
702: trk = (String) mExchange
703: .getProperty(ConfigData.TRACKINGID_PROPERTY);
704: ext = (String) mExchange
705: .getProperty(ConfigData.EXTENSION_PROPERTY);
706: fn = (String) mExchange
707: .getProperty(ConfigData.FILENAME_PROPERTY);
708: operation = mExchange.getOperation();
709: } catch (Exception e) {
710: mLog.severe(mTranslator.getString(FBC_MOVE_FAILED, e
711: .getMessage()));
712: }
713:
714: if (trk == null) {
715: mLog.severe(mTranslator.getString(FBC_MOVE_FAILED,
716: mExchange.getExchangeId()));
717: } else {
718: String filepath = FileBindingUtil.getFilePath(trk);
719: String destfolder = (String) mEndpointBean
720: .getValue(ConfigData.PROCESSEDDIR);
721: String inputdir = (String) mEndpointBean
722: .getValue(ConfigData.INPUTDIR);
723: String filename = fn + "." + ext;
724: String movefilename = null;
725:
726: if (operation.toString().equals(
727: mEndpointBean.getDefaultOperation().toString())) {
728: // cud be in inputdir or in folder under the operation
729: File f = new File(inputdir + File.separator + filename);
730:
731: if (f.exists()) {
732: movefilename = inputdir + File.separator + filename;
733: } else {
734: movefilename = inputdir + File.separator
735: + operation.getLocalPart() + File.separator
736: + filename;
737: }
738: } else {
739: movefilename = inputdir + File.separator
740: + operation.getLocalPart() + File.separator
741: + filename;
742: }
743:
744: if (!FileBindingUtil
745: .moveFile(trk, destfolder, movefilename)) {
746: mLog.severe(mTranslator.getString(FBC_MOVE_FAILED,
747: filename, destfolder));
748: }
749:
750: FileBindingUtil.removeEntry(trk);
751: }
752: }
753:
754: /**
755: * Processes robust out only messages.
756: *
757: * @param robustoutonly robust out only message.
758: */
759: private void processRobustOutOnly(RobustInOnly robustoutonly) {
760: /* This must be a request , cannot be a request , so set status
761: * and send
762: */
763: try {
764: if (canTerminate()) {
765: return;
766: }
767:
768: QName operation = robustoutonly.getOperation();
769: String mep = mEndpointBean.getMEP(operation.toString());
770:
771: if ((mep == null) || (!mep.trim().equals(ROBUST_IN_ONLY))) {
772: mLog.severe(mTranslator
773: .getString(FBC_INCONSISTENT_OPERATION)
774: + "MEP "
775: + mep
776: + " Operation : "
777: + operation.toString());
778:
779: robustoutonly.setError(new Exception(mTranslator
780: .getString(FBC_INCONSISTENT_OPERATION)));
781: robustoutonly.setStatus(ExchangeStatus.ERROR);
782: } else {
783: NormalizedMessage outmsg = robustoutonly.getInMessage();
784: updateFileName();
785:
786: if (writeOutMessage(outmsg)) {
787: robustoutonly.setStatus(ExchangeStatus.DONE);
788: } else {
789: /* Have to set some error here
790: */
791: robustoutonly.setError(mException);
792: }
793: }
794:
795: mChannel.send(robustoutonly);
796: } catch (MessagingException me) {
797: mLog.severe(mTranslator
798: .getString(FBC_PROCESS_ROBUSTOUTONLY_FAILED));
799: me.printStackTrace();
800: mLog.severe(me.getMessage());
801: } catch (RuntimeException re) {
802: mLog.severe(mTranslator
803: .getString(FBC_PROCESS_ROBUSTOUTONLY_FAILED));
804: re.printStackTrace();
805: mLog.severe(re.getMessage());
806: } catch (Throwable th) {
807: th.printStackTrace();
808: }
809: }
810:
811: /**
812: * Updates the file name according to the state.
813: */
814: private void updateFileName() {
815: String prefix = null;
816: String folder = null;
817: String filename = null;
818: String extension = null;
819: String fileextension = null;
820: String trkid = null;
821: String prefixsep = null;
822: String newext = null;
823:
824: try {
825: prefix = mEndpointBean.getPrefix(mOperation);
826: folder = mEndpointBean.getValue(ConfigData.OUTPUTDIR);
827: extension = mEndpointBean.getExtension(mOperation);
828:
829: if (null == prefix) {
830: prefixsep = DEFAULT_PREFIX + ConfigData.SEPARATOR;
831: } else if (prefix.trim().equals("")) {
832: prefixsep = "";
833: } else {
834: prefixsep = prefix + ConfigData.SEPARATOR;
835: }
836:
837: if (mEndpointBean.getRole() == ConfigData.CONSUMER) {
838: filename = (String) mExchange
839: .getProperty(FILENAME_PROPERTY);
840: fileextension = (String) mExchange
841: .getProperty(FILEEXTENSION_PROPERTY);
842: trkid = (String) mExchange
843: .getProperty(ConfigData.TRACKINGID_PROPERTY);
844: }
845:
846: if (mEndpointBean.getRole() == ConfigData.PROVIDER) {
847: filename = OUTONLY;
848: trkid = FileBindingUtil.getTrackingId();
849: }
850:
851: if (null == extension) {
852: if (fileextension != null) {
853: newext = "." + fileextension;
854: } else {
855: newext = "." + DEFAULT_EXTENSION;
856: }
857: } else if (extension.trim().equals("")) {
858: newext = "";
859: } else {
860: newext = "." + extension;
861: }
862:
863: if (mExchange.getStatus() == ExchangeStatus.ERROR) {
864: mFileName = folder + File.separatorChar + prefixsep
865: + filename + ConfigData.SEPARATOR + trkid + "."
866: + ConfigData.ERROR_EXTENSION;
867: } else {
868: mFileName = folder + File.separatorChar + prefixsep
869: + filename + ConfigData.SEPARATOR + trkid
870: + newext;
871: }
872: } catch (Exception e) {
873: e.printStackTrace();
874: mFileName = folder + File.separatorChar + trkid + "."
875: + ConfigData.ERROR_EXTENSION;
876: }
877: }
878:
879: /**
880: * Writes out a success message to file.
881: */
882: private void writeSuccessMessage() {
883: FileOutputStream out = null;
884: String fname;
885: fname = getBaseName(mFileName) + "."
886: + ConfigData.DONE_EXTENSION;
887:
888: try {
889: out = new FileOutputStream(fname);
890: out.write(mTranslator.getString(FBC_DONE_MESSAGE)
891: .getBytes());
892: out.close();
893: } catch (Exception e) {
894: mLog.severe(mTranslator.getString(FBC_FILE_WRITE_FAILED,
895: fname));
896: mLog.severe(e.getMessage());
897: mException = e;
898: } finally {
899: try {
900: if (out != null) {
901: out.close();
902: }
903: } catch (Exception e1) {
904: mLog.severe(mTranslator.getString(FBC_CLOSE_FAILED, e1
905: .getMessage()));
906: }
907: }
908: }
909: }
|