Source Code Cross Referenced for URLTemplatingUtil.java in  » Web-Services-AXIS2 » kernal » org » apache » axis2 » transport » http » util » 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 AXIS2 » kernal » org.apache.axis2.transport.http.util 
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:         */
019:        package org.apache.axis2.transport.http.util;
020:
021:        import org.apache.axiom.om.OMElement;
022:        import org.apache.axis2.AxisFault;
023:        import org.apache.axis2.context.MessageContext;
024:        import org.apache.axis2.description.WSDL20DefaultValueHolder;
025:        import org.apache.axis2.description.WSDL2Constants;
026:        import org.apache.axis2.util.WSDL20Util;
027:
028:        import java.io.UnsupportedEncodingException;
029:        import java.net.MalformedURLException;
030:        import java.net.URI;
031:        import java.net.URISyntaxException;
032:        import java.net.URL;
033:        import java.util.Iterator;
034:
035:        /**
036:         * This util is used on the client side for creating the URL's for all request (WSDL 2.0 allws to
037:         * change the URL's of SOAP messages too). It resolves WSDL 2.0 httplocation property and also
038:         * append parameters to URL's when needed.
039:         */
040:        public class URLTemplatingUtil {
041:
042:            /**
043:             * Appends Query parameters to the URL
044:             *
045:             * @param messageContext - The MessageContext of the request
046:             * @param url            - Original url string
047:             * @return String containing the appended query parameters
048:             */
049:            public static URL appendQueryParameters(
050:                    MessageContext messageContext, URL url) throws AxisFault {
051:
052:                String urlString = url.toString();
053:                OMElement firstElement;
054:                String queryParameterSeparator = (String) messageContext
055:                        .getProperty(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR);
056:                // In case queryParameterSeparator is null we better use the default value
057:
058:                if (queryParameterSeparator == null) {
059:                    queryParameterSeparator = WSDL20DefaultValueHolder
060:                            .getDefaultValue(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR);
061:                }
062:
063:                firstElement = messageContext.getEnvelope().getBody()
064:                        .getFirstElement();
065:                String params = "";
066:
067:                if (firstElement != null) {
068:                    Iterator iter = firstElement.getChildElements();
069:
070:                    String legalCharacters = WSDL2Constants.LEGAL_CHARACTERS_IN_QUERY
071:                            .replaceAll(queryParameterSeparator, "");
072:
073:                    while (iter.hasNext()) {
074:                        OMElement element = (OMElement) iter.next();
075:                        try {
076:                            params = params
077:                                    + URIEncoderDecoder.quoteIllegal(element
078:                                            .getLocalName(), legalCharacters)
079:                                    + "="
080:                                    + URIEncoderDecoder.quoteIllegal(element
081:                                            .getText(), legalCharacters)
082:                                    + queryParameterSeparator;
083:                        } catch (UnsupportedEncodingException e) {
084:                            throw AxisFault.makeFault(e);
085:                        }
086:                    }
087:                }
088:
089:                if (!"".equals(params)) {
090:                    int index = urlString.indexOf("?");
091:                    if (index == -1) {
092:                        urlString = urlString + "?"
093:                                + params.substring(0, params.length() - 1);
094:                    } else if (index == urlString.length() - 1) {
095:                        urlString = urlString
096:                                + params.substring(0, params.length() - 1);
097:
098:                    } else {
099:                        urlString = urlString + queryParameterSeparator
100:                                + params.substring(0, params.length() - 1);
101:                    }
102:
103:                    try {
104:                        return new URL(urlString);
105:                    } catch (MalformedURLException e) {
106:                        throw AxisFault.makeFault(e);
107:                    }
108:                }
109:                return url;
110:            }
111:
112:            /**
113:             * Returns the templated URL given the original URL
114:             *
115:             * @param targetURL      - The original URL
116:             * @param messageContext - The MessageContext of the request
117:             * @param detach         - Boolean value specifying whether the element should be detached from the
118:             *                       envelop. When serializing data as application/x-form-urlencoded what goes in the body is the
119:             *                       remainder and therefore we should detach the element from the envelop.
120:             * @return The templated URL
121:             * @throws AxisFault - Thrown in case an exception occurs
122:             */
123:            public static URL getTemplatedURL(URL targetURL,
124:                    MessageContext messageContext, boolean detach)
125:                    throws AxisFault {
126:
127:                String httpLocation = (String) messageContext
128:                        .getProperty(WSDL2Constants.ATTR_WHTTP_LOCATION);
129:
130:                //        String urlString = targetURL.toString();
131:                if (httpLocation != null) {
132:                    String replacedQuery = httpLocation;
133:                    int separator = httpLocation.indexOf('{');
134:                    try {
135:
136:                        if (separator > -1) {
137:                            replacedQuery = URIEncoderDecoder.quoteIllegal(
138:                                    WSDL20Util.applyURITemplating(
139:                                            messageContext, httpLocation,
140:                                            detach),
141:                                    WSDL2Constants.LEGAL_CHARACTERS_IN_URL);
142:
143:                        }
144:                        URI targetURI;
145:                        URI appendedURI;
146:                        if (replacedQuery.charAt(0) == '?') {
147:                            appendedURI = new URI(targetURL.toString()
148:                                    + replacedQuery);
149:                        } else {
150:                            String uriString = targetURL.toString();
151:                            if (!uriString.endsWith("/")) {
152:                                targetURI = new URI(uriString + "/");
153:                            } else {
154:                                targetURI = new URI(uriString);
155:                            }
156:                            appendedURI = targetURI.resolve(replacedQuery);
157:                        }
158:
159:                        targetURL = appendedURI.toURL();
160:
161:                    } catch (MalformedURLException e) {
162:                        throw new AxisFault(
163:                                "An error occured while trying to create request URL");
164:                    } catch (URISyntaxException e) {
165:                        throw new AxisFault(
166:                                "An error occured while trying to create request URL");
167:                    } catch (UnsupportedEncodingException e) {
168:                        throw new AxisFault(
169:                                "An error occured while trying to create request URL");
170:                    }
171:                }
172:
173:                return targetURL;
174:            }
175:
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.