本文整理汇总了Java中org.apache.http.localserver.LocalTestServer类的典型用法代码示例。如果您正苦于以下问题:Java LocalTestServer类的具体用法?Java LocalTestServer怎么用?Java LocalTestServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocalTestServer类属于org.apache.http.localserver包,在下文中一共展示了LocalTestServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.apache.http.localserver.LocalTestServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
BasicConfigurator.configure();
server = new LocalTestServer(null, null);
server.register("/hitme/*", new HttpRequestHandler() {
@Override
public void handle(HttpRequest req, HttpResponse resp, HttpContext ctx)
throws HttpException, IOException
{
resp.setStatusCode(200);
resp.setEntity(new StringEntity("Hello World"));
}
});
server.start();
client = new HttpClient();
}
示例2: setUp
import org.apache.http.localserver.LocalTestServer; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
OAuthTokenService.INSTANCE.clearToken();
HttpRequestHandler tokenHandler = new TokenHandler();
HttpRequestHandler resourceHandler = new ResourceHandler();
testServer = new LocalTestServer(null, null);
testServer.register("/v3/rest/*", resourceHandler);
testServer.register("/v3/token", tokenHandler);
testServer.start();
port = testServer.getServicePort();
host = testServer.getServiceHostName();
// System.out.println("LocalTestServer available via http://" + host + ":" + port);
params = new HashMap<String, String>();
params.put("username", userName);
params.put("password", password);
params.put("scope", scope);
params.put("grant_type", grantType);
client = MasheryClientBuilder.masheryClient().withHost(host).withProtocol("http").withPort(port).withApiKey(apiKey).withApiSecret(apiSecret).withTokenRequestParams(params).build();
}
示例3: setUp
import org.apache.http.localserver.LocalTestServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
handler = mock(HttpRequestHandler.class);
server = new LocalTestServer(null, null);
server.register("/*", handler);
server.start();
// report how to access the server
System.out.println("LocalTestServer available at " + server.getServiceAddress());
primaryServiceAddress = server.getServiceAddress().getHostName() + ":" + server.getServiceAddress().getPort();
secondaryServiceAddress = server.getServiceAddress().getAddress().getHostAddress() + ":" + server.getServiceAddress().getPort();
impl = new Sosumi("http://" + primaryServiceAddress, "user", "pass");
}
示例4: setUp
import org.apache.http.localserver.LocalTestServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
// use local test server to intercept http requests sent by the reporter
server = new LocalTestServer(null, null);
server.register("*", handler);
server.start();
serverUrl = "http://localhost:" + server.getServiceAddress().getPort() + "/";
Properties properties = new Properties();
properties.put(BounceProxyControllerPropertyKeys.PROPERTY_BPC_SEND_CREATE_CHANNEL_MAX_RETRY_COUNT, "3");
properties.put(BounceProxyControllerPropertyKeys.PROPERTY_BPC_SEND_CREATE_CHANNEL_RETRY_INTERVAL_MS, "100");
Injector injector = Guice.createInjector(new PropertyLoadingModule(properties), new AbstractModule() {
@Override
protected void configure() {
bind(CloseableHttpClient.class).toInstance(HttpClients.createDefault());
}
});
bpFacade = injector.getInstance(RemoteBounceProxyFacade.class);
}
示例5: startStorageServers
import org.apache.http.localserver.LocalTestServer; //导入依赖的package包/类
@Before
public void startStorageServers() throws Exception {
for (int i = 0; i < 3; i++) {
localServers[i] = new LocalTestServer(null, null);
localServers[i].register("*", new HttpStorageRequestHandler());
localServers[i].start();
}
cfg = String.format("1 http://localhost:%d\n2 http://localhost:%d\n3 http://localhost:%d\n",
localServers[0].getServiceAddress().getPort(),
localServers[1].getServiceAddress().getPort(),
localServers[2].getServiceAddress().getPort());
}
示例6: killStorageServers
import org.apache.http.localserver.LocalTestServer; //导入依赖的package包/类
@After
public void killStorageServers() {
for (LocalTestServer s: localServers) {
try {
s.stop();
} catch (Exception e) {
}
}
}
示例7: getTestServerAddress
import org.apache.http.localserver.LocalTestServer; //导入依赖的package包/类
public static String getTestServerAddress(LocalTestServer server) {
return String.format(
"http://%s:%s",
server.getServiceAddress().getHostName(),
server.getServiceAddress().getPort()
);
}
示例8: FakeConduit
import org.apache.http.localserver.LocalTestServer; //导入依赖的package包/类
public FakeConduit(Map<String, JSONObject> responses) throws Exception {
server = new LocalTestServer(null, null);
this.requestBodies = new ArrayList<String>();
for (Map.Entry<String, JSONObject> entry : responses.entrySet()) {
register(entry.getKey(), entry.getValue());
}
server.start();
}
示例9: setUp
import org.apache.http.localserver.LocalTestServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
handler = Mockito.mock(HttpRequestHandler.class);
server = new LocalTestServer(null, null);
server.register("/jenkinstest/*", handler);
server.start();
serverUrl = "http://" + server.getServiceHostName() + ":"
+ server.getServicePort() + "/jenkinstest/123";
// report how to access the server
System.out.println("LocalTestServer available at " + serverUrl);
j.get(PluginDescriptorImpl.class).setUrl(serverUrl);
}
示例10: setUp
import org.apache.http.localserver.LocalTestServer; //导入依赖的package包/类
public void setUp(HttpRequestHandler handler) throws Exception {
server = new LocalTestServer(null, null);
server.register("/*", handler);
server.start();
// report how to access the server
address = "http://" + server.getServiceAddress().getHostName() + ":"
+ server.getServiceAddress().getPort();
System.out.println("LocalTestServer available at " + address);
}
示例11: setUp
import org.apache.http.localserver.LocalTestServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
// use local test server to intercept http requests sent by the reporter
server = new LocalTestServer(null, null);
server.register("*", handler);
server.start();
final String serverUrl = "http://localhost:" + server.getServiceAddress().getPort();
// set test properties manually for a better overview of
// what is tested
Properties properties = new Properties();
// have to set the BPC base url manually as this is the
// mock server which gets port settings dynamically
properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_CONTROLLER_BASE_URL, serverUrl);
properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_ID, "X.Y");
properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCEPROXY_URL_FOR_BPC, "http://joyn-bpX.muc/bp");
properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCEPROXY_URL_FOR_CC, "http://joyn-bpX.de/bp");
properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_MONITORING_FREQUENCY_MS, "100");
properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_SEND_LIFECYCLE_REPORT_RETRY_INTERVAL_MS, "100");
properties.put(BounceProxyPropertyKeys.PROPERTY_BOUNCE_PROXY_MAX_SEND_SHUTDOWN_TIME_SECS, "1");
Injector injector = Guice.createInjector(new PropertyLoadingModule(properties),
new ControlledBounceProxyModule() {
@Override
protected void configure() {
bind(ChannelService.class).to(DefaultBounceProxyChannelServiceImpl.class);
bind(BounceProxyLifecycleMonitor.class).to(MonitoringServiceClient.class);
bind(TimestampProvider.class).toInstance(mockTimestampProvider);
bind(BounceProxyInformation.class).toProvider(BounceProxyInformationProvider.class);
}
});
reporter = injector.getInstance(MonitoringServiceClient.class);
}
示例12: setUp
import org.apache.http.localserver.LocalTestServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
server = new LocalTestServer(null, null);
server.register(CHANNELPATH, new HttpRequestHandler() {
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException,
IOException {
response.setStatusCode(createChannelResponseCode);
response.setHeader("Location", bounceProxyUrl + "channels/" + channelId);
}
});
server.start();
serviceAddress = "http://" + server.getServiceAddress().getHostName() + ":"
+ server.getServiceAddress().getPort();
bounceProxyUrl = serviceAddress + BOUNCEPROXYPATH;
Properties properties = new Properties();
properties.put(MessagingPropertyKeys.CHANNELID, channelId);
properties.put(MessagingPropertyKeys.BOUNCE_PROXY_URL, bounceProxyUrl);
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
public void configure() {
bind(HttpRequestFactory.class).to(ApacheHttpRequestFactory.class);
bind(CloseableHttpClient.class).toProvider(HttpClientProvider.class).in(Singleton.class);
bind(RequestConfig.class).toProvider(HttpDefaultRequestConfigProvider.class).in(Singleton.class);
bind(MessagingSettings.class).to(ConfigurableMessagingSettings.class);
}
}, new JoynrPropertiesModule(properties), new JsonMessageSerializerModule(), new DummyDiscoveryModule());
longpollingChannelLifecycle = injector.getInstance(LongPollingChannelLifecycle.class);
}
示例13: setUp
import org.apache.http.localserver.LocalTestServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
server = new LocalTestServer(null, null);
server.start();
}
示例14: getServer
import org.apache.http.localserver.LocalTestServer; //导入依赖的package包/类
public LocalTestServer getServer() {
return server;
}
示例15: setUp
import org.apache.http.localserver.LocalTestServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
server = new LocalTestServer(null, null);
server.start();
client = getDefaultClient();
}