KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.StringWriter JavaDoc;
20
21 import javax.jbi.messaging.MessageExchange;
22 import javax.jbi.messaging.NormalizedMessage;
23 import javax.xml.stream.XMLStreamReader;
24 import javax.xml.stream.XMLStreamWriter;
25
26 import org.apache.servicemix.components.util.OutBinding;
27 import org.codehaus.activesoap.RestService;
28
29 /**
30  * Converts an inbound JBI message into an <a HREF="http://activesoap.codehaus.org/">ActiveSOAP</a>
31  * request-response and outputs the response back into JBI
32  *
33  * @version $Revision: 429277 $
34  */

35 public class ASInOutBinding extends OutBinding {
36
37     private RestService service;
38     private ASMarshaler marshaler = new ASMarshaler();
39
40     public ASInOutBinding(RestService service) {
41         this.service = service;
42     }
43
44     /**
45      * @deprecated use getMarshaler instead
46      */

47     public ASMarshaler getMarshaller() {
48         return marshaler;
49     }
50
51     /**
52      * @deprecated use setMarshaler instead
53      */

54     public void setMarshaller(ASMarshaler marshaler) {
55         this.marshaler = marshaler;
56     }
57
58     /**
59      * @return the marshaler
60      */

61     public ASMarshaler getMarshaler() {
62         return marshaler;
63     }
64
65     /**
66      * @param marshaler the marshaler to set
67      */

68     public void setMarshaler(ASMarshaler marshaler) {
69         this.marshaler = marshaler;
70     }
71
72     // Implementation methods
73
//-------------------------------------------------------------------------
74
protected void process(MessageExchange messageExchange, NormalizedMessage inMessage) throws Exception JavaDoc {
75         XMLStreamReader in = marshaler.createStreamReader(inMessage);
76
77         StringWriter JavaDoc buffer = new StringWriter JavaDoc();
78         XMLStreamWriter out = marshaler.createStreamWriter(buffer);
79
80         org.codehaus.activesoap.MessageExchange asExchange = service.createMessageExchange(in, out);
81         marshaler.fromNMS(asExchange, inMessage);
82
83         service.invoke(asExchange);
84
85         NormalizedMessage outMessage = messageExchange.createMessage();
86
87         marshaler.setContent(outMessage, buffer.toString());
88         marshaler.toNMS(outMessage, asExchange);
89
90         answer(messageExchange, outMessage);
91     }
92 }
93
Popular Tags