Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: pkg/appengine/lib/src/protobuf_api/rpc/rpc_service_remote_api.dart

Issue 804973002: Add appengine/gcloud/mustache dependencies. (Closed) Base URL: git@github.com:dart-lang/pub-dartlang-dart.git@master
Patch Set: Added AUTHORS/LICENSE/PATENTS files Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library rpc_service_remote_api;
6
7 import 'dart:async';
8 import 'dart:io';
9
10 import 'rpc_service.dart';
11 import 'rpc_service_base.dart';
12 import '../internal/remote_api.pb.dart' as remote_api;
13
14
15 class RPCServiceRemoteApi extends RPCServiceBase implements RPCService {
16 static const Map<String, String> ADDITIONAL_HEADERS = const <String,String> {
17 'X-Google-RPC-Service-Endpoint': 'app-engine-apis',
18 'X-Google-RPC-Service-Method': '/VMRemoteAPI.CallRemoteAPI',
19 };
20
21 final String hostname;
22 final int port;
23 final String path;
24 HttpClient _client;
25
26 RPCServiceRemoteApi(this.hostname, this.port, {this.path: '/rpc_http'}) {
27 _client = new HttpClient();
28 }
29
30 Future<List<int>> call(String apiPackage,
31 String method,
32 List<int> requestProtocolBuffer,
33 {String ticket: 'invalid-ticket'}) {
34 var apiRequest = new remote_api.Request();
35 apiRequest.serviceName = apiPackage;
36 apiRequest.method = method;
37 apiRequest.request = requestProtocolBuffer;
38 apiRequest.requestId = ticket;
39 return _call(apiRequest).then((remote_api.Response apiResponse) {
40 if (apiResponse.hasApplicationError()) {
41 throw new RpcApplicationError(
42 apiResponse.applicationError.code,
43 apiResponse.applicationError.detail);
44 }
45 // This can e.g. happen if the request ticket is invalid.
46 if (apiResponse.hasRpcError()) {
47 throw new Exception('An internal error occured while making a RPC call '
48 '(${apiResponse.rpcError.toString().replaceAll('\n',' ')}).');
49 }
50 return apiResponse.response;
51 });
52 }
53
54 Future<remote_api.Response> _call(remote_api.Request rpcRequest) {
55 return makeRequest(hostname,
56 port,
57 path,
58 rpcRequest.writeToBuffer(),
59 ADDITIONAL_HEADERS).then((List<int> responseData) {
60 return new remote_api.Response.fromBuffer(responseData);
61 });
62 }
63 }
OLDNEW
« no previous file with comments | « pkg/appengine/lib/src/protobuf_api/rpc/rpc_service_base.dart ('k') | pkg/appengine/lib/src/protobuf_api/user_service.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698