Set the target host for this request. @param target host for this request. Must be an absolute target. @return a RequestTemplate for chaining.
(String target)
| 498 | * @return a RequestTemplate for chaining. |
| 499 | */ |
| 500 | public RequestTemplate target(String target) { |
| 501 | /* target can be empty */ |
| 502 | if (Util.isBlank(target)) { |
| 503 | return this; |
| 504 | } |
| 505 | |
| 506 | /* verify that the target contains the scheme, host and port */ |
| 507 | if (!UriUtils.isAbsolute(target)) { |
| 508 | throw new IllegalArgumentException("target values must be absolute."); |
| 509 | } |
| 510 | if (target.endsWith("/")) { |
| 511 | target = target.substring(0, target.length() - 1); |
| 512 | } |
| 513 | try { |
| 514 | /* parse the target */ |
| 515 | URI targetUri = URI.create(target); |
| 516 | |
| 517 | if (Util.isNotBlank(targetUri.getRawQuery())) { |
| 518 | /* |
| 519 | * target has a query string, we need to make sure that they are recorded as queries |
| 520 | */ |
| 521 | this.extractQueryTemplates(targetUri.getRawQuery(), true); |
| 522 | } |
| 523 | |
| 524 | /* strip the query string */ |
| 525 | this.target = |
| 526 | targetUri.getScheme() + "://" + targetUri.getRawAuthority() + targetUri.getRawPath(); |
| 527 | if (targetUri.getFragment() != null) { |
| 528 | this.fragment = "#" + targetUri.getFragment(); |
| 529 | } |
| 530 | } catch (IllegalArgumentException iae) { |
| 531 | /* the uri provided is not a valid one, we can't continue */ |
| 532 | throw new IllegalArgumentException("Target is not a valid URI.", iae); |
| 533 | } |
| 534 | return this; |
| 535 | } |
| 536 | |
| 537 | /** |
| 538 | * The URL for the request. If the template has not been resolved, the url will represent a uri |