http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerComponent.java b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerComponent.java new file mode 100644 index 0000000..521d2a2 --- /dev/null +++ b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerComponent.java @@ -0,0 +1,83 @@ +/** + * 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.camel.component.iec60870.server; + +import java.net.UnknownHostException; +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.Endpoint; +import org.apache.camel.component.iec60870.AbstractIecComponent; +import org.apache.camel.component.iec60870.ConnectionId; +import org.apache.camel.component.iec60870.Constants; +import org.apache.camel.component.iec60870.ObjectAddress; +import org.eclipse.neoscada.protocol.iec60870.server.data.DataModuleOptions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ServerComponent extends AbstractIecComponent<ServerConnectionMultiplexor, ServerOptions> { + + private static final Logger LOG = LoggerFactory.getLogger(ServerComponent.class); + + public ServerComponent(final CamelContext context) { + super(ServerOptions.class, new ServerOptions(), context, ServerEndpoint.class); + } + + public ServerComponent() { + super(ServerOptions.class, new ServerOptions(), ServerEndpoint.class); + } + + @Override + protected void applyDataModuleOptions(final ServerOptions options, final Map<String, Object> parameters) { + if (parameters.get(Constants.PARAM_DATA_MODULE_OPTIONS) instanceof DataModuleOptions) { + options.setDataModuleOptions((DataModuleOptions)parameters.get(Constants.PARAM_DATA_MODULE_OPTIONS)); + } + } + + @Override + protected ServerConnectionMultiplexor createConnection(final ConnectionId id, final ServerOptions options) { + LOG.debug("Create new server - id: {}", id); + + try { + return new ServerConnectionMultiplexor(new ServerInstance(id.getHost(), id.getPort(), options)); + } catch (final UnknownHostException e) { + throw new RuntimeException(e); + } + } + + @Override + protected Endpoint createEndpoint(final String uri, final ServerConnectionMultiplexor connection, final ObjectAddress address) { + return new ServerEndpoint(uri, this, connection, address); + } + + /** + * Default connection options + * + * @param defaultConnectionOptions the new default connection options, must + * not be {@code null} + */ + @Override + public void setDefaultConnectionOptions(final ServerOptions defaultConnectionOptions) { + super.setDefaultConnectionOptions(defaultConnectionOptions); + } + + @Override + public ServerOptions getDefaultConnectionOptions() { + return super.getDefaultConnectionOptions(); + } + +}
http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerConnectionMultiplexor.java ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerConnectionMultiplexor.java b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerConnectionMultiplexor.java new file mode 100644 index 0000000..43c80a4 --- /dev/null +++ b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerConnectionMultiplexor.java @@ -0,0 +1,43 @@ +/** + * 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.camel.component.iec60870.server; + +import org.apache.camel.component.iec60870.AbstractConnectionMultiplexor; + +public class ServerConnectionMultiplexor extends AbstractConnectionMultiplexor { + + private final ServerInstance server; + + public ServerConnectionMultiplexor(final ServerInstance server) { + this.server = server; + } + + @Override + protected void performStart() throws Exception { + this.server.start(); + } + + @Override + protected void performStop() throws Exception { + this.server.stop(); + } + + public ServerInstance getServer() { + return this.server; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerConsumer.java b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerConsumer.java new file mode 100644 index 0000000..a947340 --- /dev/null +++ b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerConsumer.java @@ -0,0 +1,110 @@ +/** + * 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.camel.component.iec60870.server; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.Processor; +import org.apache.camel.component.iec60870.ObjectAddress; +import org.apache.camel.impl.DefaultConsumer; +import org.apache.camel.impl.DefaultMessage; +import org.eclipse.neoscada.protocol.iec60870.server.data.model.WriteModel.Request; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ServerConsumer extends DefaultConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(ServerConsumer.class); + + private final ServerInstance server; + private final ServerEndpoint endpoint; + + public ServerConsumer(final ServerEndpoint endpoint, final Processor processor, final ServerInstance server) { + super(endpoint, processor); + this.endpoint = endpoint; + this.server = server; + } + + @Override + protected void doStart() throws Exception { + super.doStart(); + this.server.setListener(this.endpoint.getAddress(), this::updateValue); + } + + @Override + protected void doStop() throws Exception { + this.server.setListener(this.endpoint.getAddress(), null); + super.doStop(); + } + + private CompletionStage<Void> updateValue(final Request<?> value) { + try { + // create exchange + + final Exchange exchange = getEndpoint().createExchange(); + exchange.setIn(mapMessage(value)); + + // create new future + + final CompletableFuture<Void> result = new CompletableFuture<>(); + + // process and map async callback to our future + + getAsyncProcessor().process(exchange, doneSync -> result.complete(null)); + + // return future + + return result; + + } catch (final Exception e) { + + // we failed triggering the process + + LOG.debug("Failed to process message", e); + + // create a future + + final CompletableFuture<Void> result = new CompletableFuture<>(); + + // complete it right away + + result.completeExceptionally(e); + + // return it + + return result; + } + } + + private Message mapMessage(final Request<?> request) { + final DefaultMessage message = new DefaultMessage(this.endpoint.getCamelContext()); + + message.setBody(request); + + message.setHeader("address", ObjectAddress.valueOf(request.getHeader().getAsduAddress(), request.getAddress())); + message.setHeader("value", request.getValue()); + message.setHeader("informationObjectAddress", request.getAddress()); + message.setHeader("asduHeader", request.getHeader()); + message.setHeader("type", request.getType()); + message.setHeader("execute", request.isExecute()); + + return message; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerEndpoint.java b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerEndpoint.java new file mode 100644 index 0000000..ebee197 --- /dev/null +++ b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerEndpoint.java @@ -0,0 +1,60 @@ +/** + * 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.camel.component.iec60870.server; + +import static java.util.Objects.requireNonNull; + +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.component.iec60870.AbstractIecEndpoint; +import org.apache.camel.component.iec60870.ObjectAddress; +import org.apache.camel.impl.DefaultComponent; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; + +@UriEndpoint(firstVersion = "2.20.0", scheme = "iec60870-server", syntax = "iec60870-server:endpointUri", title = "IEC 60870-5-104 server", consumerClass = ServerConsumer.class, label = "iot") +public class ServerEndpoint extends AbstractIecEndpoint<ServerConnectionMultiplexor> { + + /** + * Filter out all requests which don't have the execute bit set + */ + @UriParam(defaultValue = "true") + private boolean filterNonExecute = true; + + public ServerEndpoint(final String uri, final DefaultComponent component, final ServerConnectionMultiplexor connection, final ObjectAddress address) { + super(uri, component, requireNonNull(connection), address); + } + + @Override + public Producer createProducer() throws Exception { + return new ServerProducer(this, getConnection().getServer()); + } + + @Override + public Consumer createConsumer(final Processor processor) throws Exception { + return new ServerConsumer(this, processor, getConnection().getServer()); + } + + public void setFilterNonExecute(final boolean filterNonExecute) { + this.filterNonExecute = filterNonExecute; + } + + public boolean isFilterNonExecute() { + return this.filterNonExecute; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerInstance.java ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerInstance.java b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerInstance.java new file mode 100644 index 0000000..403ceb4 --- /dev/null +++ b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerInstance.java @@ -0,0 +1,190 @@ +/** + * 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.camel.component.iec60870.server; + +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; +import java.util.LinkedList; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.CompletionStage; +import java.util.concurrent.ConcurrentHashMap; + +import static java.util.Arrays.asList; + +import org.apache.camel.component.iec60870.DiscardAckModule; +import org.apache.camel.component.iec60870.ObjectAddress; +import org.eclipse.neoscada.protocol.iec60870.asdu.types.ASDUAddress; +import org.eclipse.neoscada.protocol.iec60870.asdu.types.InformationObjectAddress; +import org.eclipse.neoscada.protocol.iec60870.asdu.types.Value; +import org.eclipse.neoscada.protocol.iec60870.server.Server; +import org.eclipse.neoscada.protocol.iec60870.server.data.DataModule; +import org.eclipse.neoscada.protocol.iec60870.server.data.model.BackgroundModel; +import org.eclipse.neoscada.protocol.iec60870.server.data.model.ChangeDataModel; +import org.eclipse.neoscada.protocol.iec60870.server.data.model.ChangeModel; +import org.eclipse.neoscada.protocol.iec60870.server.data.model.WriteModel; +import org.eclipse.neoscada.protocol.iec60870.server.data.model.WriteModel.Action; +import org.eclipse.neoscada.protocol.iec60870.server.data.model.WriteModel.Request; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ServerInstance { + private static final Logger LOG = LoggerFactory.getLogger(ServerInstance.class); + + private final ServerOptions options; + + private final class DataModelImpl extends ChangeDataModel { + private DataModelImpl() { + super("Camel/IEC60870/DataModel"); + } + + @Override + protected ChangeModel createChangeModel() { + if (ServerInstance.this.options.getBufferingPeriod() != null && ServerInstance.this.options.getBufferingPeriod() > 0) { + LOG.info("Creating buffering change model: {} ms", ServerInstance.this.options.getBufferingPeriod()); + return makeBufferingChangeModel(ServerInstance.this.options.getBufferingPeriod()); + } else { + LOG.info("Creating instant change model"); + return makeInstantChangeModel(); + } + } + + @Override + protected WriteModel createWriteModel() { + return new WriteModel() { + + @Override + public Action prepareCommand(final Request<Boolean> request) { + return prepareAction(request); + } + + @Override + public Action prepareSetpointFloat(final Request<Float> request) { + return prepareAction(request); + } + + @Override + public Action prepareSetpointScaled(final Request<Short> request) { + return prepareAction(request); + } + }; + } + + @Override + protected BackgroundModel createBackgroundModel() { + if (ServerInstance.this.options.getBackgroundScanPeriod() > 0) { + LOG.info("Creating background scan model: {} ms", ServerInstance.this.options.getBackgroundScanPeriod()); + return makeDefaultBackgroundModel(); + } + LOG.info("Not creating background scan model"); + return null; + } + + @Override + public void notifyDataChange(final ASDUAddress asduAddress, final InformationObjectAddress informationObjectAddress, final Value<?> value, final boolean notify) { + super.notifyDataChange(asduAddress, informationObjectAddress, value, notify); + } + } + + @FunctionalInterface + public interface ServerObjectListener { + CompletionStage<Void> execute(Request<?> request); + } + + private final DataModelImpl dataModel = new DataModelImpl(); + + private Server server; + private DataModule dataModule; + private final InetSocketAddress address; + private final Map<ObjectAddress, ServerObjectListener> listeners = new ConcurrentHashMap<>(); + + public ServerInstance(final String host, final int port, final ServerOptions options) throws UnknownHostException { + this.options = options; + this.address = new InetSocketAddress(InetAddress.getByName(host), port); + } + + public void start() { + this.dataModel.start(); + this.dataModule = new DataModule(this.options.getDataModuleOptions(), this.dataModel); + this.server = new Server(this.address, this.options.getProtocolOptions(), asList(this.dataModule, new DiscardAckModule())); + } + + public void stop() { + final LinkedList<Exception> ex = new LinkedList<>(); + + if (this.server != null) { + try { + this.server.close(); + } catch (final Exception e) { + ex.add(e); + } + this.server = null; + } + if (this.dataModule != null) { + try { + this.dataModule.dispose(); + } catch (final Exception e) { + ex.add(e); + } + this.dataModule = null; + } + + // handle all exceptions + + final Exception e = ex.pollFirst(); + if (e != null) { + RuntimeException re; + if (e instanceof RuntimeException) { + re = (RuntimeException)e; + } else { + re = new RuntimeException(e); + } + ex.forEach(re::addSuppressed); + throw re; + } + } + + private Action prepareAction(final Request<?> request) { + final ObjectAddress address = ObjectAddress.valueOf(request.getHeader().getAsduAddress(), request.getAddress()); + final ServerObjectListener listener = this.listeners.get(address); + + if (listener == null) { + // no one is listening + return null; + } + + return () -> listener.execute(request); + } + + public void setListener(final ObjectAddress address, final ServerObjectListener listener) { + Objects.requireNonNull(address); + + if (listener != null) { + this.listeners.put(address, listener); + } else { + this.listeners.remove(address); + } + } + + public void notifyValue(final ObjectAddress address, final Value<?> value) { + Objects.requireNonNull(address); + Objects.requireNonNull(value); + + this.dataModel.notifyDataChange(address.getASDUAddress(), address.getInformationObjectAddress(), value, true); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerOptions.java ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerOptions.java b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerOptions.java new file mode 100644 index 0000000..021838b --- /dev/null +++ b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerOptions.java @@ -0,0 +1,152 @@ +/** + * 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.camel.component.iec60870.server; + +import java.util.Objects; + +import org.apache.camel.component.iec60870.BaseOptions; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriParams; +import org.eclipse.neoscada.protocol.iec60870.ProtocolOptions; +import org.eclipse.neoscada.protocol.iec60870.server.data.DataModuleOptions; + +@UriParams +public class ServerOptions extends BaseOptions<ServerOptions> { + + /** + * Data module options + */ + @UriParam(javaType = "DataModuleOptions", label = "data") + private DataModuleOptions.Builder dataModuleOptions; + + /** + * A time period in "ms" the protocol layer will buffer change events in + * order to send out aggregated change messages + */ + @UriParam(label = "data") + private Integer bufferingPeriod; + + // dummy for doc generation + /** + * Send booleans with timestamps + */ + @UriParam(label = "data", defaultValue = "true") + private boolean booleansWithTimestamp; + + // dummy for doc generation + /** + * Send floats with timestamps + */ + @UriParam(label = "data", defaultValue = "true") + private boolean floatsWithTimestamp; + + // dummy for doc generation + /** + * Number of spontaneous events to keep in the buffer. + * <p> + * When there are more than this number of spontaneous in events in the + * buffer, then events will be dropped in order to maintain the buffer size. + * </p> + */ + @UriParam(label = "data", defaultValue = "10") + private int spontaneousDuplicates; + + // dummy for doc generation + /** + * The period in "ms" between background transmission cycles. + * <p> + * If this is set to zero or less, background transmissions will be + * disabled. + * </p> + */ + @UriParam(label = "data", defaultValue = "60000") + private int backgroundScanPeriod; + + public ServerOptions() { + this.dataModuleOptions = new DataModuleOptions.Builder(); + } + + public ServerOptions(final ServerOptions other) { + this(other.getProtocolOptions(), other.getDataModuleOptions()); + } + + public ServerOptions(final ProtocolOptions protocolOptions, final DataModuleOptions dataModuleOptions) { + super(protocolOptions); + + Objects.requireNonNull(dataModuleOptions); + + this.dataModuleOptions = new DataModuleOptions.Builder(dataModuleOptions); + } + + @Override + public ServerOptions copy() { + return new ServerOptions(this); + } + + public void setDataModuleOptions(final DataModuleOptions dataModuleOptions) { + Objects.requireNonNull(dataModuleOptions); + + this.dataModuleOptions = new DataModuleOptions.Builder(dataModuleOptions); + } + + public void setBufferingPeriod(final Integer bufferingPeriod) { + this.bufferingPeriod = bufferingPeriod; + } + + public Integer getBufferingPeriod() { + return this.bufferingPeriod; + } + + // wrapper methods - DataModuleOptions + + public DataModuleOptions getDataModuleOptions() { + return this.dataModuleOptions.build(); + } + + public void setBooleansWithTimestamp(final boolean booleansWithTimestamp) { + this.dataModuleOptions.setBooleansWithTimestamp(booleansWithTimestamp); + } + + public boolean isBooleansWithTimestamp() { + return this.dataModuleOptions.isBooleansWithTimestamp(); + } + + public void setFloatsWithTimestamp(final boolean floatsWithTimestamp) { + this.dataModuleOptions.setFloatsWithTimestamp(floatsWithTimestamp); + } + + public boolean isFloatsWithTimestamp() { + return this.dataModuleOptions.isFloatsWithTimestamp(); + } + + public void setSpontaneousDuplicates(final int spontaneousDuplicates) { + this.dataModuleOptions.setSpontaneousDuplicates(spontaneousDuplicates); + } + + public int getSpontaneousDuplicates() { + return this.dataModuleOptions.getSpontaneousDuplicates(); + } + + public void setBackgroundScanPeriod(final int backgroundScanPeriod) { + this.dataModuleOptions.setBackgroundScanPeriod(backgroundScanPeriod); + } + + public int getBackgroundScanPeriod() { + return this.dataModuleOptions.getBackgroundScanPeriod(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerProducer.java b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerProducer.java new file mode 100644 index 0000000..d8ae1e5 --- /dev/null +++ b/components/camel-iec60870/src/main/java/org/apache/camel/component/iec60870/server/ServerProducer.java @@ -0,0 +1,68 @@ +/** + * 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.camel.component.iec60870.server; + +import org.apache.camel.Exchange; +import org.apache.camel.impl.DefaultProducer; +import org.eclipse.neoscada.protocol.iec60870.asdu.types.Value; + +public class ServerProducer extends DefaultProducer { + + private final ServerEndpoint endpoint; + private final ServerInstance server; + + public ServerProducer(final ServerEndpoint endpoint, final ServerInstance server) { + super(endpoint); + this.endpoint = endpoint; + this.server = server; + } + + @Override + public void process(final Exchange exchange) throws Exception { + final Value<?> value = mapToCommand(exchange); + this.server.notifyValue(this.endpoint.getAddress(), value); + } + + private Value<?> mapToCommand(final Exchange exchange) { + final Object body = exchange.getIn().getBody(); + + if (body instanceof Value<?>) { + return (Value<?>)body; + } + + if (body instanceof Float || body instanceof Double) { + return Value.ok(((Number)body).floatValue()); + } + + if (body instanceof Boolean) { + return Value.ok((Boolean)body); + } + + if (body instanceof Short || body instanceof Byte || body instanceof Integer || body instanceof Long) { + return convertToShort(((Number)body).longValue()); + } + + throw new IllegalArgumentException("Unable to map body to a value: " + body); + } + + private Value<?> convertToShort(final long value) { + if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { + throw new IllegalArgumentException(String.format("Value must be between %s and %s", Short.MIN_VALUE, Short.MAX_VALUE)); + } + return Value.ok((short)value); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/main/resources/META-INF/LICENSE.txt ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/main/resources/META-INF/LICENSE.txt b/components/camel-iec60870/src/main/resources/META-INF/LICENSE.txt new file mode 100755 index 0000000..6b0b127 --- /dev/null +++ b/components/camel-iec60870/src/main/resources/META-INF/LICENSE.txt @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/main/resources/META-INF/NOTICE.txt ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/main/resources/META-INF/NOTICE.txt b/components/camel-iec60870/src/main/resources/META-INF/NOTICE.txt new file mode 100644 index 0000000..2e215bf --- /dev/null +++ b/components/camel-iec60870/src/main/resources/META-INF/NOTICE.txt @@ -0,0 +1,11 @@ + ========================================================================= + == NOTICE file corresponding to the section 4 d of == + == the Apache License, Version 2.0, == + == in this case for the Apache Camel distribution. == + ========================================================================= + + This product includes software developed by + The Apache Software Foundation (http://www.apache.org/). + + Please read the different LICENSE files present in the licenses directory of + this distribution. http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/main/resources/META-INF/services/org/apache/camel/component/iec60870-client ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/main/resources/META-INF/services/org/apache/camel/component/iec60870-client b/components/camel-iec60870/src/main/resources/META-INF/services/org/apache/camel/component/iec60870-client new file mode 100644 index 0000000..4194ef0 --- /dev/null +++ b/components/camel-iec60870/src/main/resources/META-INF/services/org/apache/camel/component/iec60870-client @@ -0,0 +1,18 @@ +# +# 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. +# + +class=org.apache.camel.component.iec60870.client.ClientComponent \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/main/resources/META-INF/services/org/apache/camel/component/iec60870-server ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/main/resources/META-INF/services/org/apache/camel/component/iec60870-server b/components/camel-iec60870/src/main/resources/META-INF/services/org/apache/camel/component/iec60870-server new file mode 100644 index 0000000..25afe0d --- /dev/null +++ b/components/camel-iec60870/src/main/resources/META-INF/services/org/apache/camel/component/iec60870-server @@ -0,0 +1,18 @@ +# +# 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. +# + +class=org.apache.camel.component.iec60870.server.ServerComponent \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/ConnectionIdTest.java ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/ConnectionIdTest.java b/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/ConnectionIdTest.java new file mode 100644 index 0000000..c0f0b8e --- /dev/null +++ b/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/ConnectionIdTest.java @@ -0,0 +1,71 @@ +/** + * 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.camel.component.iec60870; + +import org.junit.Assert; +import org.junit.Test; + +public class ConnectionIdTest { + @Test + public void testNotEqual1() { + ConnectionId id1 = new ConnectionId("host", 1202, "id1"); + ConnectionId id2 = new ConnectionId("host", 1202, "id2"); + Assert.assertFalse("Must be different", id1.equals(id2)); + } + + @Test + public void testNotEqual2() { + ConnectionId id1 = new ConnectionId("host1", 1202, "id"); + ConnectionId id2 = new ConnectionId("host2", 1202, "id"); + Assert.assertFalse("Must be different", id1.equals(id2)); + } + + @Test + public void testNotEqual3() { + ConnectionId id1 = new ConnectionId("host", 1202_1, "id"); + ConnectionId id2 = new ConnectionId("host", 1202_2, "id"); + Assert.assertFalse("Must be different", id1.equals(id2)); + } + + @Test(expected = IllegalArgumentException.class) + public void testIllegal1() { + new ConnectionId("host", -1, "id"); + } + + @Test + public void testGetters() { + ConnectionId id = new ConnectionId("host", 1202, "id"); + Assert.assertEquals("host", id.getHost()); + Assert.assertEquals(1202, id.getPort()); + Assert.assertEquals("id", id.getConnectionId()); + } + + @Test + public void testEqual1() { + ConnectionId id1 = new ConnectionId("host", 1202, "id"); + ConnectionId id2 = new ConnectionId("host", 1202, "id"); + Assert.assertTrue("Must be equal", id1.equals(id2)); + } + + @Test + public void testEqual2() { + ConnectionId id1 = new ConnectionId("host", 1202, "id"); + ConnectionId id2 = new ConnectionId("host", 1202, "id"); + + Assert.assertTrue("Hash code must be equal", id1.hashCode() == id2.hashCode()); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/ConnectionTest.java ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/ConnectionTest.java b/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/ConnectionTest.java new file mode 100644 index 0000000..81d79b7 --- /dev/null +++ b/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/ConnectionTest.java @@ -0,0 +1,171 @@ +/** + * 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.camel.component.iec60870; + +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.AssertionClause; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.eclipse.neoscada.protocol.iec60870.asdu.types.Value; +import org.eclipse.neoscada.protocol.iec60870.server.data.model.WriteModel.Request; +import org.junit.Test; + +public class ConnectionTest extends CamelTestSupport { + + private static final String DIRECT_SEND_S_1 = "direct:sendServer1"; + + private static final String DIRECT_SEND_C_1 = "direct:sendClient1"; + + private static final String MOCK_CLIENT_1 = "mock:testClient1"; + + private static final String MOCK_CLIENT_2 = "mock:testClient2"; + + private static final String MOCK_SERVER_1 = "mock:testServer1"; + + @Produce(uri = DIRECT_SEND_S_1) + protected ProducerTemplate producerServer1; + + @Produce(uri = DIRECT_SEND_C_1) + protected ProducerTemplate producerClient1; + + @EndpointInject(uri = MOCK_CLIENT_1) + protected MockEndpoint testClient1Endpoint; + + @EndpointInject(uri = MOCK_CLIENT_2) + protected MockEndpoint testClient2Endpoint; + + @EndpointInject(uri = MOCK_SERVER_1) + protected MockEndpoint testServer1Endpoint; + + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + + final int port = Ports.pickServerPort(); + + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from(DIRECT_SEND_S_1).toF("iec60870-server:localhost:%s/00-00-00-00-01", port); + fromF("iec60870-client:localhost:%s/00-00-00-00-01", port).to(MOCK_CLIENT_1); + fromF("iec60870-client:localhost:%s/00-00-00-00-02", port).to(MOCK_CLIENT_2); + + from(DIRECT_SEND_C_1).toF("iec60870-client:localhost:%s/00-00-00-01-01", port); + fromF("iec60870-server:localhost:%s/00-00-00-01-01", port).to(MOCK_SERVER_1); + } + }; + } + + @Test + public void testFloat1() throws InterruptedException { + this.producerServer1.sendBody(1.23f); + + // expect - count + + this.testClient1Endpoint.setExpectedCount(1); + this.testClient2Endpoint.setExpectedCount(0); + + // expect + + expectValue(testClient1Endpoint.message(0), assertGoodValue(1.23f)); + + // assert + + assertMockEndpointsSatisfied(1_000, TimeUnit.MILLISECONDS); + } + + @Test + public void testBoolean1() throws InterruptedException { + this.producerServer1.sendBody(true); + + // expect - count + + this.testClient1Endpoint.setExpectedCount(1); + this.testClient2Endpoint.setExpectedCount(0); + + // expect + + expectValue(testClient1Endpoint.message(0), assertGoodValue(true)); + + // assert + + assertMockEndpointsSatisfied(1_000, TimeUnit.MILLISECONDS); + } + + @Test + public void testCommand1() throws InterruptedException { + + Thread.sleep(1_000); + + this.producerClient1.sendBody(true); + + // expect - count + + this.testServer1Endpoint.setExpectedCount(1); + + // expect + + expectRequest(testServer1Endpoint.message(0), expectRequest(true)); + + // assert + + assertMockEndpointsSatisfied(2_000, TimeUnit.MILLISECONDS); + System.out.println(testServer1Endpoint.getExchanges().get(0).getIn().getBody()); + + } + + private <T> void expectValue(AssertionClause message, Consumer<Value<?>> consumer) { + message.predicate(exchange -> { + final Value<?> body = exchange.getIn().getBody(Value.class); + consumer.accept(body); + return true; + }); + } + + private <T> void expectRequest(AssertionClause message, Consumer<Request<?>> consumer) { + message.predicate(exchange -> { + final Request<?> body = exchange.getIn().getBody(Request.class); + consumer.accept(body); + return true; + }); + } + + public static Consumer<Value<?>> assertGoodValue(final Object expectedValue) { + return value -> { + assertNotNull(value); + assertEquals(expectedValue, value.getValue()); + assertTrue(value.getQualityInformation().isValid()); + assertTrue(value.getQualityInformation().isTopical()); + assertFalse(value.getQualityInformation().isBlocked()); + assertFalse(value.getQualityInformation().isSubstituted()); + }; + } + + private Consumer<Request<?>> expectRequest(final Object expectedValue) { + return value -> { + assertNotNull(value); + assertEquals(expectedValue, value.getValue()); + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/Ports.java ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/Ports.java b/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/Ports.java new file mode 100644 index 0000000..7b30b71 --- /dev/null +++ b/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/Ports.java @@ -0,0 +1,32 @@ +/** + * 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.camel.component.iec60870; + +import java.io.IOException; +import java.net.ServerSocket; + +public final class Ports { + + private Ports() { + } + + public static int pickServerPort() throws IOException { + try (ServerSocket socket = new ServerSocket(0)) { + return socket.getLocalPort(); + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/testing/ExampleApplication1.java ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/testing/ExampleApplication1.java b/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/testing/ExampleApplication1.java new file mode 100644 index 0000000..1d144fb --- /dev/null +++ b/components/camel-iec60870/src/test/java/org/apache/camel/component/iec60870/testing/ExampleApplication1.java @@ -0,0 +1,76 @@ +/** + * 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.camel.component.iec60870.testing; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.DefaultCamelContext; + +public class ExampleApplication1 { + public static void main(final String[] args) throws Exception { + new ExampleApplication1().run(); + } + + private void run() throws Exception { + final CamelContext context = new DefaultCamelContext(); + + context.addRoutes(new RouteBuilder() { + + @Override + public void configure() throws Exception { + + from("timer:foo") // + .setBody(simple("${random(10)}"))// + .convertBodyTo(Float.class) // + .to("iec60870-client:localhost:2404/0-1-2-3-4") // + .to("iec60870-client:localhost:2405/0-1-2-3-4") // + .setBody(simple("Timer: ${body}")) // + .to("stream:err"); + + from("iec60870-server:localhost:2404/0-1-2-3-4") // + .setBody(simple("${body.value}")) // + .to("iec60870-server:localhost:2404/0-1-2-3-4") // + .setBody(simple("Server 1: ${body}")) // + .to("stream:err"); + + from("iec60870-server:localhost:2405/0-1-2-3-4") // + .setBody(simple("${body.value}")) // + .to("iec60870-server:localhost:2405/0-1-2-3-4") // + .setBody(simple("Server 2: ${body}")) // + .to("stream:err"); + + from("iec60870-client:localhost:2404/0-1-2-3-4") // + .setBody(simple("From 1: ${body}")) // + .to("stream:err"); + + from("iec60870-client:localhost:2405/0-1-2-3-4") // + .setBody(simple("From 2: ${body}")) // + .to("stream:err"); + } + }); + + // start + + context.start(); + + // sleep + + while (true) { + Thread.sleep(Long.MAX_VALUE); + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/camel-iec60870/src/test/resources/log4j2.properties ---------------------------------------------------------------------- diff --git a/components/camel-iec60870/src/test/resources/log4j2.properties b/components/camel-iec60870/src/test/resources/log4j2.properties new file mode 100644 index 0000000..8534003 --- /dev/null +++ b/components/camel-iec60870/src/test/resources/log4j2.properties @@ -0,0 +1,28 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +appender.file.type = File +appender.file.name = file +appender.file.fileName = target/camel-iec60870-test.log +appender.file.layout.type = PatternLayout +appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n +appender.out.type = Console +appender.out.name = out +appender.out.layout.type = PatternLayout +appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n +rootLogger.level = INFO +rootLogger.appenderRef.file.ref = file http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/components/readme.adoc ---------------------------------------------------------------------- diff --git a/components/readme.adoc b/components/readme.adoc index 3edbf09..969911d 100644 --- a/components/readme.adoc +++ b/components/readme.adoc @@ -1018,7 +1018,7 @@ Miscellaneous Components ^^^^^^^^^^^^^^^^^^^^^^^^ // others: START -Number of Miscellaneous Components: 37 in 37 JAR artifacts (13 deprecated) +Number of Miscellaneous Components: 38 in 38 JAR artifacts (14 deprecated) [width="100%",cols="4,1,5",options="header"] |======================================================================= @@ -1074,6 +1074,8 @@ Number of Miscellaneous Components: 37 in 37 JAR artifacts (13 deprecated) | link:camel-spring-cloud-netflix/src/main/docs/spring-cloud-netflix.adoc[Spring Cloud Netflix] (camel-spring-cloud-netflix) | 2.19 | Camel Cloud integration with Spring Cloud Netflix +| link:camel-spring-dm/src/main/docs/spring-dm.adoc[Spring DM] (camel-spring-dm) | 2.18 | *deprecated* Camel SpringDM (OSGi) XML DSL + | link:camel-spring-javaconfig/src/main/docs/spring-javaconfig.adoc[Spring Java Configuration] (camel-spring-javaconfig) | 2.0 | Using Camel with Spring Java Configuration | link:camel-spring-security/src/main/docs/spring-security.adoc[Spring Security] (camel-spring-security) | 2.3 | Security using Spring Security http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index 4a3cf0e..4faa687 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -508,6 +508,7 @@ <narayana-version>5.6.4.Final</narayana-version> <neethi-bundle-version>3.0.1</neethi-bundle-version> <nekohtml-version>1.9.22</nekohtml-version> + <neoscada-version>0.4.0</neoscada-version> <netty3-version>3.10.6.Final</netty3-version> <netty-version>4.1.14.Final</netty-version> <netty40-version>4.0.50.Final</netty40-version> @@ -1335,6 +1336,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-iec60870</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-infinispan</artifactId> <version>${project.version}</version> </dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/platforms/spring-boot/components-starter/camel-iec60870-starter/pom.xml ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-iec60870-starter/pom.xml b/platforms/spring-boot/components-starter/camel-iec60870-starter/pom.xml new file mode 100644 index 0000000..0208573 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-iec60870-starter/pom.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>components-starter</artifactId> + <version>2.20.0-SNAPSHOT</version> + </parent> + <artifactId>camel-iec60870-starter</artifactId> + <packaging>jar</packaging> + <name>Spring-Boot Starter :: Camel :: IEC 60870</name> + <description>Spring-Boot Starter for Camel IEC 60870-5-104 support</description> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + <version>${spring-boot-version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-iec60870</artifactId> + <version>${project.version}</version> + </dependency> + <!--START OF GENERATED CODE--> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core-starter</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring-boot-starter</artifactId> + </dependency> + <!--END OF GENERATED CODE--> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/platforms/spring-boot/components-starter/camel-iec60870-starter/src/main/java/org/apache/camel/component/iec60870/client/springboot/ClientComponentAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-iec60870-starter/src/main/java/org/apache/camel/component/iec60870/client/springboot/ClientComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-iec60870-starter/src/main/java/org/apache/camel/component/iec60870/client/springboot/ClientComponentAutoConfiguration.java new file mode 100644 index 0000000..731a1ec --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-iec60870-starter/src/main/java/org/apache/camel/component/iec60870/client/springboot/ClientComponentAutoConfiguration.java @@ -0,0 +1,128 @@ +/** + * 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.camel.component.iec60870.client.springboot; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Generated; +import org.apache.camel.CamelContext; +import org.apache.camel.component.iec60870.client.ClientComponent; +import org.apache.camel.spi.ComponentCustomizer; +import org.apache.camel.spi.HasId; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.ComponentConfigurationProperties; +import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator; +import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; + +/** + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") +@Configuration +@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class, + ClientComponentAutoConfiguration.GroupConditions.class}) +@AutoConfigureAfter(CamelAutoConfiguration.class) +@EnableConfigurationProperties({ComponentConfigurationProperties.class, + ClientComponentConfiguration.class}) +public class ClientComponentAutoConfiguration { + + private static final Logger LOGGER = LoggerFactory + .getLogger(ClientComponentAutoConfiguration.class); + @Autowired + private ApplicationContext applicationContext; + @Autowired + private CamelContext camelContext; + @Autowired + private ClientComponentConfiguration configuration; + @Autowired(required = false) + private List<ComponentCustomizer<ClientComponent>> customizers; + + static class GroupConditions extends GroupCondition { + public GroupConditions() { + super("camel.component", "camel.component.iec60870-client"); + } + } + + @Lazy + @Bean(name = "iec60870-client-component") + @ConditionalOnMissingBean(ClientComponent.class) + public ClientComponent configureClientComponent() throws Exception { + ClientComponent component = new ClientComponent(); + component.setCamelContext(camelContext); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(configuration, parameters, null, + false); + for (Map.Entry<String, Object> entry : parameters.entrySet()) { + Object value = entry.getValue(); + Class<?> paramClass = value.getClass(); + if (paramClass.getName().endsWith("NestedConfiguration")) { + Class nestedClass = null; + try { + nestedClass = (Class) paramClass.getDeclaredField( + "CAMEL_NESTED_CLASS").get(null); + HashMap<String, Object> nestedParameters = new HashMap<>(); + IntrospectionSupport.getProperties(value, nestedParameters, + null, false); + Object nestedProperty = nestedClass.newInstance(); + IntrospectionSupport.setProperties(camelContext, + camelContext.getTypeConverter(), nestedProperty, + nestedParameters); + entry.setValue(nestedProperty); + } catch (NoSuchFieldException e) { + } + } + } + IntrospectionSupport.setProperties(camelContext, + camelContext.getTypeConverter(), component, parameters); + if (ObjectHelper.isNotEmpty(customizers)) { + for (ComponentCustomizer<ClientComponent> customizer : customizers) { + boolean useCustomizer = (customizer instanceof HasId) + ? HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.component.customizer", + "camel.component.iec60870-client.customizer", + ((HasId) customizer).getId()) + : HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.component.customizer", + "camel.component.iec60870-client.customizer"); + if (useCustomizer) { + LOGGER.debug("Configure component {}, with customizer {}", + component, customizer); + customizer.customize(component); + } + } + } + return component; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/platforms/spring-boot/components-starter/camel-iec60870-starter/src/main/java/org/apache/camel/component/iec60870/client/springboot/ClientComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-iec60870-starter/src/main/java/org/apache/camel/component/iec60870/client/springboot/ClientComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-iec60870-starter/src/main/java/org/apache/camel/component/iec60870/client/springboot/ClientComponentConfiguration.java new file mode 100644 index 0000000..beaa2a9 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-iec60870-starter/src/main/java/org/apache/camel/component/iec60870/client/springboot/ClientComponentConfiguration.java @@ -0,0 +1,87 @@ +/** + * 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.camel.component.iec60870.client.springboot; + +import javax.annotation.Generated; +import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Camel IEC 60870-5-104 support + * + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") +@ConfigurationProperties(prefix = "camel.component.iec60870-client") +public class ClientComponentConfiguration + extends + ComponentConfigurationPropertiesCommon { + + /** + * Default connection options + */ + private ClientOptionsNestedConfiguration defaultConnectionOptions; + /** + * Whether the component should resolve property placeholders on itself when + * starting. Only properties which are of String type can use property + * placeholders. + */ + private Boolean resolvePropertyPlaceholders = true; + + public ClientOptionsNestedConfiguration getDefaultConnectionOptions() { + return defaultConnectionOptions; + } + + public void setDefaultConnectionOptions( + ClientOptionsNestedConfiguration defaultConnectionOptions) { + this.defaultConnectionOptions = defaultConnectionOptions; + } + + public Boolean getResolvePropertyPlaceholders() { + return resolvePropertyPlaceholders; + } + + public void setResolvePropertyPlaceholders( + Boolean resolvePropertyPlaceholders) { + this.resolvePropertyPlaceholders = resolvePropertyPlaceholders; + } + + public static class ClientOptionsNestedConfiguration { + public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.iec60870.client.ClientOptions.class; + private Byte causeSourceAddress; + /** + * Whether background scan transmissions should be ignored. + */ + private Boolean ignoreBackgroundScan = true; + + public Byte getCauseSourceAddress() { + return causeSourceAddress; + } + + public void setCauseSourceAddress(Byte causeSourceAddress) { + this.causeSourceAddress = causeSourceAddress; + } + + public Boolean getIgnoreBackgroundScan() { + return ignoreBackgroundScan; + } + + public void setIgnoreBackgroundScan(Boolean ignoreBackgroundScan) { + this.ignoreBackgroundScan = ignoreBackgroundScan; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/eb4f6059/platforms/spring-boot/components-starter/camel-iec60870-starter/src/main/java/org/apache/camel/component/iec60870/server/springboot/ServerComponentAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-iec60870-starter/src/main/java/org/apache/camel/component/iec60870/server/springboot/ServerComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-iec60870-starter/src/main/java/org/apache/camel/component/iec60870/server/springboot/ServerComponentAutoConfiguration.java new file mode 100644 index 0000000..ac6a0c5 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-iec60870-starter/src/main/java/org/apache/camel/component/iec60870/server/springboot/ServerComponentAutoConfiguration.java @@ -0,0 +1,128 @@ +/** + * 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.camel.component.iec60870.server.springboot; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Generated; +import org.apache.camel.CamelContext; +import org.apache.camel.component.iec60870.server.ServerComponent; +import org.apache.camel.spi.ComponentCustomizer; +import org.apache.camel.spi.HasId; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.ComponentConfigurationProperties; +import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator; +import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; + +/** + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") +@Configuration +@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class, + ServerComponentAutoConfiguration.GroupConditions.class}) +@AutoConfigureAfter(CamelAutoConfiguration.class) +@EnableConfigurationProperties({ComponentConfigurationProperties.class, + ServerComponentConfiguration.class}) +public class ServerComponentAutoConfiguration { + + private static final Logger LOGGER = LoggerFactory + .getLogger(ServerComponentAutoConfiguration.class); + @Autowired + private ApplicationContext applicationContext; + @Autowired + private CamelContext camelContext; + @Autowired + private ServerComponentConfiguration configuration; + @Autowired(required = false) + private List<ComponentCustomizer<ServerComponent>> customizers; + + static class GroupConditions extends GroupCondition { + public GroupConditions() { + super("camel.component", "camel.component.iec60870-server"); + } + } + + @Lazy + @Bean(name = "iec60870-server-component") + @ConditionalOnMissingBean(ServerComponent.class) + public ServerComponent configureServerComponent() throws Exception { + ServerComponent component = new ServerComponent(); + component.setCamelContext(camelContext); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(configuration, parameters, null, + false); + for (Map.Entry<String, Object> entry : parameters.entrySet()) { + Object value = entry.getValue(); + Class<?> paramClass = value.getClass(); + if (paramClass.getName().endsWith("NestedConfiguration")) { + Class nestedClass = null; + try { + nestedClass = (Class) paramClass.getDeclaredField( + "CAMEL_NESTED_CLASS").get(null); + HashMap<String, Object> nestedParameters = new HashMap<>(); + IntrospectionSupport.getProperties(value, nestedParameters, + null, false); + Object nestedProperty = nestedClass.newInstance(); + IntrospectionSupport.setProperties(camelContext, + camelContext.getTypeConverter(), nestedProperty, + nestedParameters); + entry.setValue(nestedProperty); + } catch (NoSuchFieldException e) { + } + } + } + IntrospectionSupport.setProperties(camelContext, + camelContext.getTypeConverter(), component, parameters); + if (ObjectHelper.isNotEmpty(customizers)) { + for (ComponentCustomizer<ServerComponent> customizer : customizers) { + boolean useCustomizer = (customizer instanceof HasId) + ? HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.component.customizer", + "camel.component.iec60870-server.customizer", + ((HasId) customizer).getId()) + : HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.component.customizer", + "camel.component.iec60870-server.customizer"); + if (useCustomizer) { + LOGGER.debug("Configure component {}, with customizer {}", + component, customizer); + customizer.customize(component); + } + } + } + return component; + } +} \ No newline at end of file