本文整理了Java中okhttp3.mockwebserver.MockWebServer.shutdown()
方法的一些代码示例,展示了MockWebServer.shutdown()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MockWebServer.shutdown()
方法的具体详情如下:
包路径:okhttp3.mockwebserver.MockWebServer
类名称:MockWebServer
方法名:shutdown
暂无
代码示例来源:origin: square/okhttp
@Override public void close() throws IOException {
shutdown();
}
代码示例来源:origin: square/okhttp
@Override protected synchronized void after() {
try {
shutdown();
} catch (IOException e) {
logger.log(Level.WARNING, "MockWebServer shutdown failed", e);
}
}
代码示例来源:origin: square/okhttp
public void run() throws Exception {
File socketFile = new File("/tmp/ClientAndServer.sock");
socketFile.delete(); // Clean up from previous runs.
MockWebServer server = new MockWebServer();
server.setServerSocketFactory(new UnixDomainServerSocketFactory(socketFile));
server.setProtocols(Collections.singletonList(Protocol.H2_PRIOR_KNOWLEDGE));
server.enqueue(new MockResponse().setBody("hello"));
server.start();
OkHttpClient client = new OkHttpClient.Builder()
.socketFactory(new UnixDomainSocketFactory(socketFile))
.protocols(Collections.singletonList(Protocol.H2_PRIOR_KNOWLEDGE))
.build();
Request request = new Request.Builder()
.url("http://publicobject.com/helloworld.txt")
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.body().string());
}
server.shutdown();
socketFile.delete();
}
代码示例来源:origin: spring-projects/spring-framework
@After
public void tearDown() throws Exception {
this.server.shutdown();
}
代码示例来源:origin: spring-projects/spring-framework
@After
public void tearDown() throws Exception {
this.server.shutdown();
}
代码示例来源:origin: spring-projects/spring-framework
@After
public void shutdown() throws IOException {
this.server.shutdown();
}
代码示例来源:origin: square/retrofit
public static void main(String... args) throws IOException, InterruptedException {
MockWebServer server = new MockWebServer();
server.start();
server.enqueue(new MockResponse());
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(server.url("/"))
.addConverterFactory(new JsonStringConverterFactory(GsonConverterFactory.create()))
.build();
Service service = retrofit.create(Service.class);
Call<ResponseBody> call = service.example(new Filter("123"));
Response<ResponseBody> response = call.execute();
// TODO handle user response...
// Print the request path that the server saw to show the JSON query param:
RecordedRequest recordedRequest = server.takeRequest();
System.out.println(recordedRequest.getPath());
server.shutdown();
}
}
代码示例来源:origin: square/retrofit
public static void main(String... args) throws IOException {
MockWebServer server = new MockWebServer();
server.start();
server.enqueue(new MockResponse().setBody("{\"name\": \"Jason\"}"));
server.enqueue(new MockResponse().setBody("<user name=\"Eximel\"/>"));
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(server.url("/"))
.addConverterFactory(new QualifiedTypeConverterFactory(
GsonConverterFactory.create(),
SimpleXmlConverterFactory.create()))
.build();
Service service = retrofit.create(Service.class);
User user1 = service.exampleJson().execute().body();
System.out.println("User 1: " + user1.name);
User user2 = service.exampleXml().execute().body();
System.out.println("User 2: " + user2.name);
server.shutdown();
}
}
代码示例来源:origin: square/retrofit
System.out.println("ERROR: " + error.message);
server.shutdown();
代码示例来源:origin: square/retrofit
public static void main(String... args) throws IOException, InterruptedException {
MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse());
server.enqueue(new MockResponse());
server.start();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(server.url("/"))
.addConverterFactory(new ChunkingConverterFactory())
.addConverterFactory(GsonConverterFactory.create())
.build();
Service service = retrofit.create(Service.class);
Repo retrofitRepo = new Repo("square", "retrofit");
service.sendNormal(retrofitRepo).execute();
RecordedRequest normalRequest = server.takeRequest();
System.out.println(
"Normal @Body Transfer-Encoding: " + normalRequest.getHeader("Transfer-Encoding"));
service.sendChunked(retrofitRepo).execute();
RecordedRequest chunkedRequest = server.takeRequest();
System.out.println(
"@Chunked @Body Transfer-Encoding: " + chunkedRequest.getHeader("Transfer-Encoding"));
server.shutdown();
}
}
代码示例来源:origin: bumptech/glide
@After
public void tearDown() throws IOException {
HttpURLConnection.setFollowRedirects(defaultFollowRedirects);
mockWebServer.shutdown();
}
代码示例来源:origin: bumptech/glide
@After
public void tearDown() throws IOException {
mockWebServer.shutdown();
requestQueue.stop();
}
代码示例来源:origin: square/retrofit
System.out.println("Library 4: " + library4.name);
server.shutdown();
代码示例来源:origin: spring-projects/spring-security
@After
public void cleanup() throws Exception {
validateMockitoUsage();
this.server.shutdown();
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void issuerWhenRequestedIssuerIsUnresponsiveThenThrowsIllegalArgumentException()
throws Exception {
this.server.shutdown();
assertThatCode(() -> ReactiveJwtDecoders.fromOidcIssuerLocation("https://issuer"))
.isInstanceOf(IllegalArgumentException.class);
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void decodeWhenJwkResponseIsMalformedThenReturnsStockException() throws Exception {
try ( MockWebServer server = new MockWebServer() ) {
server.enqueue(new MockResponse().setBody(MALFORMED_JWK_SET));
String jwkSetUrl = server.url("/.well-known/jwks.json").toString();
NimbusJwtDecoderJwkSupport jwtDecoder = new NimbusJwtDecoderJwkSupport(jwkSetUrl);
assertThatCode(() -> jwtDecoder.decode(SIGNED_JWT))
.isInstanceOf(JwtException.class)
.hasMessage("An error occurred while attempting to decode the Jwt: Malformed Jwk set");
server.shutdown();
}
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void decodeWhenJwkEndpointIsUnresponsiveThenReturnsJwtException() throws Exception {
try ( MockWebServer server = new MockWebServer() ) {
String jwkSetUri = server.url("/.well-known/jwks.json").toString();
NimbusJwtDecoder jwtDecoder = new NimbusJwtDecoder(
withJwkSetUri(jwkSetUri).build());
server.shutdown();
assertThatCode(() -> jwtDecoder.decode(SIGNED_JWT))
.isInstanceOf(JwtException.class)
.hasMessageContaining("An error occurred while attempting to decode the Jwt");
}
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void decodeWhenJwkEndpointIsUnresponsiveThenReturnsJwtException() throws Exception {
try ( MockWebServer server = new MockWebServer() ) {
server.enqueue(new MockResponse().setBody(MALFORMED_JWK_SET));
String jwkSetUrl = server.url("/.well-known/jwks.json").toString();
NimbusJwtDecoderJwkSupport jwtDecoder = new NimbusJwtDecoderJwkSupport(jwkSetUrl);
assertThatCode(() -> jwtDecoder.decode(SIGNED_JWT))
.isInstanceOf(JwtException.class)
.hasMessageContaining("An error occurred while attempting to decode the Jwt");
server.shutdown();
}
}
代码示例来源:origin: bumptech/glide
@Test
public void testSetsReadTimeout() throws Exception {
MockWebServer tempWebServer = new MockWebServer();
tempWebServer.enqueue(
new MockResponse().setBody("test").throttleBody(1, TIMEOUT_TIME_MS, TimeUnit.MILLISECONDS));
tempWebServer.start();
try {
getFetcher().loadData(Priority.HIGH, callback);
} finally {
tempWebServer.shutdown();
// shutdown() called before any enqueue() blocks until it times out.
mockWebServer.enqueue(new MockResponse().setResponseCode(200));
}
verify(callback).onLoadFailed(isA(IOException.class));
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void getWhenUsingDefaultsWithUnavailableJwkEndpointThenInvalidToken()
throws Exception {
this.spring.register(WebServerConfig.class, JwkSetUriConfig.class).autowire();
this.web.shutdown();
String token = this.token("ValidNoScopes");
this.mvc.perform(get("/").with(bearerToken(token)))
.andExpect(status().isUnauthorized())
.andExpect(invalidTokenHeader("An error occurred while attempting to decode the Jwt"));
}
内容来源于网络,如有侵权,请联系作者删除!