コード例 #1
0
    @Override
    public void handle(ServiceRequest<GetEndpointsRequest, GetEndpointsResponse> service)
        throws UaException {
      GetEndpointsRequest request = service.getRequest();

      String endpointUrl = request.getEndpointUrl();
      if (endpointUrl == null) endpointUrl = "";

      UaTcpStackServer server = servers.get(endpointUrl);

      EndpointDescription[] endpoints =
          (server != null) ? server.getEndpointDescriptions() : new EndpointDescription[0];

      List<String> profileUris =
          request.getProfileUris() != null
              ? Lists.newArrayList(request.getProfileUris())
              : Lists.newArrayList();

      EndpointDescription[] filtered =
          Arrays.stream(endpoints)
              .filter(ed -> filterProfileUris(ed, profileUris))
              .filter(this::filterEndpointUrls)
              .toArray(EndpointDescription[]::new);

      service.setResponse(new GetEndpointsResponse(service.createResponseHeader(), filtered));
    }
コード例 #2
0
    @Override
    public void handle(ServiceRequest<FindServersRequest, FindServersResponse> service)
        throws UaException {
      FindServersRequest request = service.getRequest();

      List<ApplicationDescription> servers = Lists.newArrayList();
      List<String> serverUris = Lists.newArrayList(request.getServerUris());

      for (UaTcpStackServer server : registered) {
        ApplicationDescription description = server.getApplicationDescription();

        if (serverUris.isEmpty()) {
          servers.add(description);
        } else {
          if (serverUris.contains(description.getApplicationUri())) {
            servers.add(description);
          }
        }
      }

      ResponseHeader header = service.createResponseHeader();
      FindServersResponse response =
          new FindServersResponse(
              header, servers.toArray(new ApplicationDescription[servers.size()]));

      service.setResponse(response);
    }
コード例 #3
0
  public FallbackServer() {
    UaTcpStackServerConfig config =
        UaTcpStackServerConfig.builder()
            .setApplicationName(LocalizedText.english("Stack Discovery Server"))
            .setApplicationUri("urn:digitalpetri:stack:discovery")
            .setProductUri("http://www.digitalpetri.com/opc-ua")
            .build();

    server = new UaTcpStackServer(config);
    server.addRequestHandler(FindServersRequest.class, new FindServersHandler());
    server.addRequestHandler(GetEndpointsRequest.class, new GetEndpointsHandler());
  }
コード例 #4
0
 public void unregisterServer(UaTcpStackServer server) {
   if (registered.remove(server)) {
     server.getDiscoveryUrls().forEach(servers::remove);
   }
 }
コード例 #5
0
 public void registerServer(UaTcpStackServer server) {
   if (registered.add(server)) {
     server.getDiscoveryUrls().forEach(url -> servers.put(url, server));
   }
 }