1 package com
.google
.appengine
.tools
.remoteapi
;
3 import java
.util
.ArrayList
;
7 * Base implementation for Remote API clients.
9 abstract class BaseRemoteApiClient
implements RemoteApiClient
{
11 private final String hostname
;
12 private final int port
;
13 private final String remoteApiPath
;
14 private final String appId
;
16 BaseRemoteApiClient(RemoteApiOptions options
, String appId
) {
17 this.hostname
= options
.getHostname();
18 this.port
= options
.getPort();
19 this.remoteApiPath
= options
.getRemoteApiPath();
24 * @return the path to the remote api for this app (if logged in), {@code null} otherwise
27 public String
getRemoteApiPath() {
32 * @return the app id for this app (if logged in), {@code null} otherwise
35 public String
getAppId() {
39 String
getHostname() {
48 * Returns a full URL given a path.
50 String
makeUrl(String path
) {
51 if (!path
.startsWith("/")) {
52 throw new IllegalArgumentException("path doesn't start with a slash: " + path
);
54 String protocol
= port
== 443 ?
"https" : "http";
55 return protocol
+ "://" + hostname
+ ":" + port
+ path
;
59 * Returns a mutable list of headers required on all remote api requests.
60 * Each header is a 2-element array with the name in element 0 and the value
63 List
<String
[]> getHeadersBase() {
64 List
<String
[]> headers
= new ArrayList
<String
[]>();
65 headers
.add(new String
[]{"Host", hostname
});
66 headers
.add(new String
[]{"X-appcfg-api-version", "1"});