List of usage examples for org.apache.http.localserver LocalTestServer LocalTestServer
public LocalTestServer(BasicHttpProcessor proc, HttpParams params)
From source file:se.vgregion.pubsub.inttest.SubscriberRunner.java
public static void main(String[] args) throws Exception { LocalTestServer server = new LocalTestServer(null, null); server.register("/*", new HttpRequestHandler() { @Override//from w w w .j a v a 2s . co m public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { String challenge = getQueryParamValue(request.getRequestLine().getUri(), "hub.challenge"); if (challenge != null) { // subscription verification, confirm System.out.println("Respond to challenge"); response.setEntity(new StringEntity(challenge)); } else if (request instanceof HttpEntityEnclosingRequest) { HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); // System.out.println(HttpUtil.readContent(entity)); } else { System.err.println("Unknown request"); } } }); server.start(); HttpPost post = new HttpPost("http://localhost:8080/"); List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("hub.callback", buildTestUrl(server, "/").toString())); parameters.add(new BasicNameValuePair("hub.mode", "subscribe")); parameters.add(new BasicNameValuePair("hub.topic", "http://feeds.feedburner.com/protocol7/main")); parameters.add(new BasicNameValuePair("hub.verify", "sync")); post.setEntity(new UrlEncodedFormEntity(parameters)); DefaultHttpClient client = new DefaultHttpClient(); client.execute(post); }
From source file:org.fedoraproject.copr.client.impl.RpcTest.java
@Before public void setUp() throws Exception { server = new LocalTestServer(null, null); server.register("/api/*", new HttpMock(this)); server.start();/* w w w .j a va 2 s .c o m*/ InetSocketAddress address = server.getServiceAddress(); url = "http://" + address.getHostName() + ":" + address.getPort(); CoprConfiguration configuration = getConfiguration(); configuration.setUrl(url); CoprService copr = new DefaultCoprService(); session = copr.newSession(configuration); }
From source file:org.ojbc.util.TestHttpUtils.java
@Test public void test() throws Exception { final String responseString = "yeppers"; LocalTestServer server = new LocalTestServer(null, null); server.register("/test", new HttpRequestHandler() { @Override/*w ww . j av a 2 s . c o m*/ public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { response.setEntity(new StringEntity(responseString)); } }); server.start(); String host = server.getServiceAddress().getHostName(); int port = server.getServiceAddress().getPort(); String response = HttpUtils.post("ok?", "http://" + host + ":" + port + "/test"); assertEquals(responseString, response); }
From source file:com.uber.jenkins.phabricator.FakeConduit.java
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()); }/* w ww . j a v a2 s . co m*/ server.start(); }
From source file:org.apromore.plugin.deployment.yawl.YAWLEngineClientUnitTest.java
@Before public void setUp() throws Exception { server = new LocalTestServer(null, null); server.start();/*from w w w .ja v a 2 s.c om*/ yawlEngineClient = new YAWLEngineClient( "http://localhost:" + server.getServiceAddress().getPort() + "/yawl/ia", "test", "test"); }
From source file:com.flipkart.foxtrot.client.LocalServerTestRule.java
@Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override/*from w ww. jav a2s .co m*/ public void evaluate() throws Throwable { LocalTestServer localTestServer = new LocalTestServer(null, null); for (Map.Entry<String, HttpRequestHandler> handler : handlers.entrySet()) { localTestServer.register(handler.getKey(), handler.getValue()); } localTestServer.start(); logger.info("Started test server"); try { hostPort.setHostName(localTestServer.getServiceAddress().getHostName()); hostPort.setPort(localTestServer.getServiceAddress().getPort()); base.evaluate(); } finally { localTestServer.stop(); logger.info("Stopped test server"); } } }; }
From source file:nl.surfnet.sab.HttpClientTransportTest.java
@Before public void setUp() throws Exception { server = new LocalTestServer(null, null); server.register("/test", new HttpRequestHandler() { @Override/* w w w.j a va 2 s. c o m*/ public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { response.setEntity(new StringEntity("This is the response")); response.setStatusCode(200); } }); server.start(); endPoint = URI.create("http:/" + server.getServiceAddress().toString() + "/test"); credentials = new UsernamePasswordCredentials("theuser", "thepass"); transport = new HttpClientTransport(credentials, credentials, endPoint, endPoint); }
From source file:com.uber.jenkins.phabricator.conduit.ConduitAPIClientTest.java
@Before public void setUp() throws Exception { server = new LocalTestServer(null, null); server.start(); }
From source file:se.vgregion.pubsub.inttest.Publisher.java
public Publisher(String host) throws Exception { this.localServerName = host; server = new LocalTestServer(null, null); server.register("/*", new HttpRequestHandler() { @Override//from ww w .j a v a 2s.c o m public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { response.setHeader("Content-type", ContentType.ATOM.toString()); response.setEntity(new StringEntity(AbstractSerializer.printFeed(ContentType.ATOM, feed).toXML())); } }); server.start(); }
From source file:org.surfnet.cruncher.integration.CruncherClientTestIntegration.java
@BeforeClass public static void beforeClass() throws Exception { oauth2AuthServer = new LocalTestServer(null, null); oauth2AuthServer.start();// ww w. j a v a 2 s. c om oauth2AuthServer.register("/oauth2/token", new HttpRequestHandler() { @Override public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { response.setEntity(new StringEntity(answer, ContentType.APPLICATION_JSON)); response.setStatusCode(200); } }); String apisOAuth2AuthorizationUrl = String.format("http://%s:%d/oauth2/token", oauth2AuthServer.getServiceAddress().getHostName(), oauth2AuthServer.getServiceAddress().getPort()); cruncherClient = new CruncherClient(cruncherBaseLocation); ClientCredentialsClient oauthClient = new ClientCredentialsClient(); oauthClient.setClientKey("key"); oauthClient.setClientSecret("secret"); oauthClient.setOauthAuthorizationUrl(apisOAuth2AuthorizationUrl); cruncherClient.setOauthClient(oauthClient); }