当前位置: 首页>>代码示例>>Java>>正文


Java Response类代码示例

本文整理汇总了Java中play.libs.WS.Response的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Response类属于play.libs.WS包,在下文中一共展示了Response类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAudienceManagerUser

import play.libs.WS.Response; //导入依赖的package包/类
/**
 * Gets the audience manager username using the access token for the blog
 * user. Returns null if could not get user.
 * 
 * @return The username in audiencemanager, or null.
 */
private static String getAudienceManagerUser() {
    String audienceManagerUser = null;
    // This call will always succeed if you have valid audience manager
    // credentials.
    // It's a good way to check that everything is working.
    Response selfResponse = audienceManagerWS("users/self").get().get();
    if (selfResponse.getStatus() == OK) {
        audienceManagerUser = selfResponse.asJson().get("username")
                .asText();
    }
    return audienceManagerUser;
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:audiencemanager-api-sample-app,代码行数:19,代码来源:Application.java

示例2: postOnTemplateURLWithJsonParams_ShouldGenerateFeededDocumentWithAcceptedMimeType

import play.libs.WS.Response; //导入依赖的package包/类
private void postOnTemplateURLWithJsonParams_ShouldGenerateFeededDocumentWithAcceptedMimeType(
		final String templateName, final String requestedMimeType,
		final String fileNameOfExpectedDocument) {

	running(testServer(DOCSERVER_PORT, fakeApplication()), HTMLUNIT,
			new Callback<TestBrowser>() {
				@Override
				public void invoke(TestBrowser browser) {
					String jsonParams = null;
					Application application = Play.application();
					String jsonParamFilePath = "test/json/test_invoice.json";
					try {
						File paramFile = application
								.getFile(jsonParamFilePath);
						jsonParams = FileUtils.readFileToString(paramFile);
					} catch (IOException e) {
						fail("Can't open file json param file \""
								+ jsonParamFilePath + "\": ("
								+ e.toString() + ")");
					}
					WSRequestHolder url = WS.url(DOCSERVER_BASE_URL
							+ "/document/" + templateName);
					url = url.setHeader("Content-Type", "application/json");
					url = url.setHeader("Accept", requestedMimeType);

					Promise<Response> response = url.post(jsonParams);
					assertEquals(200, response.get(1L, TimeUnit.MINUTES)
							.getStatus());

					File expectedFile = application.getFile("test/"
							+ fileNameOfExpectedDocument);
					assertResponseEqualsFileContent(expectedFile, response,
							true);
				}

			});
}
 
开发者ID:Altrusoft,项目名称:docserv,代码行数:38,代码来源:IntegrationTest.java

示例3: requestingTemplateShouldReturnTemplate

import play.libs.WS.Response; //导入依赖的package包/类
@Test
public void requestingTemplateShouldReturnTemplate() {
	running(testServer(DOCSERVER_PORT, fakeApplication()), HTMLUNIT,
			new Callback<TestBrowser>() {
				@Override
				public void invoke(TestBrowser browser) {
					Application application = Play.application();

					WSRequestHolder url = WS.url(DOCSERVER_BASE_URL
							+ "/assets/templates/Invoice/template.odt");
					// TODO: strange that these headers do not matter
					// (default
					// values? then add test-cases)
					//
					// url = url.setHeader("Content-Type",
					// "application/json");
					// url = url.setHeader("Accept",
					// "application/vnd.oasis.opendocument.text");

					// url = url.setHeader("Accept",
					// "application/vnd.oasis.opendocument.text;charset=UTF-8");

					Promise<Response> response = url.get();
					assertEquals(200, response.get(1L, TimeUnit.MINUTES)
							.getStatus());

					File expectedFile = application
							.getFile("public/templates/Invoice/template.odt");
					assertResponseEqualsFileContent(expectedFile, response,
							false);
				}
			});
}
 
开发者ID:Altrusoft,项目名称:docserv,代码行数:34,代码来源:IntegrationTest.java

示例4: exchangeCodeForToken

import play.libs.WS.Response; //导入依赖的package包/类
public static Promise<Result> exchangeCodeForToken(String code) {
    String clientId = Play.application().configuration()
            .getString("audienceManager.clientId");
    String clientSecret = Play.application().configuration()
            .getString("audienceManager.clientSecret");
    String tokenUrl = Play.application().configuration()
            .getString("audienceManager.tokenUrl");

    // Sets the Authorization header to Basic
    // Base64Encoded(clientId:clientSecret) (includes colon)
    Promise<Result> promiseResult = WS
            .url(tokenUrl)
            .setAuth(clientId, clientSecret, AuthScheme.BASIC)
            .setContentType("application/x-www-form-urlencoded")
            .setHeader("Accept", "application/json")
            .post(String.format(TOKEN_TEMPLATE, clientId, clientSecret,
                    code)).map(new Function<Response, Result>() {

                @Override
                public Result apply(Response response) throws Throwable {
                    if (response.getStatus() == 200) {
                        AudienceManagerAuthentication aamAuth = new AudienceManagerAuthentication();
                        JsonNode responseJson = response.asJson();
                        aamAuth.accessToken = responseJson.get(
                                "access_token").asText();
                        aamAuth.refreshToken = responseJson.get(
                                "refresh_token").asText();
                        aamAuth.email = Application.getLoggedInUser().email;
                        AudienceManagerAuthentication.create(aamAuth);
                        Logger.info(String
                                .format("Got access token %s and refresh token %s for %s",
                                        aamAuth.accessToken,
                                        aamAuth.refreshToken, aamAuth.email));
                    } else {
                        Logger.error(String.format(
                                "Eror getting tokens for %s:\n %d\n %s",
                                Application.getLoggedInUser(),
                                response.getStatus(), response.getBody()));
                    }
                    return redirect(routes.Application.index());
                }

            });

    return promiseResult;
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:audiencemanager-api-sample-app,代码行数:47,代码来源:OAuth2AudienceManager.java

示例5: assertResponseEqualsFileContent

import play.libs.WS.Response; //导入依赖的package包/类
void assertResponseEqualsFileContent(File expectedFile,
		Promise<Response> response, boolean onlyVerifySize) {
	FileInputStream expectedInputStream = null;
	InputStream actualInputStream = null;
	try {
		expectedInputStream = FileUtils.openInputStream(expectedFile);
		byte[] expectedByteArray = IOUtils.toByteArray(expectedInputStream);

		actualInputStream = response.get().getBodyAsStream();
		byte[] actualByteArray = IOUtils.toByteArray(actualInputStream);

		// We only verify PDF files by raw text. This because we are
		// depending on external OpenOffice lib while
		// executing this test, and we can't be too pedantic about the
		// details then (different OO versions
		// generate slightly different files)
		if (expectedFile.getName().endsWith(".pdf")) {
			String expectedPageOne = getNonWhiteSpacesFromPDF(expectedByteArray);
			String actualPageOne = getNonWhiteSpacesFromPDF(actualByteArray);
			assertEquals("Not same text on first page", expectedPageOne,
					actualPageOne);
		} else {
			if (onlyVerifySize) {
				boolean hasGeneratedFileCorrectSize = (expectedByteArray.length == actualByteArray.length);
				if (!hasGeneratedFileCorrectSize) {
					fail("Actual file is not same size expected (exp size="
							+ new String(expectedByteArray).length()
							+ " act size="
							+ new String(actualByteArray).length());
				}
			} else {
				if (!Arrays.areEqual(expectedByteArray, actualByteArray)) {
					fail("Actual file has not same content as expected (exp size="
							+ new String(expectedByteArray).length()
							+ " act size="
							+ new String(actualByteArray).length());
				}
			}
		}
	} catch (IOException e) {
		fail("Can't compare generated file with expected file: "
				+ e.getMessage());
	} finally {
		IOUtils.closeQuietly(expectedInputStream);
		IOUtils.closeQuietly(actualInputStream);
	}
}
 
开发者ID:Altrusoft,项目名称:docserv,代码行数:48,代码来源:IntegrationTest.java


注:本文中的play.libs.WS.Response类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。