Source Code Cross Referenced for SOAPClientEngine.java in  » ERP-CRM-Financial » ofbiz » org » ofbiz » service » engine » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » ofbiz » org.ofbiz.service.engine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:         *******************************************************************************/package org.ofbiz.service.engine;
019:
020:        import java.net.MalformedURLException;
021:        import java.net.URL;
022:        import java.util.HashMap;
023:        import java.util.Hashtable;
024:        import java.util.Iterator;
025:        import java.util.List;
026:        import java.util.Map;
027:        import java.util.Vector;
028:
029:        import javax.xml.namespace.QName;
030:        import javax.xml.rpc.ParameterMode;
031:        import javax.xml.rpc.ServiceException;
032:
033:        import org.apache.axis.Message;
034:        import org.apache.axis.client.Call;
035:        import org.apache.axis.client.Service;
036:        import org.apache.axis.encoding.XMLType;
037:        import org.apache.axis.message.RPCElement;
038:        import org.apache.axis.message.RPCParam;
039:        import org.apache.axis.message.SOAPEnvelope;
040:        import org.ofbiz.service.GenericServiceException;
041:        import org.ofbiz.service.ModelParam;
042:        import org.ofbiz.service.ModelService;
043:        import org.ofbiz.service.ServiceDispatcher;
044:        import org.ofbiz.base.util.Debug;
045:        import org.ofbiz.base.util.UtilValidate;
046:
047:        /**
048:         * Generic Service SOAP Interface
049:         */
050:        public final class SOAPClientEngine extends GenericAsyncEngine {
051:
052:            public static final String module = SOAPClientEngine.class
053:                    .getName();
054:
055:            public SOAPClientEngine(ServiceDispatcher dispatcher) {
056:                super (dispatcher);
057:            }
058:
059:            /**
060:             * @see org.ofbiz.service.engine.GenericEngine#runSyncIgnore(java.lang.String, org.ofbiz.service.ModelService, java.util.Map)
061:             */
062:            public void runSyncIgnore(String localName,
063:                    ModelService modelService, Map context)
064:                    throws GenericServiceException {
065:                runSync(localName, modelService, context);
066:            }
067:
068:            /**
069:             * @see org.ofbiz.service.engine.GenericEngine#runSync(java.lang.String, org.ofbiz.service.ModelService, java.util.Map)
070:             */
071:            public Map runSync(String localName, ModelService modelService,
072:                    Map context) throws GenericServiceException {
073:                Object result = serviceInvoker(modelService, context);
074:
075:                if (result == null)
076:                    throw new GenericServiceException(
077:                            "Service did not return expected result");
078:                if (!(result instanceof  Map)) {
079:                    Map newResult = new HashMap();
080:
081:                    newResult.put("result", result);
082:                    return newResult;
083:                }
084:                return (Map) result;
085:            }
086:
087:            // Invoke the remote SOAP service
088:            private Object serviceInvoker(ModelService modelService, Map context)
089:                    throws GenericServiceException {
090:                if (modelService.location == null
091:                        || modelService.invoke == null)
092:                    throw new GenericServiceException(
093:                            "Cannot locate service to invoke");
094:
095:                Service service = null;
096:                Call call = null;
097:
098:                try {
099:                    service = new Service();
100:                    call = (Call) service.createCall();
101:                } catch (javax.xml.rpc.JAXRPCException e) {
102:                    throw new GenericServiceException("RPC service error", e);
103:                } catch (ServiceException e) {//Add by Andy.Chen 2003.01.15
104:                    throw new GenericServiceException("RPC service error", e);
105:                }
106:
107:                URL endPoint = null;
108:
109:                try {
110:                    endPoint = new URL(this .getLocation(modelService));
111:                } catch (MalformedURLException e) {
112:                    throw new GenericServiceException(
113:                            "Location not a valid URL", e);
114:                }
115:
116:                List inModelParamList = modelService.getInModelParamList();
117:                Object[] params = new Object[inModelParamList.size()];
118:
119:                if (Debug.infoOn())
120:                    Debug.logInfo(
121:                            "[SOAPClientEngine.invoke] : Parameter length - "
122:                                    + params.length, module);
123:
124:                call.setTargetEndpointAddress(endPoint);
125:
126:                if (UtilValidate.isNotEmpty(modelService.nameSpace)) {
127:                    call.setOperationName(new QName(modelService.nameSpace,
128:                            modelService.invoke));
129:                } else {
130:                    call.setOperationName(modelService.invoke);
131:                }
132:
133:                int i = 0;
134:
135:                call.setOperation(call.getOperationName().getLocalPart());
136:                Vector vParams = new Vector();
137:                Iterator iter = inModelParamList.iterator();
138:                while (iter.hasNext()) {
139:                    ModelParam p = (ModelParam) iter.next();
140:
141:                    if (Debug.infoOn())
142:                        Debug.logInfo("[SOAPClientEngine.invoke} : Parameter: "
143:                                + p.name + " (" + p.mode + ") - " + i, module);
144:
145:                    //Exclude params that ModelServiceReader insert into
146:                    if (!p.name.trim().equals("userLogin")
147:                            && !p.name.trim().equals("locale")) {
148:                        QName qName = call.getParameterTypeByName(p.name); //.getTypeMapping().getTypeQName((Class) ObjectType.classNameClassMap.get(p.type));
149:                        call.addParameter(p.name, qName, getMode(p.mode));
150:                        vParams.add(context.get(p.name));
151:                    }
152:
153:                    // if the value is null, that's fine, it will go in null...
154:                    params[i] = context.get(p.name);
155:
156:                    i++;
157:                }
158:
159:                call.setReturnType(XMLType.XSD_ANYTYPE);
160:                params = vParams.toArray();
161:
162:                Object result = null;
163:
164:                try {
165:                    Debug
166:                            .logInfo(
167:                                    "[SOAPClientEngine.invoke] : Sending Call To SOAP Server",
168:                                    module);
169:                    result = call.invoke(params);
170:                } catch (java.rmi.RemoteException e) {
171:                    throw new GenericServiceException("RPC error", e);
172:                }
173:                if (Debug.verboseOn()) {
174:                    Debug.log("SOAP Service Result - " + result, module);
175:                }
176:
177:                return getResponseParams(call.getMessageContext()
178:                        .getResponseMessage());
179:            }
180:
181:            private Map getResponseParams(Message respMessage) {
182:                Map mRet = new Hashtable();
183:                try {
184:                    SOAPEnvelope resEnv = respMessage.getSOAPEnvelope();
185:                    List bodies = resEnv.getBodyElements();
186:                    Iterator i = bodies.iterator();
187:                    while (i.hasNext()) {
188:                        Object o = i.next();
189:
190:                        if (o instanceof  RPCElement) {
191:                            RPCElement body = (RPCElement) o;
192:                            List params = null;
193:                            params = body.getParams();
194:
195:                            Iterator p = params.iterator();
196:                            while (p.hasNext()) {
197:                                RPCParam param = (RPCParam) p.next();
198:                                mRet.put(param.getName(), param.getValue());
199:                                if (Debug.verboseOn()) {
200:                                    Debug.log("SOAP Client Param - "
201:                                            + param.getName() + "="
202:                                            + param.getValue(), module);
203:                                }
204:                            }
205:                        }
206:                    }
207:                } catch (org.apache.axis.AxisFault e) {
208:                    Debug.logError(e, "AxisFault", module);
209:                } catch (org.xml.sax.SAXException e) {
210:                    Debug.logError(e, "SAXException", module);
211:                }
212:                return mRet;
213:            }
214:
215:            private ParameterMode getMode(String sMode) {
216:                if (sMode.equals("IN")) {
217:                    return ParameterMode.IN;
218:                } else if (sMode.equals("OUT")) {
219:                    return ParameterMode.OUT;
220:                } else if (sMode.equals("INOUT")) {
221:                    return ParameterMode.INOUT;
222:                } else {
223:                    return null;
224:                }
225:            }
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.