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


Java WSClient类代码示例

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


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

示例1: testsWithServer

import play.libs.ws.WSClient; //导入依赖的package包/类
@Test
public void testsWithServer() throws Exception {
    final TestServer testServer = testServer(fakeApplication());
    running(testServer, () -> {
        try (final WSClient wsClient = WS.newClient(testServer.port())) {
            final WSResponse wsResponse = wsClient
                    .url("/playbasics/show2")
                    .setQueryString("name=John")
                    .get().toCompletableFuture().get();
            assertThat(wsResponse.getStatus()).isEqualTo(OK);
            assertThat(wsResponse.getBody()).isEqualTo("Hello John!");
        } catch (IOException | InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }
    });
}
 
开发者ID:commercetools,项目名称:commercetools-sunrise-java-training,代码行数:17,代码来源:MyControllerMixScopeTest.java

示例2: shutdown

import play.libs.ws.WSClient; //导入依赖的package包/类
/**
 * After the test is finished, revoke the permission to the app so the login dialog appears again on the next login when running the test
 * See https://developers.facebook.com/docs/facebook-login/permissions/v2.1#revokelogin
 */
@After
public void shutdown() throws Exception {
    final FacebookAuthUser authUser = (FacebookAuthUser) (MyTestUserServiceService.getLastAuthUser());

    if (authUser == null) {
        // in case the test failed, we don't have an authUser
        return;
    }

    final String url = getConfig().getString("userInfoUrl") + "/permissions";

    WSClient wsClient = app.injector().instanceOf(WSClient.class);
    wsClient
            .url(url)
            .setQueryParameter(OAuth2AuthProvider.Constants.ACCESS_TOKEN, authUser.getOAuth2AuthInfo().getAccessToken())
            .setQueryParameter("format", "json")
            .setQueryParameter("method", "delete")
            .get().toCompletableFuture().get(10, TimeUnit.SECONDS);
}
 
开发者ID:Vadus,项目名称:songs_play,代码行数:24,代码来源:FacebookOAuth2Test.java

示例3: testInServerThroughUrl

import play.libs.ws.WSClient; //导入依赖的package包/类
@Test
public void testInServerThroughUrl() throws Exception {
    // Tests using a scoped WSClient to talk to the server through a port.
    try (WSClient ws = WSTestClient.newClient(this.testServer.port())) {
        CompletionStage<WSResponse> stage = ws.url("/").get();
        WSResponse response = stage.toCompletableFuture().get();
        String body = response.getBody();
        assertThat(body, containsString("Add Person"));
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
开发者ID:play2-maven-plugin,项目名称:play2-maven-test-projects,代码行数:13,代码来源:IntegrationTest.java

示例4: StockSentiment

import play.libs.ws.WSClient; //导入依赖的package包/类
@Inject
public StockSentiment(WSClient wsClient, Config configuration, HttpExecutionContext ec) {
    this.wsClient = wsClient;
    this.ec = ec;
    this.sentimentUrl = configuration.getString("sentiment.url");
    this.tweetUrl = configuration.getString("tweet.url");
}
 
开发者ID:play2-maven-plugin,项目名称:play2-maven-test-projects,代码行数:8,代码来源:StockSentiment.java

示例5: configure

import play.libs.ws.WSClient; //导入依赖的package包/类
@Override
protected void configure() {
    bind(OAuth.Configuration.class).toProvider(new Provider<OAuth.Configuration>() {
        @Override
        public OAuth.Configuration get() {
            return new OAuth.Configuration(
                    "https://accounts.google.com/o/oauth2/auth",
                    "https://accounts.google.com/o/oauth2/token",
                    "1079303020045-4kie53crgo06su51pi3dnbm90thc2q33.apps.googleusercontent.com",
                    "9-PoA1ZwynHJlE4Y3VY8fONX",
                    "https://www.googleapis.com/auth/plus.login",
                    controllers.routes.Items.list().url()
            );
        }
    });
    bind(WSClient.class).toProvider(new Provider<WSClient>() {
        @Override
        public WSClient get() {
            return injector.getInstance(Service.class).ws;
        }
    });
}
 
开发者ID:julienrf,项目名称:pfe-samples,代码行数:23,代码来源:Global.java

示例6: Rules

import play.libs.ws.WSClient; //导入依赖的package包/类
@Inject
public Rules(
    final IServicesConfig servicesConfig,
    final WSClient wsClient,
    final IAlarms alarmsService) {

    this.storageUrl = servicesConfig.getKeyValueStorageUrl() + "/collections/rules/values";
    this.wsClient = wsClient;
    this.alarmsService = alarmsService;
}
 
开发者ID:Azure,项目名称:device-telemetry-java,代码行数:11,代码来源:Rules.java

示例7: setUp

import play.libs.ws.WSClient; //导入依赖的package包/类
@Before
public void setUp() {
    // setup before every test
    try {
        IServicesConfig servicesConfig = new Config().getServicesConfig();
        IStorageClient client = mock(IStorageClient.class);
        this.wsClient = mock(WSClient.class);
        this.alarms = new Alarms(servicesConfig, client);
        this.rules = new Rules(servicesConfig, wsClient, alarms);
        this.controller = new AlarmsByRuleController(this.alarms, this.rules);
    } catch (Exception ex) {
        log.error("Exception setting up test", ex);
        Assert.fail(ex.getMessage());
    }
}
 
开发者ID:Azure,项目名称:device-telemetry-java,代码行数:16,代码来源:AlarmsByRuleControllerTest.java

示例8: LoginController

import play.libs.ws.WSClient; //导入依赖的package包/类
@Inject 
public LoginController(CidadaoDAO dao, WSClient ws, FormFactory formFactory,
		Configuration configuration, JPAApi api, AuthUtils authenticator) {
	this.dao = dao;
	this.ws = ws;
	this.formFactory = formFactory;
	this.api = api;
	this.authenticator = authenticator;
	this.facebookSecret = configuration.getString(ProvedorDeLogin.FACEBOOK.getSecretProp());
	this.googleSecret = configuration.getString(ProvedorDeLogin.GOOGLE.getSecretProp());
}
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:12,代码来源:LoginController.java

示例9: testIndex

import play.libs.ws.WSClient; //导入依赖的package包/类
/**
 * Test method for {@link controllers.CidadeController#index()}.
 */
@Test
public void testIndex() {
    String url = "/api";

    try (WSClient ws = WS.newClient(this.testServer.port())) {
        CompletionStage<WSResponse> stage = ws.url(url).get();
        WSResponse response = stage.toCompletableFuture().get();
        assertEquals(OK, response.getStatus());
    } catch (InterruptedException | ExecutionException | IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:16,代码来源:HTTPStackTest.java

示例10: testCidadeInexistente

import play.libs.ws.WSClient; //导入依赖的package包/类
/**
 * Test method for {@link controllers.CidadeController#get(Long)}.
 */
@Test
public void testCidadeInexistente() {
    String url = "/api/cidade/0";

    try (WSClient ws = WS.newClient(this.testServer.port())) {
        CompletionStage<WSResponse> stage = ws.url(url).get();
        WSResponse response = stage.toCompletableFuture().get();
        assertEquals(NOT_FOUND, response.getStatus());
    } catch (InterruptedException | ExecutionException | IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:16,代码来源:HTTPStackTest.java

示例11: testCidadeExistenteEmas

import play.libs.ws.WSClient; //导入依赖的package包/类
/**
 * Test method for {@link controllers.CidadeController#get(Long)}.
 */
@Test
public void testCidadeExistenteEmas() throws Exception {
    String url = "/api/cidade/2505907";

    try (WSClient ws = WS.newClient(this.testServer.port())) {
        CompletionStage<WSResponse> stage = ws.url(url).get();
        WSResponse response = stage.toCompletableFuture().get();
        assertEquals(OK, response.getStatus());
        Cidade cidade = Json.fromJson(response.asJson(), Cidade.class);
        assertEquals(2505907, cidade.getId().longValue());
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:18,代码来源:HTTPStackTest.java

示例12: testCidadesSimilaresAUmaInexistente

import play.libs.ws.WSClient; //导入依赖的package包/类
/**
 * Test method for {@link controllers.CidadeController#get(Long)}.
 */
@Test
public void testCidadesSimilaresAUmaInexistente() throws Exception {
    String url = "/api/cidade/0/similares";

    try (WSClient ws = WS.newClient(this.testServer.port())) {
        CompletionStage<WSResponse> stage = ws.url(url).get();
        WSResponse response = stage.toCompletableFuture().get();
        assertEquals(NOT_FOUND, response.getStatus());
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:16,代码来源:HTTPStackTest.java

示例13: testCidadesSimilaresAEmas

import play.libs.ws.WSClient; //导入依赖的package包/类
/**
 * Test method for {@link controllers.CidadeController#get(Long)}.
 */
@Test
public void testCidadesSimilaresAEmas() throws Exception {
    String url = "/api/cidade/2505907/similares";

    try (WSClient ws = WS.newClient(this.testServer.port())) {
        CompletionStage<WSResponse> stage = ws.url(url).get();
        WSResponse response = stage.toCompletableFuture().get();
        assertEquals(OK, response.getStatus());
        assertTrue(response.asJson().elements().hasNext());
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:17,代码来源:HTTPStackTest.java

示例14: test404

import play.libs.ws.WSClient; //导入依赖的package包/类
@Test
public void test404() throws Exception {
    String url = "http://localhost:" + this.testServer.port() + "/api/alou";

    try (WSClient ws = WS.newClient(this.testServer.port())) {
        CompletionStage<WSResponse> stage = ws.url(url).get();
        WSResponse response = stage.toCompletableFuture().get();
        assertEquals(NOT_FOUND, response.getStatus());
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:13,代码来源:HTTPStackTest.java

示例15: testSaveMensagem

import play.libs.ws.WSClient; //导入依赖的package包/类
@Test
  @Ignore
  public void testSaveMensagem() throws Exception {
  	String url = "/api/mensagem";

  	WSClient ws = WS.newClient(this.testServer.port());

  	CompletionStage<WSResponse> stage = ws.url(url).get();
  	WSResponse response = stage.toCompletableFuture().get();
      assertEquals(OK, response.getStatus());
      assertFalse(response.asJson().elements().hasNext());

  	stage = ws.url(url).post(Json.parse("{\"titulo\": \"Urgente!\", \"conteudo\": \"Siga em frente... olhe para o lado!\",\"autor\": \"Ministério da Justiça\"}"));
  	response = stage.toCompletableFuture().get();
  	assertEquals(OK, response.getStatus());
  	
      stage = ws.url(url).get();
      response = stage.toCompletableFuture().get();
      assertEquals(OK, response.getStatus());
      JsonNode jsonNode = response.asJson().elements().next();
Mensagem mensagem = Json.fromJson(jsonNode, Mensagem.class);
      assertNotNull(mensagem);
      assertNotNull(mensagem.getId());
  }
 
开发者ID:nazareno,项目名称:diferentonas-server,代码行数:25,代码来源:HTTPStackTest.java


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