blob: faff555b8a32a03706206ee1dec1e820e67855d6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/*******************************************************************************
* Copyright (c) 2010, 2016 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package geturl;
import java.io.IOException;
import java.net.*;
import java.security.PrivilegedAction;
import java.util.Dictionary;
import java.util.Hashtable;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
final URL url = (URL) System.getProperties().get("test.url");
final String urlSpec = (String) System.getProperties().get("test.url.spec");
Dictionary props = new Hashtable();
props.put("test.url", url);
context.registerService(PrivilegedAction.class, new PrivilegedAction() {
@Override
public Object run() {
try {
throw new RuntimeException("Expected to fail to create: " + new URL(urlSpec));
} catch (MalformedURLException e) {
// expected; the parseURL will cause this to fail
}
try {
new URL(url.getProtocol(), url.getHost(), url.getFile());
} catch (MalformedURLException e) {
// unexpected; the handler does not get involved and we have a multiplexor cached
throw new RuntimeException("Could not create URL from parts: " + url);
}
url.toExternalForm();
try {
url.openConnection(Proxy.NO_PROXY);
} catch (IOException e) {
// expected since our impl throws this
}
return Boolean.TRUE;
}
}, props);
}
public void stop(BundleContext context) throws Exception {
// TODO Auto-generated method stub
}
}
|