@Override public WebResponse sendRequest(final WebRequest request) throws IOException, Exception { for (final Entry<String,String> entry : request.getHeaders().entrySet()) { m_httpMethod.addHeader(entry.getKey(), entry.getValue()); } CloseableHttpResponse response = null; try { response = m_httpClientWrapper.execute(m_httpMethod); return new WebResponse(request, response); } catch (final Exception e) { LOG.info(e.getMessage(), e); return new WebResponse(request, null); } }
response = getClientWrapper().execute(post); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode != HttpStatus.SC_OK) {
response = getClientWrapper().execute(post); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode != HttpStatus.SC_OK) {
response = getClientWrapper().execute(get); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode != HttpStatus.SC_OK) {
response = getClientWrapper().execute(get); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode != HttpStatus.SC_OK) {
public RTUser getUserInfo(final String username) { getSession(); Map<String, String> attributes = Collections.emptyMap(); final HttpGet get = new HttpGet(m_baseURL + "/REST/1.0/user/" + username); CloseableHttpResponse response = null; try { response = getClientWrapper().execute(get); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode != HttpStatus.SC_OK) { throw new RequestTrackerException("Received a non-200 response code from the server: " + responseCode); } else { if (response.getEntity() != null) { attributes = parseResponseStream(response.getEntity().getContent()); } } } catch (final Exception e) { LOG.error("An exception occurred while getting user info for {}", username, e); return null; } finally { getClientWrapper().close(response); } final String id = attributes.get("id"); final String realname = attributes.get("realname"); final String email = attributes.get("emailaddress"); if (id == null || "".equals(id)) { LOG.error("Unable to retrieve ID from user info."); return null; } return new RTUser(Long.parseLong(id.replace("user/", "")), username, realname, email); }
public RTUser getUserInfo(final String username) { getSession(); Map<String, String> attributes = Collections.emptyMap(); final HttpGet get = new HttpGet(m_baseURL + "/REST/1.0/user/" + username); CloseableHttpResponse response = null; try { response = getClientWrapper().execute(get); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode != HttpStatus.SC_OK) { throw new RequestTrackerException("Received a non-200 response code from the server: " + responseCode); } else { if (response.getEntity() != null) { attributes = parseResponseStream(response.getEntity().getContent()); } } } catch (final Exception e) { LOG.error("An exception occurred while getting user info for {}", username, e); return null; } finally { getClientWrapper().close(response); } final String id = attributes.get("id"); final String realname = attributes.get("realname"); final String email = attributes.get("emailaddress"); if (id == null || "".equals(id)) { LOG.error("Unable to retrieve ID from user info."); return null; } return new RTUser(Long.parseLong(id.replace("user/", "")), username, realname, email); }
response = getClientWrapper().execute(get); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode != HttpStatus.SC_OK) {
response = getClientWrapper().execute(get); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode != HttpStatus.SC_OK) {
CloseableHttpResponse response = clientWrapper.execute(httpMethod); retval = parseHypericAlerts(new StringReader(EntityUtils.toString(response.getEntity()))); } finally {
response = getClientWrapper().execute(get); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode != HttpStatus.SC_OK) {
int statusCode = -1; try { CloseableHttpResponse response = clientWrapper.execute(method); statusCode = response.getStatusLine().getStatusCode(); contents = EntityUtils.toString(response.getEntity());
post.setEntity(entity); response = m_clientWrapper.execute(post); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode != HttpStatus.SC_OK) {
post.setEntity(entity); response = m_clientWrapper.execute(post); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode != HttpStatus.SC_OK) {
CloseableHttpResponse response = null; try { response = m_clientWrapper.execute(method); final StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() != 200) {
CloseableHttpResponse response = m_clientWrapper.execute(request); return response.getEntity().getContent(); } catch (Exception e) {
CloseableHttpResponse response = m_clientWrapper.execute(request); return response.getEntity().getContent(); } catch (Exception e) {
CloseableHttpResponse response = null; try { response = m_clientWrapper.execute(method); final StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() != 200) {
@Override public Requisition getRequisitionFor(HttpRequisitionRequest request) { try (HttpClientWrapper client = HttpClientWrapper.create()) { final URI uri = new URI(request.getUrl()); HttpGet get = new HttpGet(uri); if (Boolean.FALSE.equals(request.getStrictSsl())) { client.trustSelfSigned(uri.getScheme()); } if(Boolean.TRUE.equals(request.getUseSystemProxy())){ client.useSystemProxySettings(); } if (request.getUsername() != null) { client.addBasicCredentials(request.getPassword(), request.getPassword()); } try (CloseableHttpResponse response = client.execute(get)) { String responseString = new BasicResponseHandler().handleResponse(response); return JaxbUtils.unmarshal(Requisition.class, responseString); } } catch (Exception e) { throw new RuntimeException(e); } }
/** * Test the Servlet with a simple POST Request based on XML Data. * * @throws Exception the exception */ @Test @JUnitHttpServer(port=10342, https=false, webapps={ @Webapp(context="/junit", path="src/test/resources/test-webapp") }) public void testServlet() throws Exception { String xml = "<person><firstName>Alejandro</firstName></person>"; final HttpClientWrapper clientWrapper = HttpClientWrapper.create(); try { StringEntity entity = new StringEntity(xml, ContentType.APPLICATION_XML); HttpPost method = new HttpPost("http://localhost:10342/junit/test/sample"); method.setEntity(entity); CloseableHttpResponse response = clientWrapper.execute(method); Assert.assertEquals(200, response.getStatusLine().getStatusCode()); Assert.assertEquals("OK!", EntityUtils.toString(response.getEntity())); } finally { IOUtils.closeQuietly(clientWrapper); } }