KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > component > common > handleMessagesExchange > HandleResponses


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * Id : ${file_name} 154 ${date} rbarraza
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.component.common.handleMessagesExchange;
23
24 import java.util.Set JavaDoc;
25
26 import javax.activation.DataHandler JavaDoc;
27 import javax.jbi.JBIException;
28 import javax.jbi.messaging.ExchangeStatus;
29 import javax.jbi.messaging.Fault;
30 import javax.jbi.messaging.MessageExchange;
31 import javax.jbi.messaging.MessagingException;
32 import javax.jbi.messaging.NormalizedMessage;
33 import javax.xml.namespace.QName JavaDoc;
34 import javax.xml.transform.Source JavaDoc;
35
36 import org.objectweb.petals.component.common.util.SourceHelper;
37
38 /**
39  *
40  * @version $Rev: 250 $Date: {date}
41  * @since Petals 1.0
42  * @author Rocio BARRAZA - eBMWebsourcing
43  *
44  */

45 public class HandleResponses {
46
47     public static void faultMessageExchange(MessageExchange messageExchange,
48             Throwable JavaDoc thr, String JavaDoc code) throws JBIException {
49         Fault fault;
50         try {
51             fault = messageExchange.createFault();
52
53             // Create fault message.
54
Source JavaDoc source = SourceHelper.createContentSource(SourceHelper
55                     .createSoapFault(thr, code));
56             fault.setContent(source);
57
58             messageExchange.setFault(fault);
59             messageExchange.setStatus(ExchangeStatus.ERROR);
60
61         } catch (MessagingException e) {
62             throw new JBIException(e.getMessage());
63         }
64     }
65
66     public static void buildInMessage(MessageExchange msg, String JavaDoc mailCorps,
67             QName JavaDoc service, String JavaDoc operation, Set JavaDoc<DataHandler JavaDoc> attach)
68         throws JBIException {
69         Source JavaDoc source = null;
70         if (mailCorps != null)
71             source = SourceHelper.createSource(mailCorps);
72         NormalizedMessage nm;
73         try {
74             nm = msg.createMessage();
75             if (attach != null) {
76                 for (DataHandler JavaDoc handler : attach) {
77                     nm.addAttachment(handler.getName(), handler);
78                 }
79             }
80
81             nm.setContent(source);
82             msg.setMessage(nm, "IN");
83             msg.setService(service);
84             if (operation != null && !operation.equals("")) {
85                 msg.setOperation(new QName JavaDoc(operation));
86             }
87
88         } catch (javax.jbi.messaging.MessagingException e) {
89             throw new JBIException(e.getMessage());
90         }
91     }
92 }
93
Popular Tags