use of org.openremote.model.value.StringValue in project openremote by openremote.
the class AbstractHttpServerProtocol method createDeployment.
protected ResteasyDeployment createDeployment(Application application, AssetAttribute protocolConfiguration) {
ResteasyDeployment resteasyDeployment = new ResteasyDeployment();
resteasyDeployment.setApplication(application);
List<String> allowedOrigins;
if (devMode) {
allowedOrigins = Collections.singletonList("*");
} else {
Optional<MetaItem> allowedOriginsMeta = protocolConfiguration.getMetaItem(META_PROTOCOL_ALLOWED_ORIGINS);
allowedOrigins = allowedOriginsMeta.flatMap(AbstractValueHolder::getValueAsString).map(Collections::singletonList).orElseGet(() -> allowedOriginsMeta.flatMap(AbstractValueHolder::getValueAsArray).flatMap(arrayValue -> Values.getArrayElements(arrayValue, StringValue.class, true, false, StringValue::getString)).orElse(null));
}
if (allowedOrigins != null) {
String allowedMethods = protocolConfiguration.getMetaItem(META_PROTOCOL_ALLOWED_METHODS).flatMap(AbstractValueHolder::getValueAsString).orElse(DEFAULT_ALLOWED_METHODS);
if (TextUtil.isNullOrEmpty(allowedMethods)) {
throw new IllegalArgumentException("Allowed methods meta item must be a non empty string: " + META_PROTOCOL_ALLOWED_METHODS);
}
CorsFilter corsFilter = new CorsFilter();
corsFilter.getAllowedOrigins().addAll(allowedOrigins);
corsFilter.setAllowedMethods(allowedMethods);
resteasyDeployment.getProviders().add(corsFilter);
}
return resteasyDeployment;
}
use of org.openremote.model.value.StringValue in project openremote by openremote.
the class AbstractTcpServerProtocol method doLinkProtocolConfiguration.
@Override
protected void doLinkProtocolConfiguration(AssetAttribute protocolConfiguration) {
final AttributeRef protocolRef = protocolConfiguration.getReferenceOrThrow();
if (!protocolConfiguration.isEnabled()) {
updateStatus(protocolRef, ConnectionStatus.DISABLED);
return;
}
int port = protocolConfiguration.getMetaItem(META_PROTOCOL_PORT).flatMap(AbstractValueHolder::getValueAsInteger).orElseThrow(() -> new IllegalArgumentException("Missing or invalid require meta item: " + META_PROTOCOL_PORT));
Optional<StringValue> bindAddress = Values.getMetaItemValueOrThrow(protocolConfiguration, META_PROTOCOL_BIND_ADDRESS, StringValue.class, false, true);
LOG.info("Creating TCP server instance");
T tcpServer = createTcpServer(port, bindAddress.map(StringValue::getString).orElse(null), protocolConfiguration);
tcpServerMap.put(protocolRef, tcpServer);
startTcpServer(protocolRef, tcpServer);
if (!tcpServer.isStarted()) {
LOG.warning("Failed to start TCP server instance");
updateStatus(protocolRef, ConnectionStatus.ERROR);
} else {
updateStatus(protocolRef, ConnectionStatus.CONNECTED);
}
}
Aggregations