001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.rpc.client;
020:
021: import org.apache.axiom.om.OMElement;
022: import org.apache.axis2.AxisFault;
023: import org.apache.axis2.client.ServiceClient;
024: import org.apache.axis2.client.async.Callback;
025: import org.apache.axis2.client.async.AxisCallback;
026: import org.apache.axis2.context.ConfigurationContext;
027: import org.apache.axis2.databinding.utils.BeanUtil;
028: import org.apache.axis2.description.AxisService;
029: import org.apache.axis2.engine.DefaultObjectSupplier;
030:
031: import javax.xml.namespace.QName;
032: import java.net.URL;
033:
034: public class RPCServiceClient extends ServiceClient {
035:
036: private boolean notNullService;
037:
038: public RPCServiceClient(ConfigurationContext configContext,
039: AxisService service) throws AxisFault {
040: super (configContext, service);
041: if (service != null) {
042: notNullService = true;
043: }
044: }
045:
046: public RPCServiceClient() throws AxisFault {
047: super ();
048: }
049:
050: public RPCServiceClient(ConfigurationContext configContext,
051: URL wsdlURL, QName wsdlServiceName, String portName)
052: throws AxisFault {
053: super (configContext, wsdlURL, wsdlServiceName, portName);
054: notNullService = true;
055: }
056:
057: /**
058: * Return value can be a single a object or an object array (itself an object) , but it is
059: * difficulty to figure the return object correctly unless we have TyepMapping in the client
060: * side too. Until it is finalized lets return OMElement as return value. And the retuen value
061: * will be the body first element user has to deal with that and create his own object out of
062: * that.
063: *
064: * @param opName Operation QName (to get the body wrapper element)
065: * @param args Arraylist of objects
066: * @return Response OMElement
067: * @throws AxisFault in case of a problem - this can either be a processing fault or a received
068: * on-the-wire fault.
069: */
070: public OMElement invokeBlocking(QName opName, Object[] args)
071: throws AxisFault {
072: OMElement omElement = BeanUtil.getOMElement(opName, args, null,
073: false, null);
074: if (notNullService) {
075: return super .sendReceive(opName, omElement);
076: }
077: return super .sendReceive(omElement);
078: }
079:
080: /**
081: * @param opName Operation QName (to get the body wrapper element)
082: * @param args Arraylist of objects
083: * @param returnTypes , this array contains the JavaTypes for the return object , it could be
084: * one or more depending on the return type , most of the type array will
085: * contain just one element It should be noted that the array should only
086: * contains JavaTypes NOT real object , what this methods does is , get the
087: * body first element , and if it contains more than one childern take ith
088: * element and convert that to ith javatype and fill the return arrya the
089: * array will look like as follows [Integer, String, MyBean , etc]
090: * @return Object array , whic will contains real object , but the object can either be simple
091: * type object or the JavaBeans, thats what this method can handle right now the return
092: * array will contains [10, "Axis2Echo", {"foo","baa","11"}]
093: * @throws AxisFault a problem occurred, either locally or on the other side of the wire
094: */
095:
096: public Object[] invokeBlocking(QName opName, Object[] args,
097: Class[] returnTypes) throws AxisFault {
098: OMElement omElement = BeanUtil.getOMElement(opName, args, null,
099: false, null);
100: OMElement response;
101: if (notNullService) {
102: response = super .sendReceive(opName, omElement);
103: } else {
104: response = super .sendReceive(omElement);
105: }
106: return BeanUtil.deserialize(response, returnTypes,
107: new DefaultObjectSupplier());
108: }
109:
110: /**
111: * Invoke the nonblocking/Asynchronous call
112: *
113: * @param opName Operation QName (to get the body wrapper element)
114: * @param args an array of argument Objects
115: * @param callback object extending Callback which will receive notifications
116: * @throws AxisFault in case of a local processing error
117: * @deprecated Please use the AxisCallback interface rather than Callback, which has been deprecated
118: */
119: public void invokeNonBlocking(QName opName, Object[] args,
120: Callback callback) throws AxisFault {
121: OMElement omElement = BeanUtil.getOMElement(opName, args, null,
122: false, null);
123: // call the underlying implementation
124: if (notNullService) {
125: super .sendReceiveNonBlocking(opName, omElement, callback);
126: } else {
127: super .sendReceiveNonBlocking(omElement, callback);
128: }
129: }
130:
131: /**
132: * Invoke the nonblocking/Asynchronous call
133: *
134: * @param opName Operation QName (to get the body wrapper element)
135: * @param args an array of argument Objects
136: * @param callback object implementing AxisCallback which will receive notifications
137: * @throws AxisFault in case of a local processing error
138: */
139: public void invokeNonBlocking(QName opName, Object[] args,
140: AxisCallback callback) throws AxisFault {
141: OMElement omElement = BeanUtil.getOMElement(opName, args, null,
142: false, null);
143: // call the underlying implementation
144: if (notNullService) {
145: super .sendReceiveNonBlocking(opName, omElement, callback);
146: } else {
147: super .sendReceiveNonBlocking(omElement, callback);
148: }
149: }
150:
151: public void invokeRobust(QName opName, Object[] args)
152: throws AxisFault {
153: OMElement omElement = BeanUtil.getOMElement(opName, args, null,
154: false, null);
155: //call the underline implementation
156: if (notNullService) {
157: super.sendRobust(opName, omElement);
158: } else {
159: super.sendRobust(omElement);
160: }
161: }
162: }
|