Source Code Cross Referenced for XMLCallingConvention.java in  » Web-Services » xins » org » xins » server » 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 » xins » org.xins.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: XMLCallingConvention.java,v 1.48 2007/09/18 08:45:03 agoubard Exp $
003:         *
004:         * Copyright 2003-2007 Orange Nederland Breedband B.V.
005:         * See the COPYRIGHT file for redistribution and use restrictions.
006:         */
007:        package org.xins.server;
008:
009:        import java.io.IOException;
010:        import java.io.PrintWriter;
011:
012:        import java.util.Iterator;
013:        import java.util.List;
014:
015:        import javax.servlet.http.HttpServletRequest;
016:        import javax.servlet.http.HttpServletResponse;
017:
018:        import org.xins.common.collections.BasicPropertyReader;
019:        import org.xins.common.text.TextUtils;
020:        import org.xins.common.xml.Element;
021:
022:        /**
023:         * XML calling convention.
024:         *
025:         * @version $Revision: 1.48 $ $Date: 2007/09/18 08:45:03 $
026:         * @author <a href="mailto:anthony.goubard@japplis.com">Anthony Goubard</a>
027:         */
028:        public class XMLCallingConvention extends CallingConvention {
029:
030:            /**
031:             * The response encoding format.
032:             */
033:            protected static final String RESPONSE_ENCODING = "UTF-8";
034:
035:            /**
036:             * The content type of the HTTP response.
037:             */
038:            protected static final String RESPONSE_CONTENT_TYPE = "text/xml; charset="
039:                    + RESPONSE_ENCODING;
040:
041:            protected String[] getSupportedMethods() {
042:                return new String[] { "POST" };
043:            }
044:
045:            /**
046:             * Checks if the specified request can be handled by this calling
047:             * convention.
048:             *
049:             * <p>This method will not throw any exception.
050:             *
051:             * @param httpRequest
052:             *    the HTTP request to investigate, cannot be <code>null</code>.
053:             *
054:             * @return
055:             *    <code>true</code> if this calling convention is <em>possibly</em>
056:             *    able to handle this request, or <code>false</code> if it
057:             *    <em>definitely</em> not able to handle this request.
058:             *
059:             * @throws Exception
060:             *    if analysis of the request causes an exception;
061:             *    <code>false</code> will be assumed.
062:             */
063:            protected boolean matches(HttpServletRequest httpRequest)
064:                    throws Exception {
065:
066:                // Parse the XML in the request (if any)
067:                Element element = parseXMLRequest(httpRequest);
068:
069:                return element.getLocalName().equals("request")
070:                        && element.getAttribute("function") != null;
071:            }
072:
073:            /**
074:             * Converts an HTTP request to a XINS request (implementation method). This
075:             * method should only be called from class CallingConvention. Only
076:             * then it is guaranteed that the <code>httpRequest</code> argument is not
077:             * <code>null</code>.
078:             *
079:             * @param httpRequest
080:             *    the HTTP request, will not be <code>null</code>.
081:             *
082:             * @return
083:             *    the XINS request object, never <code>null</code>.
084:             *
085:             * @throws InvalidRequestException
086:             *    if the request is considerd to be invalid.
087:             *
088:             * @throws FunctionNotSpecifiedException
089:             *    if the request does not indicate the name of the function to execute.
090:             */
091:            protected FunctionRequest convertRequestImpl(
092:                    HttpServletRequest httpRequest)
093:                    throws InvalidRequestException,
094:                    FunctionNotSpecifiedException {
095:
096:                Element requestElem = parseXMLRequest(httpRequest);
097:
098:                String functionName = requestElem.getAttribute("function");
099:
100:                // Determine function parameters
101:                BasicPropertyReader functionParams = new BasicPropertyReader();
102:                Iterator parameters = requestElem.getChildElements("param")
103:                        .iterator();
104:                while (parameters.hasNext()) {
105:                    Element nextParam = (Element) parameters.next();
106:                    String name = nextParam.getAttribute("name");
107:                    String value = nextParam.getText();
108:                    functionParams.set(name, value);
109:                }
110:
111:                // Check if function is specified
112:                if (TextUtils.isEmpty(functionName)) {
113:                    throw new FunctionNotSpecifiedException();
114:                }
115:
116:                // Remove all invalid parameters
117:                cleanUpParameters(functionParams);
118:
119:                // Get data section
120:                Element dataElement = null;
121:                List dataElementList = requestElem.getChildElements("data");
122:                if (dataElementList.size() == 1) {
123:                    dataElement = (Element) dataElementList.get(0);
124:                } else if (dataElementList.size() > 1) {
125:                    throw new InvalidRequestException(
126:                            "Found multiple data sections.");
127:                }
128:
129:                return new FunctionRequest(functionName, functionParams,
130:                        dataElement);
131:            }
132:
133:            /**
134:             * Converts a XINS result to an HTTP response (implementation method).
135:             *
136:             * @param xinsResult
137:             *    the XINS result object that should be converted to an HTTP response,
138:             *    will not be <code>null</code>.
139:             *
140:             * @param httpResponse
141:             *    the HTTP response object to configure, will not be <code>null</code>.
142:             *
143:             * @param httpRequest
144:             *    the HTTP request, will not be <code>null</code>.
145:             *
146:             * @throws IOException
147:             *    if calling any of the methods in <code>httpResponse</code> causes an
148:             *    I/O error.
149:             */
150:            protected void convertResultImpl(FunctionResult xinsResult,
151:                    HttpServletResponse httpResponse,
152:                    HttpServletRequest httpRequest) throws IOException {
153:
154:                // Send the XML output to the stream and flush
155:                httpResponse.setContentType(RESPONSE_CONTENT_TYPE);
156:                PrintWriter out = httpResponse.getWriter();
157:                httpResponse.setStatus(HttpServletResponse.SC_OK);
158:                CallResultOutputter.output(out, xinsResult);
159:                out.close();
160:            }
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.