KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > soa > encoding > SoapEncoding


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Emil Ong
28  */

29
30 package com.caucho.soa.encoding;
31
32 import com.caucho.soap.reflect.WebServiceIntrospector;
33 import com.caucho.soap.skeleton.DirectSkeleton;
34
35 import javax.annotation.PostConstruct;
36 import javax.xml.bind.JAXBException;
37 import javax.xml.stream.XMLInputFactory;
38 import javax.xml.stream.XMLOutputFactory;
39 import javax.xml.stream.XMLStreamReader;
40 import javax.xml.stream.XMLStreamWriter;
41 import java.io.IOException JavaDoc;
42 import java.io.InputStream JavaDoc;
43 import java.io.OutputStream JavaDoc;
44 import java.util.logging.Logger JavaDoc;
45
46 /**
47  * Invokes a service based on a Hessian-encoded request.
48  */

49 public class SoapEncoding implements ServiceEncoding {
50   private static final Logger JavaDoc log =
51     Logger.getLogger(SoapEncoding.class.getName());
52
53   private Object JavaDoc _object;
54   private Class JavaDoc _class;
55   private DirectSkeleton _skeleton;
56   private String JavaDoc _wsdlLocation;
57
58   public void setService(Object JavaDoc service)
59   {
60     _object = service;
61
62     if (_class == null)
63       _class = service.getClass();
64   }
65
66   public void setInterface(Class JavaDoc cl)
67   {
68     _class = cl;
69   }
70
71   @PostConstruct
72   public void init()
73   {
74   }
75
76   public void invoke(InputStream JavaDoc is, OutputStream JavaDoc os)
77     throws Throwable JavaDoc
78   {
79     XMLInputFactory inputFactory = XMLInputFactory.newInstance();
80     XMLStreamReader in = inputFactory.createXMLStreamReader(is);
81
82     XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
83     XMLStreamWriter out = outputFactory.createXMLStreamWriter(os);
84
85     getSkeleton().invoke(_object, in, out);
86
87     out.flush();
88   }
89
90   private DirectSkeleton getSkeleton()
91     throws JAXBException, IOException JavaDoc
92   {
93     if (_skeleton == null) {
94       _skeleton =
95         new WebServiceIntrospector().introspect(_class, _wsdlLocation);
96     }
97
98     return _skeleton;
99   }
100 }
101
Popular Tags