use of ee.jakarta.tck.ws.rs.common.webclient.http.HttpResponse in project jaxrs-api by eclipse-ee4j.
the class AdaptiveHttpRequest method execute.
/**
* <code>execute</code> will dispatch the current request to the target
* server.
*
* @return HttpResponse the server's response.
* @throws IOException
* if an I/O error occurs during dispatch.
*/
public HttpResponse execute() throws IOException, HttpException {
String method;
int defaultPort;
ProtocolSocketFactory factory;
if (_method.getFollowRedirects()) {
client = new HttpClient();
if (_isSecure) {
method = "https";
defaultPort = DEFAULT_SSL_PORT;
factory = new SSLProtocolSocketFactory();
} else {
method = "http";
defaultPort = DEFAULT_HTTP_PORT;
factory = new DefaultProtocolSocketFactory();
}
Protocol protocol = new Protocol(method, factory, defaultPort);
HttpConnection conn = new HttpConnection(_host, _port, protocol);
if (conn.isOpen()) {
throw new IllegalStateException("Connection incorrectly opened");
}
conn.open();
TestUtil.logMsg("[HttpRequest] Dispatching request: '" + _requestLine + "' to target server at '" + _host + ":" + _port + "'");
addSupportHeaders();
_headers = _method.getRequestHeaders();
TestUtil.logTrace("########## The real value set: " + _method.getFollowRedirects());
client.getHostConfiguration().setHost(_host, _port, protocol);
client.executeMethod(_method);
return new HttpResponse(_host, _port, _isSecure, _method, getState());
} else {
if (_isSecure) {
method = "https";
defaultPort = DEFAULT_SSL_PORT;
factory = new SSLProtocolSocketFactory();
} else {
method = "http";
defaultPort = DEFAULT_HTTP_PORT;
factory = new DefaultProtocolSocketFactory();
}
Protocol protocol = new Protocol(method, factory, defaultPort);
HttpConnection conn = new HttpConnection(_host, _port, protocol);
if (conn.isOpen()) {
throw new IllegalStateException("Connection incorrectly opened");
}
conn.open();
TestUtil.logMsg("[HttpRequest] Dispatching request: '" + _requestLine + "' to target server at '" + _host + ":" + _port + "'");
addSupportHeaders();
_headers = _method.getRequestHeaders();
TestUtil.logTrace("########## The real value set: " + _method.getFollowRedirects());
_method.execute(getState(), conn);
return new HttpResponse(_host, _port, _isSecure, _method, getState());
}
}
use of ee.jakarta.tck.ws.rs.common.webclient.http.HttpResponse in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method selectVariantResponseVaryTest.
/*
* @testName: selectVariantResponseVaryTest
*
* @assertion_ids: JAXRS:JAVADOC:119; JAXRS:SPEC:40;
*
* @test_Strategy: Check if the response contains VARY
*/
@Test
public void selectVariantResponseVaryTest() throws Fault {
setProperty(Property.REQUEST, buildRequest(GET, "SelectVariantTestResponse"));
setProperty(Property.REQUEST_HEADERS, "Accept: application/json");
setProperty(Property.REQUEST_HEADERS, "Accept-Encoding: *");
setProperty(Property.REQUEST_HEADERS, "Accept-Language: *");
setProperty(Property.STATUS_CODE, getStatusCode(Status.OK));
invoke();
HttpResponse response = _testCase.getResponse();
Header[] headers = response.getResponseHeaders("Vary");
assertTrue(headers.length != 0, "Expected at least 1 Vary response header");
boolean accept = false, lang = false, encoding = false;
for (Header header : headers) for (String vary : header.getValue().split(",")) {
lang |= vary.contains("Accept-Language");
encoding |= vary.contains("Accept-Encoding");
accept |= (vary.contains("Accept") && !vary.contains("Accept-"));
}
assertTrue(lang, "Vary should contain Accept-Language");
assertTrue(encoding, "Vary should contain Accept-Encoding");
assertTrue(accept, "Vary should contain Accept");
}
use of ee.jakarta.tck.ws.rs.common.webclient.http.HttpResponse in project jaxrs-api by eclipse-ee4j.
the class JAXRSProvidersClientIT method getReturnedNumber.
// ///////////////////////////////////////////////////////////////////////
protected int getReturnedNumber() throws Fault {
HttpResponse response = _testCase.getResponse();
String body;
try {
body = response.getResponseBodyAsString();
} catch (IOException e) {
throw new Fault(e);
}
return Integer.parseInt(body);
}
use of ee.jakarta.tck.ws.rs.common.webclient.http.HttpResponse in project jaxrs-api by eclipse-ee4j.
the class JAXRSCommonClient method getResponseBody.
/**
* @return http response body as string
* @throws Fault
* when an error occur
*/
protected String getResponseBody() throws Fault {
try {
HttpResponse response;
response = _testCase.getResponse();
boolean isNull = response.getResponseBodyAsRawStream() == null;
return isNull ? null : response.getResponseBodyAsString();
} catch (IOException e) {
throw new Fault(e);
}
}
use of ee.jakarta.tck.ws.rs.common.webclient.http.HttpResponse in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method headGetTest.
/*
* @testName: headGetTest
*
* @assertion_ids: JAXRS:SPEC:17.2;
*
* @test_Strategy: Call a method annotated with a request method designator
* for GET and discard any returned entity
*/
@Test
public void headGetTest() throws Fault, IOException {
setProperty(REQUEST, buildRequest("HEAD", "get"));
setProperty(Property.EXPECTED_HEADERS, "CTS-HEAD: get");
invoke();
HttpResponse request = _testCase.getResponse();
assertTrue(request.getResponseBodyAsRawString() == null, "Unexpected entity in request body");
}
Aggregations