KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > soap > skeleton > RpcAction


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.soap.skeleton;
31
32 import com.caucho.jaxb.JAXBContextImpl;
33 import com.caucho.util.L10N;
34
35 import javax.xml.bind.JAXBException;
36 import javax.xml.bind.Marshaller;
37 import javax.xml.bind.Unmarshaller;
38 import javax.xml.ws.WebServiceException;
39 import java.lang.reflect.Method JavaDoc;
40 import java.util.Map JavaDoc;
41 import java.util.logging.Logger JavaDoc;
42
43 /**
44  * Invokes a SOAP request on a Java POJO method
45  */

46 public class RpcAction extends AbstractAction {
47   private final static Logger JavaDoc log = Logger.getLogger(RpcAction.class.getName());
48   public static final L10N L = new L10N(RpcAction.class);
49
50   private static final String JavaDoc TARGET_NAMESPACE_PREFIX = "tns";
51
52   public RpcAction(Method JavaDoc method,
53                    JAXBContextImpl jaxbContext,
54                    String JavaDoc targetNamespace,
55                    Marshaller marshaller,
56                    Unmarshaller unmarshaller)
57     throws JAXBException, WebServiceException
58   {
59     super(method, jaxbContext, targetNamespace);
60
61     /*
62
63     // WSDL message name
64     String messageName = DirectSkeleton.getWebServiceName(cl) + "_" +
65                          _methodName;
66
67     _inputMessage.setName(messageName);
68     _outputMessage.setName(messageName + "Response");
69
70     _wsdlOperation.setName(_methodName);
71     _wsdlBindingOperation.setName(_methodName);
72
73     SOAPBody soapBody = new SOAPBody();
74     soapBody.addEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");
75     soapBody.setUse(SOAPUseChoice.LITERAL);
76     soapBody.setNamespace(targetNamespace);
77
78     WSDLBindingOperationMessage bindingInput =
79       new WSDLBindingOperationMessage();
80     bindingInput.addAny(soapBody);
81     _wsdlBindingOperation.setInput(bindingInput);
82
83     WSDLBindingOperationMessage bindingOutput =
84       new WSDLBindingOperationMessage();
85     bindingOutput.addAny(soapBody);
86     _wsdlBindingOperation.setOutput(bindingOutput);
87
88     SOAPOperation soapOperation = new SOAPOperation();
89     soapOperation.setSoapAction("");
90     _wsdlBindingOperation.addAny(soapOperation);
91
92     _jaxbContext = jaxbContext;
93
94     //
95     // Create wrappers for input and output parameters
96     //
97     
98     switch (_jaxbStyle) {
99       case DOCUMENT_BARE:
100         prepareDocumentBareParameters();
101         break;
102
103       case DOCUMENT_WRAPPED:
104         prepareDocumentWrappedParameters();
105         break;
106
107       case RPC:
108         prepareDocumentWrappedParameters();
109         break;
110     }
111
112     for (int i = 0; i < params.length; i++) {
113       boolean isInput = true;
114       WSDLPart part = new WSDLPart();
115
116       String localName = "arg" + i; // As per JAX-WS spec
117
118       for(Annotation a : annotations[i]) {
119         if (a instanceof WebParam) {
120           WebParam webParam = (WebParam) a;
121
122           if (! "".equals(webParam.name()))
123             localName = webParam.name();
124
125           if ("".equals(webParam.targetNamespace()))
126             _argMarshall[i]._name = new QName(localName);
127           else
128             _argMarshall[i]._name =
129               new QName(localName, webParam.targetNamespace());
130
131           if (params[i].equals(Holder.class)) {
132             _argMarshall[i]._mode = webParam.mode();
133
134             if (_argMarshall[i]._mode == WebParam.Mode.OUT)
135               isInput = false;
136           }
137         }
138       }
139
140       part.setName(localName);
141       part.setType(marshall.getXmlSchemaDatatype());
142
143       if (isInput) {
144         _inputMessage.addPart(part);
145         _wsdlOperation.addParameterOrder(localName);
146       }
147       else {
148         _outputMessage.addPart(part);
149         _inputArgumentCount--;
150       }
151
152       argNames.put(localName, _argMarshall[i]);
153     }
154
155     WSDLOperationInput opInput = new WSDLOperationInput();
156     opInput.setMessage(new QName(targetNamespace,
157                                  _inputMessage.getName(),
158                                  TARGET_NAMESPACE_PREFIX));
159     _wsdlOperation.addOperationPart(opInput);
160
161     WSDLOperationOutput opOutput = new WSDLOperationOutput();
162     opOutput.setMessage(new QName(targetNamespace,
163                                   _outputMessage.getName(),
164                                   TARGET_NAMESPACE_PREFIX));
165     _wsdlOperation.addOperationPart(opOutput);
166
167     // XXX Can input/output messages have no parts?
168
169     _retMarshall =
170       factory.createSerializer(method.getReturnType(), _jaxbContext);
171
172     if (method.isAnnotationPresent(WebResult.class))
173       _resultName =
174         new QName(method.getAnnotation(WebResult.class).targetNamespace(),
175                   method.getAnnotation(WebResult.class).name());
176     else
177       _resultName = new QName("return");
178
179     if (! method.getReturnType().equals(Void.class) &&
180         ! method.getReturnType().equals(void.class)) {
181       WSDLPart part = new WSDLPart();
182       part.setName(_resultName.getLocalPart());
183       part.setType(_retMarshall.getXmlSchemaDatatype());
184       _outputMessage.addPart(part);
185     }
186     */

187
188     //
189
// Exceptions -> Faults
190
//
191

192     // XXX
193
/*Class[] exceptions = getExceptionTypes();
194
195     for (Class exception : exceptions)
196       exceptionToFault(exception);
197       */

198   }
199 }
200
Popular Tags