/** * Creates a new {@code Service} instance using a map of arguments. * * @param args A {@code Map} of arguments to initialize the service. */ public Service(Map<String, Object> args) { super(); this.app = Args.<String>get(args, "app", null); this.host = Args.<String>get(args, "host", DEFAULT_HOST); this.owner = Args.<String>get(args, "owner", null); this.port = Args.<Integer>get(args, "port", DEFAULT_PORT); this.scheme = Args.<String>get(args, "scheme", DEFAULT_SCHEME); this.token = Args.<String>get(args, "token", null); this.username = (String)args.get("username"); this.password = (String)args.get("password"); this.httpsHandler = Args.<URLStreamHandler>get(args, "httpsHandler", null); this.setSslSecurityProtocol(Args.get(args, "SSLSecurityProtocol", Service.getSslSecurityProtocol())); this.addCookie((String)args.get("cookie")); this.connectTimeout = Args.<Integer>get(args, "connectTimeout", null); this.readTimeout = Args.<Integer>get(args, "readTimeout", null); }
/** * Creates a new {@code Service} instance using a collection of arguments. * * @param args The {@code ServiceArgs} to initialize the service. */ // NOTE: This overload exists primarily to provide better documentation // for the "args" parameter. @SuppressWarnings("deprecation") public Service(ServiceArgs args) { super(); // NOTE: Must read the deprecated fields for backward compatibility. // (Consider the case where the fields are initialized directly, // rather than using the new setters.) // NOTE: Must also read the underlying dictionary for forward compatibility. // (Consider the case where the user calls Map.put() directly, // rather than using the new setters.) this.app = Args.<String>get(args, "app", args.app != null ? args.app : null); this.host = Args.<String>get(args, "host", args.host != null ? args.host : DEFAULT_HOST); this.owner = Args.<String>get(args, "owner", args.owner != null ? args.owner : null); this.port = Args.<Integer>get(args, "port", args.port != null ? args.port : DEFAULT_PORT); this.scheme = Args.<String>get(args, "scheme", args.scheme != null ? args.scheme : DEFAULT_SCHEME); this.token = Args.<String>get(args, "token", args.token != null ? args.token : null); this.username = (String)args.get("username"); this.password = (String)args.get("password"); this.httpsHandler = Args.<URLStreamHandler>get(args, "httpsHandler", null); this.setSslSecurityProtocol(Args.get(args, "SSLSecurityProtocol", Service.getSslSecurityProtocol())); this.addCookie((String)args.get("cookie")); }