Source Code Cross Referenced for RestServlet.java in  » Web-Services » crispy » net » sf » crispy » impl » rest » 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 » Web Services » crispy » net.sf.crispy.impl.rest 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sf.crispy.impl.rest;
002:
003:        import java.io.IOException;
004:        import java.io.PrintWriter;
005:        import java.lang.reflect.Method;
006:        import java.util.Hashtable;
007:        import java.util.Map;
008:        import java.util.Vector;
009:
010:        import javax.servlet.ServletException;
011:        import javax.servlet.http.HttpServletRequest;
012:        import javax.servlet.http.HttpServletResponse;
013:
014:        import net.sf.crispy.impl.http.Constant;
015:        import net.sf.crispy.impl.http.HttpServlet;
016:        import net.sf.crispy.util.Converter;
017:        import net.sf.crispy.util.Invoker;
018:
019:        /**
020:         * 
021:         * 
022:         * @author Linke
023:         *
024:         */
025:        public class RestServlet extends HttpServlet implements  Constant {
026:
027:            private static final long serialVersionUID = 89089242427878787L;
028:
029:            public RestServlet() {
030:                super ();
031:            }
032:
033:            /**
034:             * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
035:             */
036:            protected void doPost(HttpServletRequest pvRequest,
037:                    HttpServletResponse pvResponse) throws ServletException,
038:                    IOException {
039:                //		Object lvResult = call(pvRequest.getParameterMap(), pvRequest.getParameter(PARAM_CLASS), pvRequest.getParameter(PARAM_METHOD));
040:                Object lvResult = null;
041:                String lvServiceClassName = "NoServiceClass-available";
042:                String lvMethodName = "NoMethod-available";
043:
044:                try {
045:                    Object lvService = getService(pvRequest, pvResponse);
046:                    String lvServiceAndMethodName[] = getServiceAndMethodName(
047:                            pvRequest.getParameter(PARAM_CLASS), pvRequest
048:                                    .getParameter(PARAM_METHOD));
049:                    lvServiceClassName = lvServiceAndMethodName[0];
050:                    lvMethodName = lvServiceAndMethodName[1];
051:
052:                    Method lvMethod = getMethod(lvService, pvRequest
053:                            .getParameterMap(), pvRequest
054:                            .getParameter(PARAM_CLASS), pvRequest
055:                            .getParameter(PARAM_METHOD));
056:                    Object lvArgs[] = getArgs(pvRequest.getParameterMap(),
057:                            lvMethod);
058:                    lvResult = doInvoke(lvService, lvMethod, lvArgs,
059:                            createNewInterceptorHandlerInstance());
060:                } catch (Exception e) {
061:                    //			e.printStackTrace();
062:                    lvResult = createResponseFail(lvServiceClassName,
063:                            lvMethodName, e);
064:                }
065:
066:                if (log.isDebugEnabled()) {
067:                    log.debug("Result from method "
068:                            + pvRequest.getParameter(PARAM_METHOD) + " is: "
069:                            + lvResult);
070:                }
071:                String output = makeXmlStream(lvResult);
072:
073:                PrintWriter pw = pvResponse.getWriter();
074:                pw.print(output);
075:                pw.flush();
076:                pw.close();
077:            }
078:
079:            /** Convert the result value to xml representation. */
080:            public String makeXmlStream(Object pvResult) {
081:                String xmlStr = null;
082:                try {
083:                    xmlStr = Serializer.serialize(pvResult);
084:                } catch (Exception e) {
085:                    ResponseFail lvFail = new ResponseFail();
086:                    lvFail.setMessage(e.getMessage());
087:                    lvFail.setException(e.getClass().getName());
088:                    try {
089:                        xmlStr = Serializer.serialize(pvResult);
090:                    } catch (Exception e2) {
091:                        log.debug("Error by Serializer: " + pvResult, e);
092:                    }
093:                    e.printStackTrace();
094:                }
095:                if (log.isDebugEnabled()) {
096:                    log.debug(xmlStr);
097:                }
098:                return xmlStr;
099:            }
100:
101:            protected Object[] getArgs(Map pvParameterMap, Method pvMethod)
102:                    throws Exception {
103:                Object lvParameters = new ParameterDeserializer()
104:                        .deserialize(prepareParameter(pvParameterMap));
105:
106:                Vector lvParamVector = null;
107:                if (lvParameters instanceof  Vector) {
108:                    lvParamVector = (Vector) lvParameters;
109:                } else {
110:                    lvParamVector = new Vector();
111:                    lvParamVector.add(lvParameters);
112:                }
113:                Object lvParams[] = Converter.convertStringParams2MethodParams(
114:                        pvMethod, lvParamVector);
115:                return lvParams;
116:            }
117:
118:            public Method getMethod(Object pvService, Map pvParameterMap,
119:                    String pvServiceClassName, String pvMethodName)
120:                    throws Exception {
121:
122:                String lvServiceAndMethodName[] = getServiceAndMethodName(
123:                        pvServiceClassName, pvMethodName);
124:                //		String lvServiceClassName = lvServiceAndMethodName[0];
125:                String lvMethodName = lvServiceAndMethodName[1];
126:
127:                String lvParamTypes[] = (String[]) pvParameterMap
128:                        .get(PARAM_TYPES);
129:                Vector findParamVector = convertInParameterTypes(lvParamTypes);
130:
131:                Object lvParameters = new ParameterDeserializer()
132:                        .deserialize(prepareParameter(pvParameterMap));
133:
134:                Vector lvParamVector = null;
135:                if (lvParameters instanceof  Vector) {
136:                    lvParamVector = (Vector) lvParameters;
137:                } else {
138:                    lvParamVector = new Vector();
139:                    lvParamVector.add(lvParameters);
140:                }
141:
142:                if (findParamVector == null) {
143:                    findParamVector = lvParamVector;
144:                }
145:
146:                Method lvMethod = Invoker.findMethod(pvService.getClass(),
147:                        lvMethodName, findParamVector);
148:                return lvMethod;
149:            }
150:
151:            private ResponseFail createResponseFail(String pvServiceClassName,
152:                    String pvMethodName, Throwable pvThrowable) {
153:                ResponseFail lvFail = new ResponseFail();
154:                lvFail.setService(pvServiceClassName);
155:                lvFail.setMethod(pvMethodName);
156:                lvFail.setMessage(pvThrowable.getMessage());
157:                lvFail.setException(pvThrowable.getClass().getName());
158:                return lvFail;
159:            }
160:
161:            public Object call(Map pvParameterMap, String pvServiceClassName,
162:                    String pvMethodName) {
163:                String lvServiceClassName = "NoServiceClass-available";
164:                String lvMethodName = "NoMethod-available";
165:                try {
166:                    String lvServiceAndMethodName[] = getServiceAndMethodName(
167:                            pvServiceClassName, pvMethodName);
168:                    lvServiceClassName = lvServiceAndMethodName[0];
169:                    lvMethodName = lvServiceAndMethodName[1];
170:
171:                    Object lvService = getService(lvServiceClassName);
172:
173:                    Method lvMethod = getMethod(lvService, pvParameterMap,
174:                            pvServiceClassName, pvMethodName);
175:                    Object lvArgs[] = getArgs(pvParameterMap, lvMethod);
176:
177:                    Object lvResult = doInvoke(lvService, lvMethod, lvArgs,
178:                            createNewInterceptorHandlerInstance());
179:                    return lvResult;
180:                } catch (Exception e) {
181:                    //			e.printStackTrace();
182:                    return createResponseFail(lvServiceClassName, lvMethodName,
183:                            e);
184:                }
185:            }
186:
187:            protected Map prepareParameter(Map pvParameterMap) {
188:                // Parameter bereinigen, d.h. Methode und Klasse entfernen
189:                Map lvParameterMap = new Hashtable(pvParameterMap);
190:                lvParameterMap.remove(Constant.PARAM_METHOD);
191:                lvParameterMap.remove(Constant.PARAM_CLASS);
192:                return lvParameterMap;
193:            }
194:
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.