@Override
    protected UriInfo validateAndCleanUriInfo(UriInfo uriInfo) {
      if (uriInfo.getScheme() == null) {
        throw new IllegalArgumentException("Missing scheme in amqp URI: " + uriInfo);
      }

      if (uriInfo.getHost() == null) {
        throw new IllegalArgumentException("Missing authority in amqp URI: " + uriInfo);
      }

      if (uriInfo.getUserName() == null || uriInfo.getPassword() == null) {
        throw new IllegalArgumentException("Missing userinfo in amqp URI: " + uriInfo);
      }

      String path = uriInfo.getPath();
      if (path == null) {
        // NO-OP, this is the default vhost
      } else {
        // Check that the path only has a single segment.  As we have an authority component
        // in the URI, paths always begin with a slash.
        if (path.indexOf('/') != -1) {
          throw new IllegalArgumentException("Multiple segments in path of amqp URI: " + uriInfo);
        }
      }
      return uriInfo;
    }
Пример #2
0
  @Override
  protected UriInfo validateAndCleanUriInfo(UriInfo uriInfo) {
    if (!"amqp".equals(uriInfo.getScheme())) {
      throw new IllegalArgumentException("wrong scheme in amqp URI: " + uriInfo);
    }

    if (uriInfo.getHost() == null) {
      throw new IllegalArgumentException("missing authority in amqp URI: " + uriInfo);
    }

    int port = uriInfo.getPort();
    if (port == -1) {
      port = 5672;
    }

    String userName = uriInfo.getUserName();
    String password = uriInfo.getPassword();

    if (userName == null || password == null) {
      throw new IllegalArgumentException("missing userinfo in amqp URI: " + uriInfo);
    }

    String path = uriInfo.getPath();
    if (path == null) {
      // The RabbitMQ default vhost
      path = "/";
    } else {
      // Check that the path only has a single segment.  As we have an authority component
      // in the URI, paths always begin with a slash.
      if (path.indexOf('/') != -1) {
        throw new IllegalArgumentException("multiple segemtns in path of amqp URI: " + uriInfo);
      }
    }
    return new UriInfo(
        uriInfo.getScheme(),
        uriInfo.getHost(),
        port,
        uriInfo.getUserName(),
        uriInfo.getPassword(),
        path);
  }