Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.aries.rsa.itests.felix.RsaTestBase;
import org.apache.aries.rsa.spi.DistributionProvider;
import org.apache.aries.rsa.spi.EndpointDescriptionParser;
import org.apache.aries.rsa.spi.ImportedService;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;
import org.hamcrest.Matchers;
Expand Down Expand Up @@ -67,10 +68,11 @@ public static Option[] configure() throws Exception {
@Test
public void testDiscoveryExport() throws Exception {
EndpointDescription epd = getEndpoint();
EchoService service = (EchoService)tcpProvider
.importEndpoint(EchoService.class.getClassLoader(),
bundleContext, new Class[]{EchoService.class}, epd);
ImportedService importedService = tcpProvider.importEndpoint(EchoService.class.getClassLoader(),
bundleContext, new Class[]{EchoService.class}, epd);
EchoService service = (EchoService)importedService.getService();
Assert.assertEquals("test", service.echo("test"));
importedService.close();
}

private EndpointDescription getEndpoint() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.aries.rsa.provider.fastbin.util.UuidGenerator;
import org.apache.aries.rsa.spi.DistributionProvider;
import org.apache.aries.rsa.spi.Endpoint;
import org.apache.aries.rsa.spi.ImportedService;
import org.apache.aries.rsa.spi.IntentUnsatisfiedException;
import org.fusesource.hawtdispatch.Dispatch;
import org.fusesource.hawtdispatch.DispatchQueue;
Expand Down Expand Up @@ -172,15 +173,16 @@ public void close() throws IOException {
}

@Override
public Object importEndpoint(ClassLoader cl,
BundleContext consumerContext,
Class[] interfaces,
EndpointDescription endpoint)
public ImportedService importEndpoint(ClassLoader cl,
BundleContext consumerContext,
Class[] interfaces,
EndpointDescription endpoint)
throws IntentUnsatisfiedException {

String address = (String) endpoint.getProperties().get(FASTBIN_ADDRESS);
InvocationHandler handler = client.getProxy(address, endpoint.getId(), cl);
return Proxy.newProxyInstance(cl, interfaces, handler);
Object service = Proxy.newProxyInstance(cl, interfaces, handler);
return () -> service;
}

}
15 changes: 15 additions & 0 deletions provider/tcp/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ is ideal to get a simple remote services setup running.

## Endpoint Configuration Properties

The exported endpoint service supports the following properties:

| Key | Default | Description |
|--------------------------|--------------------|-------------------------------------|
| service.exported.configs | | Must contain "aries.tcp" |
Expand All @@ -14,3 +16,16 @@ is ideal to get a simple remote services setup running.
| aries.rsa.port | [free port] | Port to listen on |
| aries.rsa.id | [random id] | Unique id string for endpoint |
| aries.rsa.numThreads | 10 | Number of listener threads to spawn |

## Provider Configuration

The provider's configuration pid is `org.apache.aries.rsa.provider.tcp`, and supports the following properties:

| Key | Default | Description |
|------------------------------|-----------------|--------------------------------------------------------|
| aries.rsa.keyStore | [no server TLS] | Path to the key store file (or empty to disable TLS) |
| aries.rsa.keyStorePassword | | Key store password |
| aries.rsa.trustStore | [no client TLS] | Path to the trust store file (or empty to disable TLS) |
| aries.rsa.trustStorePassword | | Trust store password |
| aries.rsa.keyAlias | [autoselect] | Alias of key within keystore to use for server TLS |
| aries.rsa.mtls | false | Whether to use MTLS (require client authentication) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* 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.aries.rsa.provider.tcp;

import java.util.Map;
import java.util.UUID;

/**
* A convenience class for extracting endpoint configuration properties,
* provider properties and defaults.
*/
public class Config {

// endpoint service properties
static final String PORT = "aries.rsa.port";
static final String HOSTNAME = "aries.rsa.hostname";
static final String BIND_ADDRESS = "aries.rsa.bindAddress";
static final String ID = "aries.rsa.id";
static final String THREADS = "aries.rsa.numThreads";
static final String TIMEOUT = "osgi.basic.timeout";

// provider component properties
static final String KEYSTORE = "aries.rsa.keyStore";
static final String TRUSTSTORE = "aries.rsa.trustStore";
static final String KEYSTORE_PASSWORD = "aries.rsa.keyStorePassword";
static final String TRUSTSTORE_PASSWORD = "aries.rsa.trustStorePassword";
static final String KEY_ALIAS = "aries.rsa.keyAlias";
static final String MTLS = "aries.rsa.mtls";

static final int DYNAMIC_PORT = 0;
static final int DEFAULT_TIMEOUT_MILLIS = 300000;
static final int DEFAULT_NUM_THREADS = 10;

private final Map<String, Object> props;
private final String uuid = UUID.randomUUID().toString(); // fallback id
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of uuid we can call the fieldfallbackId


public Config(Map<String, Object> props) {
this.props = props;
}

public int getTimeoutMillis() {
return getInt(TIMEOUT, DEFAULT_TIMEOUT_MILLIS);
}

int getInt(String key, int defaultValue) {
Object value = props.get(key);
return value != null ? Integer.parseInt(value.toString()) : defaultValue;
}

String getString(String key, String defaultValue) {
Object value = props.get(key);
return value != null ? value.toString() : defaultValue;
}

public int getPort() {
return getInt(PORT, DYNAMIC_PORT);
}

public String getHostname() {
String hostName = getString(HOSTNAME, System.getProperty(HOSTNAME));
if (hostName == null) {
hostName = NetUtil.getLocalIp();
}
return hostName;
}

public String getBindAddress() {
return getString(BIND_ADDRESS, System.getProperty(BIND_ADDRESS));
}

public String getId() {
return getString(ID, uuid);
}

public int getNumThreads() {
return getInt(THREADS, DEFAULT_NUM_THREADS);
}

public String getKeyStore() {
return getString(KEYSTORE, System.getProperty(KEYSTORE));
}

public String getTrustStore() {
return getString(TRUSTSTORE, System.getProperty(TRUSTSTORE));
}

public String getKeyStorePassword() {
return getString(KEYSTORE_PASSWORD, System.getProperty(KEYSTORE_PASSWORD));
}

public String getTrustStorePassword() {
return getString(TRUSTSTORE_PASSWORD, System.getProperty(TRUSTSTORE_PASSWORD));
}

public String getKeyAlias() {
return getString(KEY_ALIAS, System.getProperty(KEY_ALIAS));
}

public boolean isMtls() {
return Boolean.parseBoolean(getString(MTLS, System.getProperty(MTLS)));
}
}

This file was deleted.

This file was deleted.

Loading