KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > jbi > serviceengine > bridge > transport > NMRClientConnection


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.jbi.serviceengine.bridge.transport;
24
25 import com.sun.enterprise.deployment.ServiceRefPortInfo;
26 import com.sun.enterprise.jbi.serviceengine.ServiceEngineException;
27 import com.sun.enterprise.jbi.serviceengine.util.soap.MessageExchangeHelper;
28 import javax.jbi.messaging.ExchangeStatus;
29 import javax.xml.soap.SOAPMessage JavaDoc;
30
31
32 /**
33  *
34  * @author Manisha Umbarje
35  */

36 public class NMRClientConnection extends NMRConnection{
37     
38     //private QName svcQName;
39
private boolean oneWay;
40     private ServiceRefPortInfo portInfo;
41     
42     private MessageExchangeHelper meHelper;
43     /** Creates a new instance of NMRClientConnection */
44     
45     public NMRClientConnection(ServiceRefPortInfo portInfo, boolean oneWay) {
46         meHelper = new MessageExchangeHelper();
47         //setServiceQName(serviceQName);
48
setOneWay(oneWay);
49         setServicePortInfo(portInfo);
50     }
51     
52     /*public void setServiceQName(QName serviceQName) {
53         this.svcQName = serviceQName;
54     }*/

55     
56     
57     public void setOneWay(boolean oneWay) {
58         this.oneWay = oneWay;
59     }
60     
61     public void setServicePortInfo(ServiceRefPortInfo portInfo) {
62         this.portInfo = portInfo;
63     }
64     
65     public void closeOutput() {
66         try {
67             SOAPMessage JavaDoc incomingMessage = createSOAPMessageFromOutputStream();
68             
69             meHelper.initializeMessageExchange(portInfo, incomingMessage);
70             meHelper.normalizeMessage(incomingMessage, true);
71             meHelper.dispatchMessage();
72             
73             if(meHelper.isInOutMessageExchange()) {
74                 handleResponse();
75             }
76         } catch (Exception JavaDoc ex) {
77             ex.printStackTrace();
78             throw new RuntimeException JavaDoc(ex);
79         }
80     }
81     
82      public void handleResponse()
83     throws ServiceEngineException {
84         createSOAPMessageInputStream(meHelper.denormalizeMessage(false));
85
86         // Send the status back to the provider.
87
try {
88             ExchangeStatus currentStatus = meHelper.getMessageExchange().getStatus();
89             /**
90              * JBI 1.0 spec section #5.4.2.4 : If Provider has sent either message or fault,
91              * then Consumer needs to send the status (DONE) back to provider to complete the exchange.
92              */

93             if(!ExchangeStatus.ERROR.equals(currentStatus)) {
94                 meHelper.getMessageExchange().setStatus(ExchangeStatus.DONE);
95                 meHelper.dispatchMessage();
96             }
97         } catch(Exception JavaDoc e) {
98            throw new ServiceEngineException(e);
99         }
100         
101     }
102     
103 }
104
Popular Tags