KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > activesoap > ASTransport


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.components.activesoap;
18
19 import org.codehaus.activesoap.transport.Invocation;
20 import org.codehaus.activesoap.transport.TransportClient;
21 import org.codehaus.activesoap.util.XMLStreamFactory;
22
23 import javax.jbi.messaging.DeliveryChannel;
24 import javax.jbi.messaging.Fault;
25 import javax.jbi.messaging.InOnly;
26 import javax.jbi.messaging.InOut;
27 import javax.jbi.messaging.MessageExchangeFactory;
28 import javax.jbi.messaging.NormalizedMessage;
29 import javax.xml.stream.XMLStreamReader;
30 import java.io.Reader JavaDoc;
31
32 /**
33  * An <a HREF="http://activesoap.codehaus.org/">ActiveSOAP</a> transport which uses JBI.
34  *
35  * @version $Revision: 426415 $
36  */

37 public class ASTransport implements TransportClient {
38
39     private ASMarshaler marshaler = new ASMarshaler();
40
41
42     private DeliveryChannel channel;
43     private XMLStreamFactory streamFactory;
44
45     public ASTransport(DeliveryChannel channel) {
46         this(channel, new XMLStreamFactory());
47     }
48
49     public ASTransport(DeliveryChannel channel, XMLStreamFactory streamFactory) {
50         this.channel = channel;
51         this.streamFactory = streamFactory;
52     }
53
54     public Invocation createInvocation() {
55         return new ASInvocation(this, streamFactory);
56     }
57
58     public void invokeOneWay(Invocation invocation, Reader request) throws Exception JavaDoc {
59         throw new UnsupportedOperationException JavaDoc("Should never be invoked directly");
60     }
61
62     public Reader invokeRequest(Invocation invocation, Reader request) throws Exception JavaDoc {
63         throw new UnsupportedOperationException JavaDoc("Should never be invoked directly");
64     }
65
66     public void close() throws Exception JavaDoc {
67         channel.close();
68     }
69
70     public void invokeOneWay(ASInvocation invocation, String JavaDoc xml) throws Exception JavaDoc {
71         MessageExchangeFactory fac = channel.createExchangeFactory();
72         InOnly exchange = fac.createInOnlyExchange();
73         NormalizedMessage inMessage = exchange.createMessage();
74         marshaler.setContent(inMessage, xml);
75         exchange.setInMessage(inMessage);
76         channel.send(exchange);
77     }
78
79     public XMLStreamReader invokeRequest(ASInvocation invocation, String JavaDoc xml) throws Exception JavaDoc {
80         MessageExchangeFactory fac = channel.createExchangeFactory();
81         InOut exchange = fac.createInOutExchange();
82         NormalizedMessage inMessage = exchange.createMessage();
83         marshaler.setContent(inMessage, xml);
84         exchange.setInMessage(inMessage);
85         boolean answer = channel.sendSync(exchange);
86         if (answer) {
87             NormalizedMessage outMessage = exchange.getOutMessage();
88             return marshaler.createStreamReader(outMessage);
89         }
90         else {
91             Fault fault = exchange.getFault();
92             return marshaler.createStreamReader(fault);
93         }
94     }
95 }
96
Popular Tags