本文整理汇总了Java中com.google.apphosting.api.ApiProxy类的典型用法代码示例。如果您正苦于以下问题:Java ApiProxy类的具体用法?Java ApiProxy怎么用?Java ApiProxy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ApiProxy类属于com.google.apphosting.api包,在下文中一共展示了ApiProxy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.google.apphosting.api.ApiProxy; //导入依赖的package包/类
@Override
public void init() throws ServletException {
try {
ApiProxy.Environment env = ApiProxy.getCurrentEnvironment();
Map<String,Object> attr = env.getAttributes();
String hostname = (String) attr.get("com.google.appengine.runtime.default_version_hostname");
String url = hostname.contains("localhost:")
? System.getProperty("cloudsql-local") : System.getProperty("cloudsql");
log("connecting to: " + url);
try {
conn = DriverManager.getConnection(url);
} catch (SQLException e) {
throw new ServletException("Unable to connect to Cloud SQL", e);
}
} finally {
// Nothing really to do here.
}
}
示例2: wrap
import com.google.apphosting.api.ApiProxy; //导入依赖的package包/类
public static Response wrap(Response.ResponseBuilder builder) {
builder.header(CONNECT_TIME_HEADER, current().connectionStopwatch.elapsed(TimeUnit.NANOSECONDS));
builder.header(TRANSACT_TIME_HEADER, current().transactionStopwatch.elapsed(TimeUnit.NANOSECONDS));
builder.header(CONNECTION_COUNT_HEADER, current().connectionCount);
builder.header(REQUEST_ID_HEADER,
ApiProxy.getCurrentEnvironment().getAttributes().get("com.google.appengine.runtime.request_log_id"));
long totalRequestTime = TimeUnit.SECONDS.toMillis(60) - ApiProxy.getCurrentEnvironment().getRemainingMillis();
if(totalRequestTime > 0) {
builder.header(REQUEST_TIME_HEADER, TimeUnit.MILLISECONDS.toNanos(totalRequestTime));
}
return builder.build();
}
示例3: reconstructTask
import com.google.apphosting.api.ApiProxy; //导入依赖的package包/类
private static Task reconstructTask(HttpServletRequest request) {
Properties properties = new Properties();
Enumeration<?> paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String paramValue = request.getParameter(paramName);
properties.setProperty(paramName, paramValue);
}
String taskName = request.getHeader(TASK_NAME_REQUEST_HEADER);
Task task = Task.fromProperties(taskName, properties);
task.getQueueSettings().setDelayInSeconds(null);
String queueName = request.getHeader(TASK_QUEUE_NAME_HEADER);
if (queueName != null && !queueName.isEmpty()) {
String onQueue = task.getQueueSettings().getOnQueue();
if (onQueue == null || onQueue.isEmpty()) {
task.getQueueSettings().setOnQueue(queueName);
}
Map<String, Object> attributes = ApiProxy.getCurrentEnvironment().getAttributes();
attributes.put(TASK_QUEUE_NAME_HEADER, queueName);
}
return task;
}
示例4: run
import com.google.apphosting.api.ApiProxy; //导入依赖的package包/类
@Override
public Value<Void> run() {
int count = runCount.getAndIncrement();
if (count < 2) {
System.setProperty(SHOULD_FAIL_PROPERTY, "true");
}
Value<Integer> dummyValue;
if (usePromise) {
PromisedValue<Integer> promisedValue = newPromise();
(new Thread(new SupplyPromisedValueRunnable(ApiProxy.getCurrentEnvironment(),
promisedValue.getHandle()))).start();
dummyValue = promisedValue;
} else {
dummyValue = immediate(0);
}
futureCall(new ChildJob(), dummyValue);
return null;
}
示例5: doGet
import com.google.apphosting.api.ApiProxy; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ApiProxy.Delegate oldDelegate = setUpMockDelegate();
response.setContentType("text/plain");
try {
testOpenAndClose(response);
testConnectWriteAndRead(response);
testSocketOpt(response);
testSetDatagramSocketImpl(response);
testSocketImplConstructor(response);
} catch (AssertionFailedException e) {
return;
//return the error response
} finally {
ApiProxy.setDelegate(oldDelegate);
}
response.getWriter().print("Success!");
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:22,代码来源:TestDatagramSocketServlet.java
示例6: doGet
import com.google.apphosting.api.ApiProxy; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ApiProxy.Delegate oldDelegate = setUpMockDelegate();
response.setContentType("text/plain");
try {
testConnectWriteAndRead(response);
testTimedConnect(response);
testSocketOpt(response);
testSetSocketImpl(response);
testShutDownAndClose(response);
testProxyConstructor(response);
testSocketImplConstructor(response);
} catch (AssertionFailedException e) {
return;
//return the error response
} finally {
ApiProxy.setDelegate(oldDelegate);
}
response.getWriter().print("Success!");
}
示例7: doFlush
import com.google.apphosting.api.ApiProxy; //导入依赖的package包/类
private Future<byte[]> doFlush() {
UserAppLogGroup group = new UserAppLogGroup();
for (UserAppLogLine logLine : buffer) {
group.addLogLine(logLine);
}
buffer.clear();
currentByteCount = 0;
flushCount++;
stopwatch.reset();
FlushRequest request = new FlushRequest();
request.setLogsAsBytes(group.toByteArray());
// This assumes that we are always doing a flush from the request
// thread. See the TODO above.
ApiConfig apiConfig = new ApiConfig();
apiConfig.setDeadlineInSeconds(LOG_FLUSH_TIMEOUT_MS / 1000.0);
return ApiProxy.makeAsyncCall("logservice", "Flush", request.toByteArray(), apiConfig);
}
示例8: newThread
import com.google.apphosting.api.ApiProxy; //导入依赖的package包/类
/**
* Create a new {@link Thread} that executes {@code runnable} for the duration of the current
* request. This thread will be interrupted at the end of the current request.
*
* @param runnable The object whose run method is invoked when this thread is started. If null,
* this classes run method does nothing.
*
* @throws ApiProxy.ApiProxyException If called outside of a running request.
* @throws IllegalStateException If called after the request thread stops.
*/
@Override
public Thread newThread(final Runnable runnable) {
checkState(requestEnvironment != null,
"Request threads can only be created within the context of a running request.");
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
if (runnable == null) {
return;
}
checkState(allowNewRequestThreadCreation,
"Cannot start new threads after the request thread stops.");
ApiProxy.setEnvironmentForCurrentThread(requestEnvironment);
runnable.run();
}
});
checkState(
allowNewRequestThreadCreation, "Cannot create new threads after the request thread stops.");
synchronized (mutex) {
createdThreads.add(thread);
}
return thread;
}
示例9: testAPIExceptionWrapping
import com.google.apphosting.api.ApiProxy; //导入依赖的package包/类
public void testAPIExceptionWrapping() {
VmApiProxyDelegate delegate = new VmApiProxyDelegate(createMockHttpClient());
RuntimeException exception = delegate.constructApiException("logservice", "a");
assertEquals(LogServiceException.class, exception.getClass());
assertEquals("RCP Failure for API call: logservice a", exception.getMessage());
exception = delegate.constructApiException("modules", "b");
assertEquals(ModulesException.class, exception.getClass());
assertEquals("RCP Failure for API call: modules b", exception.getMessage());
exception = delegate.constructApiException("datastore_v3", "c");
assertEquals(DatastoreFailureException.class, exception.getClass());
assertEquals("RCP Failure for API call: datastore_v3 c", exception.getMessage());
exception = delegate.constructApiException("barf", "d");
assertEquals(ApiProxy.RPCFailedException.class, exception.getClass());
assertEquals(
"The remote RPC to the application server failed for the call barf.d().",
exception.getMessage());
}
示例10: VmRuntimeWebAppContext
import com.google.apphosting.api.ApiProxy; //导入依赖的package包/类
/**
* Creates a new VmRuntimeWebAppContext.
*/
public VmRuntimeWebAppContext() {
this.serverInfo = VmRuntimeUtils.getServerInfo();
_scontext = new VmRuntimeServletContext();
// Configure the Jetty SecurityHandler to understand our method of authentication
// (via the UserService). Only the default ConstraintSecurityHandler is supported.
AppEngineAuthentication.configureSecurityHandler(
(ConstraintSecurityHandler) getSecurityHandler(), this);
setMaxFormContentSize(MAX_RESPONSE_SIZE);
setConfigurationClasses(preconfigurationClasses);
// See http://www.eclipse.org/jetty/documentation/current/configuring-webapps.html#webapp-context-attributes
// We also want the Jetty container libs to be scanned for annotations.
setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*\\.jar");
metadataCache = new VmMetadataCache();
wallclockTimer = new VmTimer();
ApiProxy.setDelegate(new VmApiProxyDelegate());
}
示例11: log
import com.google.apphosting.api.ApiProxy; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @param throwable an exception associated with this log message,
* or {@code null}.
*/
@Override
public void log(String message, Throwable throwable) {
StringWriter writer = new StringWriter();
writer.append("javax.servlet.ServletContext log: ");
writer.append(message);
if (throwable != null) {
writer.append("\n");
throwable.printStackTrace(new PrintWriter(writer));
}
LogRecord.Level logLevel = throwable == null ? LogRecord.Level.info : LogRecord.Level.error;
ApiProxy.log(new ApiProxy.LogRecord(logLevel, System.currentTimeMillis() * 1000L,
writer.toString()));
}
示例12: runSyncCall
import com.google.apphosting.api.ApiProxy; //导入依赖的package包/类
@Override
protected byte[] runSyncCall(VmApiProxyEnvironment environment, String packageName,
String methodName, byte[] requestData, int timeoutMs) throws ApiProxy.ApiProxyException {
// Lots of tests triggers logging. Ignore calls to the logservice by default. Tests
// verifying logging behavior can enable the log api capture calling setIgnoreLogging(false).
if (ignoreLogging && "logservice".equals(packageName)) {
return new ApiBasePb.VoidProto().toByteArray();
}
if ("google.util".equals(packageName) && "Delay".equals(methodName)) {
return handleDelayApi(requestData);
}
requests.add(new ApiRequest(environment, packageName, methodName, requestData));
if (responses.isEmpty()) {
throw new RuntimeException(
"Got unexpected ApiProxy call to: " + packageName + "/" + methodName);
}
return responses.removeFirst().toByteArray();
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:19,代码来源:FakeableVmApiProxyDelegate.java
示例13: testAsyncRequests_WaitUntilDone
import com.google.apphosting.api.ApiProxy; //导入依赖的package包/类
public void testAsyncRequests_WaitUntilDone() throws Exception {
long sleepTime = 2000;
FakeableVmApiProxyDelegate fakeApiProxy = new FakeableVmApiProxyDelegate();
ApiProxy.setDelegate(fakeApiProxy);
HttpClient httpClient = new HttpClient();
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
GetMethod get = new GetMethod(createUrl("/sleep").toString());
get.addRequestHeader("Use-Async-Sleep-Api", "true");
get.addRequestHeader("Sleep-Time", Long.toString(sleepTime));
long startTime = System.currentTimeMillis();
int httpCode = httpClient.executeMethod(get);
assertEquals(200, httpCode);
Header vmApiWaitTime = get.getResponseHeader(VmRuntimeUtils.ASYNC_API_WAIT_HEADER);
assertNotNull(vmApiWaitTime);
assertTrue(Integer.parseInt(vmApiWaitTime.getValue()) > 0);
long elapsed = System.currentTimeMillis() - startTime;
assertTrue(elapsed >= sleepTime);
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:19,代码来源:VmRuntimeJettyKitchenSinkTest.java
示例14: testAuth_UserRequiredNoUser
import com.google.apphosting.api.ApiProxy; //导入依赖的package包/类
public void testAuth_UserRequiredNoUser() throws Exception {
String loginUrl = "http://login-url?url=http://test-app.googleapp.com/user/test-auth";
CreateLoginURLResponse loginUrlResponse = new CreateLoginURLResponse();
loginUrlResponse.setLoginUrl(loginUrl);
// Fake the expected call to "user/CreateLoginUrl".
FakeableVmApiProxyDelegate fakeApiProxy = new FakeableVmApiProxyDelegate();
ApiProxy.setDelegate(fakeApiProxy);
fakeApiProxy.addApiResponse(loginUrlResponse);
HttpClient httpClient = new HttpClient();
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
GetMethod get = new GetMethod(createUrl("/user/test-auth").toString());
get.setFollowRedirects(false);
int httpCode = httpClient.executeMethod(get);
assertEquals(302, httpCode);
Header redirUrl = get.getResponseHeader("Location");
assertEquals(loginUrl, redirUrl.getValue());
}
示例15: testAuth_AdminRequiredNoUser
import com.google.apphosting.api.ApiProxy; //导入依赖的package包/类
public void testAuth_AdminRequiredNoUser() throws Exception {
String loginUrl = "http://login-url?url=http://test-app.googleapp.com/user/test-auth";
CreateLoginURLResponse loginUrlResponse = new CreateLoginURLResponse();
loginUrlResponse.setLoginUrl(loginUrl);
// Fake the expected call to "user/CreateLoginUrl".
FakeableVmApiProxyDelegate fakeApiProxy = new FakeableVmApiProxyDelegate();
ApiProxy.setDelegate(fakeApiProxy);
fakeApiProxy.addApiResponse(loginUrlResponse);
HttpClient httpClient = new HttpClient();
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
GetMethod get = new GetMethod(createUrl("/admin/test-auth").toString());
get.setFollowRedirects(false);
int httpCode = httpClient.executeMethod(get);
assertEquals(302, httpCode);
Header redirUrl = get.getResponseHeader("Location");
assertEquals(loginUrl, redirUrl.getValue());
}