List of usage examples for org.apache.http.client HttpResponseException getStatusCode
public int getStatusCode()
From source file:fr.lissi.belilif.om2m.oao.ApplicationManager.java
@Override public int create(Application obj) { String appInXML = JAXBMapper.objectToXMLString(obj); LOGGER.info("App to create : " + obj.getAppId()); LOGGER.info(obj.getAppId() + " in OM2M XML strcuture : \n" + appInXML); // appeler le client REST avec le code XML correspondant int resp = -1; try {/* w w w.ja v a2 s . c om*/ resp = WebServiceActions.doPost(this.OM2MUrlBase + "applications", appInXML, this.headers); LOGGER.info("Application '" + obj.getAppId() + "' creation status : " + resp); } catch (HttpResponseException e) { resp = e.getStatusCode(); LOGGER.error("HttpResponseException - " + e.getStatusCode() + " / " + e.getMessage() + "\n" + "Unable to create the application '" + obj.getAppId() + "' with " + this.OM2MUrlBase + "applications"); } catch (ClientProtocolException e) { e.printStackTrace(); LOGGER.error(e.getMessage()); } catch (ConnectException e) { LOGGER.error( e.getMessage() + ". \nThe server '" + this.OM2MUrlBase.substring(7, 21) + "' is unreachable."); } catch (IOException e) { LOGGER.error(e.getMessage()); } return resp; }
From source file:org.neo4j.ogm.integration.TransactionRequestHandlerTest.java
@Test public void shouldRollbackExplicitTransactionWhenServerTransactionTimeout() throws InterruptedException { SessionFactory sessionFactory = new SessionFactory(); session = sessionFactory.openSession(neo4jRule.url()); try (Transaction tx = session.beginTransaction()) { // Wait for transaction to timeout on server Thread.sleep(3000);//from www . j av a2 s . c om // Try to purge database using timed-out transaction session.purgeDatabase(); fail("Should have caught exception"); } catch (ResultProcessingException rpe) { HttpResponseException cause = (HttpResponseException) rpe.getCause(); assertEquals("Not Found", cause.getMessage()); assertEquals(404, cause.getStatusCode()); } // should pass, because previous transaction will be closed by try block session.purgeDatabase(); }
From source file:org.musicmount.io.server.dav.DAVResourceProvider.java
@Override protected boolean exists(ServerPath path) throws IOException { if (path.isDirectory()) { try {// www . j av a2 s .c o m return getFileAttributes(path).isDirectory(); } catch (HttpResponseException e) { if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) { return false; } else { throw new IOException(e.getMessage() + " (" + e.getStatusCode() + ")", e); } } } else { // HEAD, doesn't work for directories return getSardine().exists(path.toUri().toString()); } }
From source file:org.jfrog.artifactory.client.ning.ArtifactoryNingClientTest.java
@Test public void test404() throws Exception { RepositoryHandle repositoryHandle = artifactory.repository(repo); Assert.assertNotNull(repositoryHandle); ItemHandle itemHandle = repositoryHandle.file(filePath + "/" + fileName + "NOT_FOUND"); Assert.assertNotNull(itemHandle);//from w w w .j a va 2s . c o m try { Item item = itemHandle.info(); Assert.fail("Should have failed."); } catch (Exception e) { if (!(e instanceof org.apache.http.client.HttpResponseException)) { throw e; } HttpResponseException status = (org.apache.http.client.HttpResponseException) e; // GOOD Assert.assertEquals(status.getStatusCode(), 404); } }
From source file:fr.lissi.belilif.om2m.oao.ApplicationManager.java
@Override public int delete(Application obj) { HttpGetSimpleResp resp;/*from w w w. jav a 2 s.c o m*/ int appResponse = -1; try { resp = WebServiceActions.doDelete(this.OM2MUrlBase + "applications/" + obj.getAppId(), headers); appResponse = resp.getStatusCode(); } catch (HttpResponseException e) { LOGGER.error("HttpResponseException - " + e.getStatusCode() + " / " + e.getMessage()); } catch (ClientProtocolException e) { e.printStackTrace(); LOGGER.error(e.getMessage()); } catch (ConnectException e) { LOGGER.error( e.getMessage() + ". \nThe server '" + this.OM2MUrlBase.substring(7, 21) + "' is unreachable."); } catch (IOException e) { LOGGER.error(e.getMessage()); } return appResponse; }
From source file:fr.lissi.belilif.om2m.oao.ContentInstanceManager.java
@Override public int subscribe(ContentInstance obj, Subscription subscription) { LOGGER.info("Create : \n" + JAXBMapper.objectToXMLString(obj)); int resp = -1; try {/*from ww w. j a v a 2 s . c o m*/ resp = WebServiceActions.doPost( this.OM2MUrlBase + "applications/" + obj.getContainer().getApplication().getAppId() + "/containers/" + JAXBMapper.objectToXMLString(subscription) + "/contentInstances/subscriptions", "BODY-" + new String(obj.getContent().getValue()), this.headers); // ID pas content } catch (HttpResponseException e) { resp = e.getStatusCode(); LOGGER.info(e.getStatusCode() + " / " + e.getMessage()); } catch (ClientProtocolException e) { // TODO ClientProtocolException e.printStackTrace(); } catch (IOException e) { // TODO IOException e.printStackTrace(); } return resp; }
From source file:au.csiro.casda.sodalint.ValidateCapabilities.java
private String getCapabilities(final Reporter reporter, URL serviceUrl) { String baseUrl = serviceUrl.toString(); if (!baseUrl.endsWith("/")) { baseUrl += "/"; }/*from w w w . jav a 2 s.c o m*/ String address = baseUrl + "capabilities"; try { reporter.report(SodaCode.I_VURL, "Validating URL: " + address); String content = getXmlContentFromUrl(address); if (content == null) { reporter.report(SodaCode.E_CPRS, "Capabilities response contains no content"); } return content; } catch (HttpResponseException e) { reporter.report(SodaCode.E_CPRS, "Unexpected http response: " + e.getStatusCode() + " Reason: " + e.getMessage()); } catch (UnsupportedEncodingException e) { reporter.report(SodaCode.E_CPRS, "Capabilities response has an unexpected content type:" + e.getMessage()); } catch (IOException e) { reporter.report(SodaCode.E_CPRS, "Unable to read capabilities response: " + e.getMessage()); } return null; }
From source file:fr.lissi.belilif.om2m.oao.ApplicationManager.java
@Override public Application get(String id) { Application appResponse = null;/*from w w w .j a v a2s. c o m*/ HttpGetSimpleResp resp; try { resp = WebServiceActions.doGet(this.OM2MUrlBase + "applications/" + id, headers); if (resp.getStatusCode() == 200) appResponse = (Application) JAXBMapper.XMLStringToObject(resp.getResult(), Application.class); } catch (HttpResponseException e) { LOGGER.error("HttpResponseException - " + e.getStatusCode() + " / " + e.getMessage()); } catch (ClientProtocolException e) { e.printStackTrace(); LOGGER.error(e.getMessage()); } catch (ConnectException e) { LOGGER.error( e.getMessage() + ". \nThe server '" + this.OM2MUrlBase.substring(7, 21) + "' is unreachable."); } catch (IOException e) { LOGGER.error(e.getMessage()); } return appResponse; }
From source file:fr.lissi.belilif.om2m.oao.ApplicationManager.java
@Override public List<Application> getAll(Resource resource) { // TODO manage exceptions HttpGetSimpleResp resp = null;//from ww w.j av a 2 s . c om try { resp = WebServiceActions.doGet(this.OM2MUrlBase + "applications", headers); } catch (HttpResponseException e) { LOGGER.error("HttpResponseException - " + e.getStatusCode() + " / " + e.getMessage()); } catch (ClientProtocolException e) { LOGGER.error(e); } catch (ConnectException e) { LOGGER.error( e.getMessage() + ". \nThe server '" + this.OM2MUrlBase.substring(7, 21) + "' is unreachable."); } catch (IOException e) { LOGGER.error(e); } // xml to object Applications appsResp = (Applications) JAXBMapper.XMLStringToObject(resp.getResult(), Applications.class); List<Application> apps = new ArrayList<Application>(); LOGGER.info("MODEL APPS : " + appsResp); for (ReferenceToNamedResource refToNamedRes : appsResp.getApplicationCollection().getNamedReference()) { apps.add(new Application(refToNamedRes.getId())); } return apps; }