Skip to content

Commit

Permalink
fix(opcua): fix issues with empty port
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Aug 3, 2023
1 parent 68fc264 commit 40644f7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions plc4go/assets/testing/protocols/opcua/DriverTestsuite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@
<messageType dataType="string" bitLength="24" encoding="UTF-8">HEL</messageType>
<OpcuaHelloRequest>
<chunk dataType="string" bitLength="8" encoding="UTF-8">F</chunk>
<messageSize dataType="int" bitLength="32">52</messageSize>
<messageSize dataType="int" bitLength="32">47</messageSize>
<version dataType="int" bitLength="32">0</version>
<receiveBufferSize dataType="int" bitLength="32">65535</receiveBufferSize>
<sendBufferSize dataType="int" bitLength="32">65535</sendBufferSize>
<maxMessageSize dataType="int" bitLength="32">2097152</maxMessageSize>
<maxChunkCount dataType="int" bitLength="32">64</maxChunkCount>
<endpoint>
<PascalString>
<sLength dataType="int" bitLength="32">20</sLength>
<stringValue dataType="string" bitLength="160" encoding="UTF-8">opc.test://hurz:null</stringValue>
<sLength dataType="int" bitLength="32">15</sLength>
<stringValue dataType="string" bitLength="120" encoding="UTF-8">opc.test://hurz</stringValue>
</PascalString>
</endpoint>
</OpcuaHelloRequest>
Expand Down
10 changes: 8 additions & 2 deletions plc4go/internal/opcua/Driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ func (d *Driver) GetConnectionWithContext(ctx context.Context, transportUrl url.
configuration.host = transportHost
configuration.port = transportPort
configuration.transportEndpoint = transportEndpoint
configuration.endpoint = "opc." + transportCode + "://" + transportHost + ":" + transportPort + "" + transportEndpoint
portAddition := ""
if transportPort != "" {
portAddition += ":" + transportPort
}
configuration.endpoint = "opc." + transportCode + "://" + transportHost + portAddition + "" + transportEndpoint
d.log.Debug().Stringer("configuration", &configuration).Msg("working with configurartion")

if securityPolicy := configuration.securityPolicy; securityPolicy != "" && securityPolicy != "None" {
d.log.Trace().Str("securityPolicy", securityPolicy).Msg("working with security policy")
Expand All @@ -151,7 +156,8 @@ func (d *Driver) GetConnectionWithContext(ctx context.Context, transportUrl url.

// Create the new connection
connection := NewConnection(
codec, configuration,
codec,
configuration,
driverContext,
d.GetPlcTagHandler(),
driverOptions,
Expand Down
6 changes: 4 additions & 2 deletions plc4go/internal/opcua/SecureChannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,15 @@ func (s *SecureChannel) onConnect(ctx context.Context, connection *Connection, c
s.log.Debug().Msg("Opcua Driver running in ACTIVE mode.")
s.codec = connection.messageCodec // TODO: why would we need to set that?

hello := readWriteModel.NewOpcuaHelloRequest(FINAL_CHUNK,
hello := readWriteModel.NewOpcuaHelloRequest(
FINAL_CHUNK,
VERSION,
DEFAULT_RECEIVE_BUFFER_SIZE,
DEFAULT_SEND_BUFFER_SIZE,
DEFAULT_MAX_MESSAGE_SIZE,
DEFAULT_MAX_CHUNK_COUNT,
s.endpoint)
s.endpoint,
)

requestConsumer := func(transactionId int32) {
s.log.Trace().Int32("transactionId", transactionId).Msg("request consumer called")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public class OpcuaPlcDriver extends GeneratedDriverBase<OpcuaAPU> {

public static final Pattern URI_PATTERN = Pattern.compile("^(?<protocolCode>opcua)" +
INET_ADDRESS_PATTERN +
"(?<transportEndpoint>[\\w/=]*)[\\?]?" +
"(?<paramString>([^\\=]+\\=[^\\=&]+[&]?)*)"
"(?<transportEndpoint>[\\w/=]*)[?]?" +
"(?<paramString>([^=]+=[^=&]+&?)*)"
);

private boolean isEncrypted;
Expand Down Expand Up @@ -156,7 +156,8 @@ public PlcConnection getConnection(String connectionString) throws PlcConnection
configuration.setHost(transportHost);
configuration.setPort(transportPort);
configuration.setTransportEndpoint(transportEndpoint);
configuration.setEndpoint("opc." + transportCode + "://" + transportHost + ":" + transportPort + "" + transportEndpoint);
String portAddition = transportPort != null ? ":" + transportPort : "";
configuration.setEndpoint("opc." + transportCode + "://" + transportHost + portAddition + transportEndpoint);

// Try to find a transport in order to create a communication channel.
Transport transport = null;
Expand Down

0 comments on commit 40644f7

Please sign in to comment.