Source Code Cross Referenced for BurlapClientInterceptor.java in  » J2EE » spring-framework-2.0.6 » org » springframework » remoting » caucho » 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 » J2EE » spring framework 2.0.6 » org.springframework.remoting.caucho 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.remoting.caucho;
018:
019:        import java.lang.reflect.InvocationTargetException;
020:        import java.lang.reflect.UndeclaredThrowableException;
021:        import java.net.ConnectException;
022:        import java.net.MalformedURLException;
023:
024:        import com.caucho.burlap.client.BurlapProxyFactory;
025:        import com.caucho.burlap.client.BurlapRuntimeException;
026:        import org.aopalliance.intercept.MethodInterceptor;
027:        import org.aopalliance.intercept.MethodInvocation;
028:
029:        import org.springframework.remoting.RemoteAccessException;
030:        import org.springframework.remoting.RemoteConnectFailureException;
031:        import org.springframework.remoting.RemoteLookupFailureException;
032:        import org.springframework.remoting.RemoteProxyFailureException;
033:        import org.springframework.remoting.support.UrlBasedRemoteAccessor;
034:        import org.springframework.util.Assert;
035:
036:        /**
037:         * Interceptor for accessing a Burlap service.
038:         * Supports authentication via username and password.
039:         * The service URL must be an HTTP URL exposing a Burlap service.
040:         *
041:         * <p>Burlap is a slim, XML-based RPC protocol.
042:         * For information on Burlap, see the
043:         * <a href="http://www.caucho.com/burlap">Burlap website</a>
044:         *
045:         * <p>Note: There is no requirement for services accessed with this proxy factory
046:         * to have been exported using Spring's {@link BurlapServiceExporter}, as there is
047:         * no special handling involved. As a consequence, you can also access services that
048:         * have been exported using Caucho's {@link com.caucho.burlap.server.BurlapServlet}.
049:         *
050:         * @author Juergen Hoeller
051:         * @since 29.09.2003
052:         * @see #setServiceInterface
053:         * @see #setServiceUrl
054:         * @see #setUsername
055:         * @see #setPassword
056:         * @see BurlapServiceExporter
057:         * @see BurlapProxyFactoryBean
058:         * @see com.caucho.burlap.client.BurlapProxyFactory
059:         * @see com.caucho.burlap.server.BurlapServlet
060:         */
061:        public class BurlapClientInterceptor extends UrlBasedRemoteAccessor
062:                implements  MethodInterceptor {
063:
064:            private BurlapProxyFactory proxyFactory = new BurlapProxyFactory();
065:
066:            private Object burlapProxy;
067:
068:            /**
069:             * Set the BurlapProxyFactory instance to use.
070:             * If not specified, a default BurlapProxyFactory will be created.
071:             * <p>Allows to use an externally configured factory instance,
072:             * in particular a custom BurlapProxyFactory subclass.
073:             */
074:            public void setProxyFactory(BurlapProxyFactory proxyFactory) {
075:                this .proxyFactory = (proxyFactory != null ? proxyFactory
076:                        : new BurlapProxyFactory());
077:            }
078:
079:            /**
080:             * Set the username that this factory should use to access the remote service.
081:             * Default is none.
082:             * <p>The username will be sent by Burlap via HTTP Basic Authentication.
083:             * @see com.caucho.burlap.client.BurlapProxyFactory#setUser
084:             */
085:            public void setUsername(String username) {
086:                this .proxyFactory.setUser(username);
087:            }
088:
089:            /**
090:             * Set the password that this factory should use to access the remote service.
091:             * Default is none.
092:             * <p>The password will be sent by Burlap via HTTP Basic Authentication.
093:             * @see com.caucho.burlap.client.BurlapProxyFactory#setPassword
094:             */
095:            public void setPassword(String password) {
096:                this .proxyFactory.setPassword(password);
097:            }
098:
099:            /**
100:             * Set whether overloaded methods should be enabled for remote invocations.
101:             * Default is "false".
102:             * @see com.caucho.burlap.client.BurlapProxyFactory#setOverloadEnabled
103:             */
104:            public void setOverloadEnabled(boolean overloadEnabled) {
105:                this .proxyFactory.setOverloadEnabled(overloadEnabled);
106:            }
107:
108:            public void afterPropertiesSet() {
109:                super .afterPropertiesSet();
110:                prepare();
111:            }
112:
113:            /**
114:             * Initialize the Burlap proxy for this interceptor.
115:             * @throws RemoteLookupFailureException if the service URL is invalid
116:             */
117:            public void prepare() throws RemoteLookupFailureException {
118:                try {
119:                    this .burlapProxy = createBurlapProxy(this .proxyFactory);
120:                } catch (MalformedURLException ex) {
121:                    throw new RemoteLookupFailureException("Service URL ["
122:                            + getServiceUrl() + "] is invalid", ex);
123:                }
124:            }
125:
126:            /**
127:             * Create the Burlap proxy that is wrapped by this interceptor.
128:             * @param proxyFactory the proxy factory to use
129:             * @return the Burlap proxy
130:             * @throws MalformedURLException if thrown by the proxy factory
131:             * @see com.caucho.burlap.client.BurlapProxyFactory#create
132:             */
133:            protected Object createBurlapProxy(BurlapProxyFactory proxyFactory)
134:                    throws MalformedURLException {
135:                Assert.notNull(getServiceInterface(),
136:                        "Property 'serviceInterface' is required");
137:                return proxyFactory.create(getServiceInterface(),
138:                        getServiceUrl());
139:            }
140:
141:            public Object invoke(MethodInvocation invocation) throws Throwable {
142:                if (this .burlapProxy == null) {
143:                    throw new IllegalStateException(
144:                            "BurlapClientInterceptor is not properly initialized - "
145:                                    + "invoke 'prepare' before attempting any operations");
146:                }
147:
148:                try {
149:                    return invocation.getMethod().invoke(this .burlapProxy,
150:                            invocation.getArguments());
151:                } catch (InvocationTargetException ex) {
152:                    if (ex.getTargetException() instanceof  BurlapRuntimeException) {
153:                        BurlapRuntimeException bre = (BurlapRuntimeException) ex
154:                                .getTargetException();
155:                        Throwable rootCause = (bre.getRootCause() != null ? bre
156:                                .getRootCause() : bre);
157:                        throw convertBurlapAccessException(rootCause);
158:                    } else if (ex.getTargetException() instanceof  UndeclaredThrowableException) {
159:                        UndeclaredThrowableException utex = (UndeclaredThrowableException) ex
160:                                .getTargetException();
161:                        throw convertBurlapAccessException(utex
162:                                .getUndeclaredThrowable());
163:                    }
164:                    throw ex.getTargetException();
165:                } catch (Throwable ex) {
166:                    throw new RemoteProxyFailureException(
167:                            "Failed to invoke Burlap proxy for remote service ["
168:                                    + getServiceUrl() + "]", ex);
169:                }
170:            }
171:
172:            /**
173:             * Convert the given Burlap access exception to an appropriate
174:             * Spring RemoteAccessException.
175:             * @param ex the exception to convert
176:             * @return the RemoteAccessException to throw
177:             */
178:            protected RemoteAccessException convertBurlapAccessException(
179:                    Throwable ex) {
180:                if (ex instanceof  ConnectException) {
181:                    throw new RemoteConnectFailureException(
182:                            "Cannot connect to Burlap remote service at ["
183:                                    + getServiceUrl() + "]", ex);
184:                } else {
185:                    throw new RemoteAccessException(
186:                            "Cannot access Burlap remote service at ["
187:                                    + getServiceUrl() + "]", ex);
188:                }
189:            }
190:
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.