本文整理了Java中okhttp3.mockwebserver.MockWebServer.getPort()
方法的一些代码示例,展示了MockWebServer.getPort()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MockWebServer.getPort()
方法的具体详情如下:
包路径:okhttp3.mockwebserver.MockWebServer
类名称:MockWebServer
方法名:getPort
暂无
代码示例来源:origin: openzipkin/brave
protected String url(String pathIncludingQuery) {
return "http://127.0.0.1:" + server.getPort() + pathIncludingQuery;
}
}
代码示例来源:origin: square/okhttp
public Proxy toProxyAddress() {
before();
InetSocketAddress address = new InetSocketAddress(inetSocketAddress.getAddress()
.getCanonicalHostName(), getPort());
return new Proxy(Proxy.Type.HTTP, address);
}
代码示例来源:origin: square/okhttp
/**
* Returns a URL for connecting to this server.
*
* @param path the request path, such as "/".
*/
public HttpUrl url(String path) {
return new HttpUrl.Builder()
.scheme(sslSocketFactory != null ? "https" : "http")
.host(getHostName())
.port(getPort())
.build()
.resolve(path);
}
代码示例来源:origin: googlemaps/google-maps-services-java
private void setMockBaseUrl() {
builder.baseUrlOverride("http://127.0.0.1:" + server.getPort());
}
代码示例来源:origin: openzipkin/brave
@Before public void setup() {
httpTracing = HttpTracing.create(tracingBuilder(Sampler.ALWAYS_SAMPLE).build());
client = newClient(server.getPort());
}
代码示例来源:origin: openzipkin/brave
@Test
public void reportsServerAddress() throws Exception {
server.enqueue(new MockResponse());
get(client, "/foo");
Span span = takeSpan();
assertThat(span.remoteEndpoint())
.isEqualTo(Endpoint.newBuilder()
.ip("127.0.0.1")
.port(server.getPort()).build()
);
}
代码示例来源:origin: ctripcorp/apollo
@Override
protected void before() throws Throwable {
clear();
server = new MockWebServer();
final Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
if (request.getPath().startsWith("/notifications/v2")) {
String notifications = request.getRequestUrl().queryParameter("notifications");
return new MockResponse().setResponseCode(200).setBody(mockLongPollBody(notifications));
} else if (request.getPath().startsWith("/configs")) {
List<String> pathSegments = request.getRequestUrl().pathSegments();
// appId and cluster might be used in the future
String appId = pathSegments.get(1);
String cluster = pathSegments.get(2);
String namespace = pathSegments.get(3);
return new MockResponse().setResponseCode(200).setBody(loadConfigFor(namespace));
}
return new MockResponse().setResponseCode(404);
}
};
server.setDispatcher(dispatcher);
server.start();
mockConfigServiceUrl("http://localhost:" + server.getPort());
super.before();
}
代码示例来源:origin: spring-projects/spring-framework
@Before
public void setUp() throws Exception {
this.server = new MockWebServer();
this.server.setDispatcher(new TestDispatcher());
this.server.start();
this.port = this.server.getPort();
this.baseUrl = "http://localhost:" + this.port;
}
代码示例来源:origin: spring-projects/spring-framework
@Before
public void setUp() throws Exception {
this.server = new MockWebServer();
this.server.setDispatcher(new TestDispatcher());
this.server.start();
this.port = this.server.getPort();
this.baseUrl = "http://localhost:" + this.port;
}
代码示例来源:origin: SonarSource/sonarqube
private void setUpWithHttpUrl(ProcessId processId) {
try (DefaultProcessCommands processCommands = DefaultProcessCommands.secondary(ipcSharedDir, processId.getIpcIndex())) {
processCommands.setUp();
processCommands.setHttpUrl(format("http://%s:%d", server.getHostName(), server.getPort()));
}
}
}
代码示例来源:origin: openzipkin/brave
/** Unlike Brave 3, Brave 4 propagates trace ids even when unsampled */
@Test public void propagates_sampledFalse() throws Exception {
close();
httpTracing = HttpTracing.create(tracingBuilder(Sampler.NEVER_SAMPLE).build());
client = newClient(server.getPort());
server.enqueue(new MockResponse());
get(client, "/foo");
RecordedRequest request = server.takeRequest();
assertThat(request.getHeaders().toMultimap())
.containsKeys("x-b3-traceId", "x-b3-spanId")
.doesNotContainKey("x-b3-parentSpanId")
.containsEntry("x-b3-sampled", asList("0"));
}
代码示例来源:origin: openzipkin/brave
@Test public void customSampler() throws Exception {
close();
httpTracing = httpTracing.toBuilder().clientSampler(HttpRuleSampler.newBuilder()
.addRule(null, "/foo", 0.0f)
.build()).build();
client = newClient(server.getPort());
server.enqueue(new MockResponse());
get(client, "/foo");
RecordedRequest request = server.takeRequest();
assertThat(request.getHeaders().toMultimap())
.containsEntry("x-b3-sampled", asList("0"));
}
代码示例来源:origin: openzipkin/brave
.build().clientOf("remote-service");
client = newClient(server.getPort());
server.enqueue(new MockResponse());
get(client, uri);
代码示例来源:origin: googlemaps/google-maps-services-java
LocalTestServerContext(BufferedImage image) throws IOException {
this.server = new MockWebServer();
Buffer buffer = new Buffer();
ImageIO.write(image, "png", buffer.outputStream());
MockResponse response = new MockResponse();
response.setHeader("Content-Type", "image/png");
response.setBody(buffer);
server.enqueue(response);
server.start();
this.context =
new GeoApiContext.Builder()
.apiKey("AIzaFakeKey")
.baseUrlOverride("http://127.0.0.1:" + server.getPort())
.build();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void use_proxy_authentication_wrong_crendentials() throws Exception {
try (MockWebServer proxy = new MockWebServer()) {
proxy.start();
underTest = HttpConnector.newBuilder()
.url(serverUrl)
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy.getHostName(), proxy.getPort())))
.proxyCredentials("theProxyLogin", "wrongPassword")
.build();
GetRequest request = new GetRequest("api/issues/search");
proxy.enqueue(new MockResponse().setResponseCode(407));
proxy.enqueue(new MockResponse().setResponseCode(407));
proxy.enqueue(new MockResponse().setResponseCode(407));
underTest.call(request);
RecordedRequest recordedRequest = proxy.takeRequest();
assertThat(recordedRequest.getHeader("Proxy-Authorization")).isNull();
recordedRequest = proxy.takeRequest();
assertThat(recordedRequest.getHeader("Proxy-Authorization")).isEqualTo(basic("theProxyLogin", "wrongPassword"));
assertThat(proxy.getRequestCount()).isEqualTo(2);
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void use_proxy_authentication() throws Exception {
try (MockWebServer proxy = new MockWebServer()) {
proxy.start();
underTest = HttpConnector.newBuilder()
.url(serverUrl)
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy.getHostName(), proxy.getPort())))
.proxyCredentials("theProxyLogin", "theProxyPassword")
.build();
GetRequest request = new GetRequest("api/issues/search");
proxy.enqueue(new MockResponse().setResponseCode(407));
proxy.enqueue(new MockResponse().setBody("OK!"));
underTest.call(request);
RecordedRequest recordedRequest = proxy.takeRequest();
assertThat(recordedRequest.getHeader("Proxy-Authorization")).isNull();
recordedRequest = proxy.takeRequest();
assertThat(recordedRequest.getHeader("Proxy-Authorization")).isEqualTo(basic("theProxyLogin", "theProxyPassword"));
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void retrieveSystemInfo_throws_ISE_if_http_error() {
server.enqueue(new MockResponse().setResponseCode(500));
// initialize registration of process
setUpWithHttpUrl(ProcessId.COMPUTE_ENGINE);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Failed to call HTTP server of process " + ProcessId.COMPUTE_ENGINE);
expectedException.expectCause(hasType(IOException.class)
.andMessage(format("Server returned HTTP response code: 500 for URL: http://%s:%d/systemInfo", server.getHostName(), server.getPort())));
underTest.retrieveSystemInfo();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void changeLogLevel_throws_ISE_if_http_error() {
String message = "blah";
server.enqueue(new MockResponse().setResponseCode(500).setBody(message));
// initialize registration of process
setUpWithHttpUrl(ProcessId.COMPUTE_ENGINE);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Failed to call HTTP server of process " + ProcessId.COMPUTE_ENGINE);
expectedException.expectCause(hasType(IOException.class)
.andMessage(format("Failed to change log level in Compute Engine. Code was '500' and response was 'blah' for url " +
"'http://%s:%s/changeLogLevel'", server.getHostName(), server.getPort())));
underTest.changeLogLevel(LoggerLevel.DEBUG);
}
代码示例来源:origin: googlemaps/google-maps-services-java
LocalTestServerContext(String responseBody) throws IOException {
this.server = new MockWebServer();
MockResponse response = new MockResponse();
response.setHeader("Content-Type", "application/json");
response.setBody(responseBody);
server.enqueue(response);
server.start();
this.context =
new GeoApiContext.Builder()
.apiKey("AIzaFakeKey")
.baseUrlOverride("http://127.0.0.1:" + server.getPort())
.build();
}
代码示例来源:origin: line/line-bot-sdk-java
protected LineMessagingClient createLineMessagingClient(final MockWebServer mockWebServer) {
return LineMessagingClient.builder("token")
.apiEndPoint("http://localhost:" + mockWebServer.getPort())
.build();
}
内容来源于网络,如有侵权,请联系作者删除!