Update NodeUtil and add a test case
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@775282 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2a4b87ac24
commit
80f7efa886
2 changed files with 59 additions and 20 deletions
java/sca/modules/node-impl/src
main/java/org/apache/tuscany/sca/node/impl
test/java/org/apache/tuscany/sca/node/impl
|
@ -22,6 +22,7 @@ package org.apache.tuscany.sca.node.impl;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
|
@ -46,26 +47,6 @@ public class NodeUtil {
|
|||
return contribution;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape the space in URL string
|
||||
* @param uri
|
||||
* @return
|
||||
*/
|
||||
static URI createURI(String uri) {
|
||||
URI returnURI = null;
|
||||
|
||||
try {
|
||||
returnURI = URI.create(uri);
|
||||
} catch( Exception e) {
|
||||
try {
|
||||
returnURI = new URI(null, uri, null);
|
||||
} catch (Exception ee) {
|
||||
throw new IllegalArgumentException("Invalid URI :" + uri, ee);
|
||||
}
|
||||
}
|
||||
return returnURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a URL connection without cache
|
||||
* @param url
|
||||
|
@ -79,4 +60,25 @@ public class NodeUtil {
|
|||
is = connection.getInputStream();
|
||||
return is;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape the space in URL string
|
||||
* @param uri
|
||||
* @return
|
||||
*/
|
||||
static URI createURI(String uri) {
|
||||
int index = uri.indexOf(':');
|
||||
String scheme = null;
|
||||
String ssp = uri;
|
||||
if (index != -1) {
|
||||
scheme = uri.substring(0, index);
|
||||
ssp = uri.substring(index + 1);
|
||||
}
|
||||
try {
|
||||
return new URI(scheme, ssp, null);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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.tuscany.sca.node.impl;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class NodeUtilTestCase {
|
||||
@Test
|
||||
public void testCreateURI() {
|
||||
Assert.assertEquals("/a/b", NodeUtil.createURI("/a/b").toString());
|
||||
Assert.assertEquals("/a%20b", NodeUtil.createURI("/a b").toString());
|
||||
Assert.assertEquals("file:/a/b", NodeUtil.createURI("file:/a/b").toString());
|
||||
Assert.assertEquals("file:/a%20b", NodeUtil.createURI("file:/a b").toString());
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue