Author: asankha
Date: Sat Jan 5 08:14:28 2008
New Revision: 609165
URL: http://svn.apache.org/viewvc?rev=609165&view=rev
Log:
fix SYNAPSE-207
Added:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/ClasspathURLStreamHandler.java
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerManager.java
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerManager.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerManager.java?rev=609165&r1=609164&r2=609165&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerManager.java
(original)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ServerManager.java
Sat Jan 5 08:14:28 2008
@@ -27,9 +27,13 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.core.SynapseEnvironment;
import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.synapse.util.ClasspathURLStreamHandler;
import java.io.File;
import java.net.ServerSocket;
+import java.net.URL;
+import java.net.URLStreamHandler;
+import java.net.URLStreamHandlerFactory;
import java.util.Iterator;
import java.util.Collection;
@@ -66,6 +70,14 @@
*/
public void start() {
+ // Register custom protocol handler classpath://
+ try {
+ URL.setURLStreamHandlerFactory(new
URLStreamHandlerFactoryImpl());
+ } catch (Throwable t) {
+ log.warn("Unable to register a URLStreamHandlerFactory
- " +
+ "Custom URL protocols may not work
properly (e.g. classpath://)");
+ }
+
if (axis2Repolocation == null) {
log.fatal("The Axis2 Repository must be provided");
return;
@@ -207,5 +219,20 @@
public ConfigurationContext getConfigurationContext() {
return configctx;
+ }
+
+ private static final class URLStreamHandlerFactoryImpl implements
URLStreamHandlerFactory {
+
+ public URLStreamHandler createURLStreamHandler(String protocol) {
+
+ if (protocol == null) {
+ throw new IllegalArgumentException("'protocol' cannot be
null");
+ }
+ URLStreamHandler urlSH = null;
+ if (protocol.equals("classpath")) {
+ urlSH = new ClasspathURLStreamHandler();
+ }
+ return urlSH;
+ }
}
}
Added:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/ClasspathURLStreamHandler.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/ClasspathURLStreamHandler.java?rev=609165&view=auto
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/ClasspathURLStreamHandler.java
(added)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/ClasspathURLStreamHandler.java
Sat Jan 5 08:14:28 2008
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.synapse.util;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+
+public final class ClasspathURLStreamHandler extends URLStreamHandler {
+
+ public URLConnection openConnection(URL url) {
+ return new URLConnectionImpl(url);
+ }
+
+ private static final class URLConnectionImpl extends URLConnection {
+
+ public URLConnectionImpl(URL url) {
+ super(url);
+ }
+
+ public void connect() {}
+
+ public InputStream getInputStream() {
+ String s = url.toExternalForm();
+ s = s.substring((url.getProtocol() + "://").length(), s.length());
+
+ InputStream is =
ClasspathURLStreamHandler.class.getClassLoader().getResourceAsStream(s);
+ if (is == null) {
+ String msg = "Unable to read the specified resource from the
classpath: " + s;
+ throw new RuntimeException(msg);
+ }
+ return is;
+ }
+
+ public OutputStream getOutputStream() {
+ throw new UnsupportedOperationException();
+ }
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]