This repository has been archived by the owner on Jul 13, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
used in DiagStatusServletTest, also upcoming restconf support
- Loading branch information
Showing
2 changed files
with
51 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/java/org/opendaylight/infrautils/testutils/TestHttpClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2018 Red Hat, Inc. and others. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v1.0 which accompanies this distribution, | ||
* and is available at http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.opendaylight.infrautils.testutils; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import org.opendaylight.aaa.web.WebServer; | ||
|
||
/** | ||
* HTTP Client. | ||
* | ||
* @author Michael Vorburger.ch | ||
*/ | ||
@Singleton | ||
public class TestHttpClient { | ||
|
||
public enum Method { | ||
GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE | ||
} | ||
|
||
private final WebServer webServer; | ||
|
||
@Inject | ||
public TestHttpClient(WebServer webServer) { | ||
this.webServer = webServer; | ||
} | ||
|
||
public int responseCode(Method httpMethod, String path) throws IOException { | ||
URL url = new URL(webServer.getBaseURL() + path); | ||
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | ||
conn.setRequestMethod(httpMethod.name()); | ||
return conn.getResponseCode(); | ||
} | ||
} |