Source Code Cross Referenced for HttpConduitBeanDefinitionParser.java in  » Web-Services-apache-cxf-2.0.1 » transports » org » apache » cxf » transport » http » spring » 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 apache cxf 2.0.1 » transports » org.apache.cxf.transport.http.spring 
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.apache.cxf.transport.http.spring;
019:
020:        import javax.xml.bind.JAXBContext;
021:        import javax.xml.bind.JAXBElement;
022:        import javax.xml.bind.Unmarshaller;
023:        import javax.xml.namespace.QName;
024:
025:        import org.w3c.dom.Element;
026:        import org.w3c.dom.Node;
027:        import org.w3c.dom.NodeList;
028:
029:        import org.apache.cxf.common.classloader.ClassLoaderUtils;
030:        import org.apache.cxf.configuration.jsse.TLSClientParameters;
031:        import org.apache.cxf.configuration.jsse.spring.TLSClientParametersConfig;
032:        import org.apache.cxf.configuration.security.AuthorizationPolicy;
033:        import org.apache.cxf.configuration.security.ProxyAuthorizationPolicy;
034:        import org.apache.cxf.configuration.security.TLSClientParametersType;
035:        import org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser;
036:        import org.apache.cxf.transport.http.HTTPConduit;
037:        import org.apache.cxf.transport.http.HttpBasicAuthSupplier;
038:        import org.apache.cxf.transport.http.MessageTrustDecider;
039:        import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
040:        import org.springframework.beans.factory.support.BeanDefinitionBuilder;
041:        import org.springframework.beans.factory.xml.ParserContext;
042:
043:        public class HttpConduitBeanDefinitionParser extends
044:                AbstractBeanDefinitionParser {
045:
046:            private static final String HTTP_NS = "http://cxf.apache.org/transports/http/configuration";
047:
048:            @Override
049:            public void doParse(Element element, ParserContext ctx,
050:                    BeanDefinitionBuilder bean) {
051:                bean.setAbstract(true);
052:                mapElementToJaxbProperty(element, bean, new QName(HTTP_NS,
053:                        "client"), "client", HTTPClientPolicy.class);
054:                mapElementToJaxbProperty(element, bean, new QName(HTTP_NS,
055:                        "proxyAuthorization"), "proxyAuthorization",
056:                        ProxyAuthorizationPolicy.class);
057:                mapElementToJaxbProperty(element, bean, new QName(HTTP_NS,
058:                        "authorization"), "authorization",
059:                        AuthorizationPolicy.class);
060:
061:                mapSpecificElements(element, bean);
062:            }
063:
064:            /**
065:             * This method specifically maps the "trustDecider" and "basicAuthSupplier"
066:             * elements to properties on the HttpConduit.
067:             * 
068:             * @param parent This should represent "conduit".
069:             * @param bean   The bean parser.
070:             */
071:            private void mapSpecificElements(Element parent,
072:                    BeanDefinitionBuilder bean) {
073:                NodeList nl = parent.getChildNodes();
074:                for (int i = 0; i < nl.getLength(); i++) {
075:                    Node n = nl.item(i);
076:                    if (Node.ELEMENT_NODE != n.getNodeType()
077:                            || !HTTP_NS.equals(n.getNamespaceURI())) {
078:                        continue;
079:                    }
080:                    String elementName = n.getLocalName();
081:                    // Schema should require that no more than one each of these exist.
082:                    if ("trustDecider".equals(elementName)) {
083:                        mapBeanOrClassElement((Element) n, bean,
084:                                MessageTrustDecider.class);
085:                    } else if ("basicAuthSupplier".equals(elementName)) {
086:                        mapBeanOrClassElement((Element) n, bean,
087:                                HttpBasicAuthSupplier.class);
088:                    } else if ("tlsClientParameters".equals(elementName)) {
089:                        mapTLSClientParameters(n, bean);
090:                    }
091:                }
092:
093:            }
094:
095:            /**
096:             * Inject the "setTlsClientParameters" method with
097:             * a TLSClientParametersConfig object initialized with the JAXB
098:             * generated type unmarshalled from the selected node.
099:             */
100:            public void mapTLSClientParameters(Node n,
101:                    BeanDefinitionBuilder bean) {
102:
103:                // Unmarshal the JAXB Generated Type from Config and inject
104:                // the configured TLSClientParameters into the HTTPConduit.
105:                JAXBContext context = null;
106:                try {
107:                    context = JAXBContext.newInstance(
108:                            TLSClientParametersType.class.getPackage()
109:                                    .getName(), getClass().getClassLoader());
110:                    Unmarshaller u = context.createUnmarshaller();
111:                    JAXBElement<TLSClientParametersType> jaxb = u.unmarshal(n,
112:                            TLSClientParametersType.class);
113:                    TLSClientParameters params = new TLSClientParametersConfig(
114:                            jaxb.getValue());
115:                    bean.addPropertyValue("tlsClientParameters", params);
116:                } catch (Exception e) {
117:                    throw new RuntimeException(
118:                            "Could not process configuration.", e);
119:                }
120:            }
121:
122:            /**
123:             * This method finds the class or bean associated with the named element
124:             * and sets the bean property that is associated with the same name as
125:             * the element.
126:             * <p>
127:             * The element has either a "class" attribute or "bean" attribute, but 
128:             * not both.
129:             * 
130:             * @param element      The element.
131:             * @param bean         The Bean Definition Parser.
132:             * @param elementClass The Class a bean or class is supposed to be.
133:             */
134:            protected void mapBeanOrClassElement(Element element,
135:                    BeanDefinitionBuilder bean, Class elementClass) {
136:                String elementName = element.getLocalName();
137:
138:                String classProperty = element.getAttribute("class");
139:                if (classProperty != null && !classProperty.equals("")) {
140:                    try {
141:                        Object obj = ClassLoaderUtils.loadClass(classProperty,
142:                                getClass()).newInstance();
143:                        if (!elementClass.isInstance(obj)) {
144:                            throw new IllegalArgumentException("Element '"
145:                                    + elementName + "' must be of type "
146:                                    + elementClass.getName() + ".");
147:                        }
148:                        bean.addPropertyValue(elementName, obj);
149:                    } catch (IllegalAccessException ex) {
150:                        throw new IllegalArgumentException("Element '"
151:                                + elementName + "' could not load "
152:                                + classProperty + " - " + ex);
153:                    } catch (ClassNotFoundException ex) {
154:                        throw new IllegalArgumentException("Element '"
155:                                + elementName + "' could not load "
156:                                + classProperty + " - " + ex);
157:                    } catch (InstantiationException ex) {
158:                        throw new IllegalArgumentException("Element '"
159:                                + elementName + "' could not load "
160:                                + classProperty + " - " + ex);
161:                    }
162:                }
163:                String beanref = element.getAttribute("bean");
164:                if (beanref != null && !beanref.equals("")) {
165:                    if (classProperty != null && !classProperty.equals("")) {
166:                        throw new IllegalArgumentException("Element '"
167:                                + elementName + "' cannot have both "
168:                                + "\"bean\" and \"class\" attributes.");
169:
170:                    }
171:                    bean.addPropertyReference(elementName, beanref);
172:                } else if (classProperty == null || classProperty.equals("")) {
173:                    throw new IllegalArgumentException("Element '"
174:                            + elementName + "' requires at least one of the "
175:                            + "\"bean\" or \"class\" attributes.");
176:                }
177:            }
178:
179:            @Override
180:            protected Class getBeanClass(Element arg0) {
181:                return HTTPConduit.class;
182:            }
183:
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.