use of com.predic8.membrane.core.transport.http.HttpClient in project service-proxy by membrane.
the class AccessControlInterceptorIntegrationTest method setInterceptor.
/*
* This test can only by run on a specific machine.
*/
/*@Test
public void testLocalhost() throws Exception {
setInterceptor(FILE_CLIENTS_FROM_LOCALHOST);
HttpClient client = new HttpClient();
HostConfiguration config = new HostConfiguration();
config.setLocalAddress(InetAddress.getByName("localhost"));
client.setHostConfiguration(config);
assertEquals(200, client.executeMethod(getBLZRequestMethod()));
}*/
/*
* This test can only by run on a specific machine.
*/
/*@Test
public void test192_168_2_Star() throws Exception {
setInterceptor(FILE_CLIENTS_FROM_192_168_2_STAR);
assertEquals(200, getClient(FIXED_IP).executeMethod(getBLZRequestMethod()));
}*/
private void setInterceptor(String fileName) throws Exception {
AccessControlInterceptor interceptor = new AccessControlInterceptor();
interceptor.setFile(fileName);
router.addUserFeatureInterceptor(interceptor);
router.init();
}
use of com.predic8.membrane.core.transport.http.HttpClient in project service-proxy by membrane.
the class IllegalCharactersInURLTest method doit.
@Test
public void doit() throws Exception {
URIFactory uriFactory = new URIFactory(true);
Response res = new HttpClient().call(new Request.Builder().method("GET").url(uriFactory, "http://localhost:3027/foo{}").body("").buildExchange()).getResponse();
Assert.assertEquals(200, res.getStatusCode());
}
use of com.predic8.membrane.core.transport.http.HttpClient in project service-proxy by membrane.
the class RegExReplaceInterceptorTest method testReplace.
@Test
public void testReplace() throws Exception {
router = Router.init("src/test/resources/regex-monitor-beans.xml");
Rule serverRule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3009), "www.predic8.de", 80);
router.getRuleManager().addProxyAndOpenPortIfNew(serverRule);
router.init();
try {
HttpClient client = new HttpClient();
GetMethod method = new GetMethod("http://localhost:3009");
method.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8);
method.setRequestHeader(Header.SOAP_ACTION, "");
assertEquals(200, client.executeMethod(method));
assertTrue(new String(method.getResponseBody()).contains("Membrane RegEx Replacement Is Cool"));
} finally {
router.shutdown();
}
}
use of com.predic8.membrane.core.transport.http.HttpClient in project service-proxy by membrane.
the class LargeBodyTest method large.
@Test
public void large() throws Exception {
setup();
long len = Integer.MAX_VALUE + 1l;
Exchange e = new Request.Builder().post("http://localhost:3041/foo").body(len, new ConstantInputStream(len)).buildExchange();
new HttpClient(hcc).call(e);
}
use of com.predic8.membrane.core.transport.http.HttpClient in project service-proxy by membrane.
the class TelekomSMSTokenProvider method getAccessToken.
private synchronized String getAccessToken() throws Exception {
long now = System.currentTimeMillis();
if (token == null || tokenExpiration < now) {
Exchange exc = new Request.Builder().post("https://global.telekom.com/gcp-web-api/oauth").header(Header.HOST, "global.telekom.com").header(Header.AUTHORIZATION, "Basic " + new String(Base64.encodeBase64((clientId + ":" + clientSecret).getBytes("UTF-8")), "UTF-8")).header(Header.ACCEPT, "application/json").header(Header.USER_AGENT, Constants.PRODUCT_NAME + " " + Constants.VERSION).header(Header.CONTENT_TYPE, "application/x-www-form-urlencoded").body(new URLParamUtil.ParamBuilder().add("grant_type", "client_credentials").add("scope", scope).build()).buildExchange();
new HttpClient().call(exc, false, true);
if (exc.getResponse().getStatusCode() != 200)
throw new RuntimeException("Telekom Authentication Server returned: " + exc.getResponse());
HashMap<String, String> values = Util.parseSimpleJSONResponse(exc.getResponse());
if (!values.containsKey("access_token") || !values.containsKey("expires_in"))
throw new Exception("Telekom Authentication: Received 200 and JSON body, but no access_token or no expires_in.");
token = values.get("access_token");
tokenExpiration = Long.parseLong(values.get("expires_in")) + System.currentTimeMillis() - 2000;
}
return token;
}
Aggregations