App Engine Java SDK version 1.9.14
[gae.git] / java / src / main / com / google / appengine / tools / remoteapi / BaseRemoteApiClient.java
blob11fa2a4b2756efe5e160763b8633f1636329b61c
1 package com.google.appengine.tools.remoteapi;
3 import java.util.ArrayList;
4 import java.util.List;
6 /**
7 * Base implementation for Remote API clients.
8 */
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();
20 this.appId = appId;
23 /**
24 * @return the path to the remote api for this app (if logged in), {@code null} otherwise
26 @Override
27 public String getRemoteApiPath() {
28 return remoteApiPath;
31 /**
32 * @return the app id for this app (if logged in), {@code null} otherwise
34 @Override
35 public String getAppId() {
36 return appId;
39 String getHostname() {
40 return hostname;
43 int getPort() {
44 return port;
47 /**
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;
58 /**
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
61 * in element 1.
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"});
67 return headers;