List of usage examples for org.apache.commons.httpclient HttpStatus SC_CREATED
int SC_CREATED
To view the source code for org.apache.commons.httpclient HttpStatus SC_CREATED.
Click Source Link
From source file:org.openo.nfvo.vnfmadapter.service.csm.connect.ConnectMgrVnfm.java
/** * Make connection//from w w w. j av a 2s . co m * <br> * * @param vnfmObj * @return * @since NFVO 0.5 */ public int connect(JSONObject vnfmObj) { LOG.info("function=connect, msg=enter connect function."); ConnectInfo info = new ConnectInfo(vnfmObj.getString("url"), vnfmObj.getString("userName"), vnfmObj.getString("password"), Constant.ANONYMOUS); HttpMethod httpMethod = null; int statusCode = Constant.INTERNAL_EXCEPTION; try { httpMethod = new HttpRequests.Builder(info.getAuthenticateMode()) .setUrl(info.getUrl(), ParamConstants.CSM_AUTH_CONNECT) .setParams(String.format(ParamConstants.GET_TOKENS_V2, info.getUserName(), info.getUserPwd())) .post().execute(); statusCode = httpMethod.getStatusCode(); String result = httpMethod.getResponseBodyAsString(); if (statusCode == HttpStatus.SC_CREATED) { JSONObject accessObj = JSONObject.fromObject(result); JSONObject tokenObj = accessObj.getJSONObject("token"); Header header = httpMethod.getResponseHeader("accessSession"); setAccessSession(header.getValue()); setRoaRand(tokenObj.getString("roa_rand")); statusCode = HttpStatus.SC_OK; } else { LOG.error("connect fail, code:" + statusCode + " re:" + result); } } catch (JSONException e) { LOG.error("function=connect, msg=connect JSONException e={}.", e); } catch (VnfmException e) { LOG.error("function=connect, msg=connect VnfmException e={}.", e); } catch (IOException e) { LOG.error("function=connect, msg=connect IOException e={}.", e); } finally { clearCSMPwd(info); if (httpMethod != null) { httpMethod.releaseConnection(); } } return statusCode; }
From source file:org.openo.portal.system.RegisterService.java
private static String registerPortalService(String serviceName, String url, JSONObject json, String token) { DefaultHttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); String response = null;//from ww w . j a va2 s. co m try { if (null != json) { StringEntity s = new StringEntity(json.toString()); s.setContentEncoding("UTF-8"); s.setContentType("application/json"); post.setEntity(s); } if (!CommonUtil.isEmpty(token)) { post.addHeader("X-Auth-Token", token); } HttpResponse res = client.execute(post); if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK || res.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED) { String result = EntityUtils.toString(res.getEntity()); if (!CommonUtil.isEmpty(result)) { response = result; } else { response = null; } } logger.info("register task [" + serviceName + "] completed successfully."); } catch (Exception e) { logger.error("register task [" + serviceName + "] failed because of errors."); logger.error(e.getMessage()); } return response; }
From source file:org.openo.sdnhub.osdriverservice.openstack.client.http.OpenStackHttpConnection.java
/** * Login to OpenStack//from w w w .j a va2s .c o m * <br> * * @throws OpenStackException * @since SDNHUB 0.5 */ public void login() throws OpenStackException { if (!this.credentials.isValid()) { LOGGER.error("invalid credentials failed. "); throw new OpenStackException("Invalid credentials"); } String tokenJson = V3_TOKEN_BODY_DOMAIN_SCOPE; if (!KILO.equalsIgnoreCase(credentials.getVersion())) { tokenJson = V3_TOEKN_BODY_KILO_PLUS; } HttpInput input = new HttpInput().setUri(this.getAuthUrl() + URI_LOGIN).setMethod("post") .setBody(String.format(tokenJson, this.credentials.getUsername(), this.credentials.getPassword(), this.credentials.getDomain(), this.credentials.getDomain())); HttpResult result = this.commonRequest(input, true); HttpGateKeeper.add(input, result); if ((result.getStatus() == HttpStatus.SC_OK) || (result.getStatus() == HttpStatus.SC_CREATED)) { this.credentials.setToken(result.getRespHeaders().get("X-Subject-Token")); this.populateEndpointCache(result.getBody()); LOGGER.info("Login Successful."); } else { LOGGER.error("Login failed. " + result.getBody()); throw new OpenStackException(result.getStatus(), "Login failed"); } }
From source file:org.opens.tanaguru.util.http.HttpRequestHandler.java
private int computeStatus(int status) { switch (status) { case HttpStatus.SC_FORBIDDEN: case HttpStatus.SC_METHOD_NOT_ALLOWED: case HttpStatus.SC_BAD_REQUEST: case HttpStatus.SC_UNAUTHORIZED: case HttpStatus.SC_PAYMENT_REQUIRED: case HttpStatus.SC_NOT_FOUND: case HttpStatus.SC_NOT_ACCEPTABLE: case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED: case HttpStatus.SC_REQUEST_TIMEOUT: case HttpStatus.SC_CONFLICT: case HttpStatus.SC_GONE: case HttpStatus.SC_LENGTH_REQUIRED: case HttpStatus.SC_PRECONDITION_FAILED: case HttpStatus.SC_REQUEST_TOO_LONG: case HttpStatus.SC_REQUEST_URI_TOO_LONG: case HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE: case HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE: case HttpStatus.SC_EXPECTATION_FAILED: case HttpStatus.SC_INSUFFICIENT_SPACE_ON_RESOURCE: case HttpStatus.SC_METHOD_FAILURE: case HttpStatus.SC_UNPROCESSABLE_ENTITY: case HttpStatus.SC_LOCKED: case HttpStatus.SC_FAILED_DEPENDENCY: case HttpStatus.SC_INTERNAL_SERVER_ERROR: case HttpStatus.SC_NOT_IMPLEMENTED: case HttpStatus.SC_BAD_GATEWAY: case HttpStatus.SC_SERVICE_UNAVAILABLE: case HttpStatus.SC_GATEWAY_TIMEOUT: case HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED: case HttpStatus.SC_INSUFFICIENT_STORAGE: return 0; case HttpStatus.SC_CONTINUE: case HttpStatus.SC_SWITCHING_PROTOCOLS: case HttpStatus.SC_PROCESSING: case HttpStatus.SC_OK: case HttpStatus.SC_CREATED: case HttpStatus.SC_ACCEPTED: case HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION: case HttpStatus.SC_NO_CONTENT: case HttpStatus.SC_RESET_CONTENT: case HttpStatus.SC_PARTIAL_CONTENT: case HttpStatus.SC_MULTI_STATUS: case HttpStatus.SC_MULTIPLE_CHOICES: case HttpStatus.SC_MOVED_PERMANENTLY: case HttpStatus.SC_MOVED_TEMPORARILY: case HttpStatus.SC_SEE_OTHER: case HttpStatus.SC_NOT_MODIFIED: case HttpStatus.SC_USE_PROXY: case HttpStatus.SC_TEMPORARY_REDIRECT: return 1; default://from w ww .j av a2 s. com return 1; } }
From source file:org.osaf.caldav4j.functional.support.CalDavFixture.java
public void makeCalendar(String relativePath) throws IOException { /*//from w ww .j a v a2 s .co m GoogleCalDavDialect gdialect = new GoogleCalDavDialect(); if (dialect.equals(gdialect.getProdId())) { log.warn("Google Caldav Server doesn't support MKCALENDAR"); return; } */ MkCalendarMethod method = methodFactory.createMkCalendarMethod(relativePath); //method.setPath(relativePath); executeMethod(HttpStatus.SC_CREATED, method, true); }
From source file:org.osaf.caldav4j.functional.support.CalDavFixture.java
public void makeCollection(String relativePath) throws IOException { MkcolMethod method = new MkcolMethod(UrlUtils.removeDoubleSlashes(relativePath)); executeMethod(HttpStatus.SC_CREATED, method, true); }
From source file:org.osaf.caldav4j.functional.support.CalDavFixture.java
public void putEvent(String relativePath, VEvent event) throws IOException { PutMethod method = methodFactory.createPutMethod(); method.setPath(relativePath);/*from ww w . j av a 2 s.com*/ method.setRequestBody(event); executeMethod(HttpStatus.SC_CREATED, method, true); }
From source file:org.osaf.caldav4j.functional.support.CalDavFixture.java
protected void mkcalendar(String path) { MkCalendarMethod mk = new MkCalendarMethod(path); //mk.setPath(path); mk.addDescription(TestConstants.CALENDAR_DESCRIPTION, "en"); try {// ww w. j a v a 2s. co m executeMethod(HttpStatus.SC_CREATED, mk, true); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.osaf.caldav4j.functional.support.CalDavFixture.java
protected void mkcol(String path) { MkcolMethod mk = new MkcolMethod(path); try {//from w ww .j a v a 2 s . co m executeMethod(HttpStatus.SC_CREATED, mk, true); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.pac4j.cas.client.rest.CasRestAuthenticator.java
private String requestTicketGrantingTicket(final String username, final String password) { HttpURLConnection connection = null; try {/*from w w w.j av a 2 s . c o m*/ connection = HttpUtils.openPostConnection(new URL(getCasRestUrl())); final String payload = HttpUtils.encodeQueryParam(getUsernameParameter(), username) + "&" + HttpUtils.encodeQueryParam(getPasswordParameter(), password); final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream())); out.write(payload); out.close(); final String locationHeader = connection.getHeaderField("location"); final int responseCode = connection.getResponseCode(); if (locationHeader != null && responseCode == HttpStatus.SC_CREATED) { return locationHeader.substring(locationHeader.lastIndexOf("/") + 1); } throw new TechnicalException("Ticket granting ticket request failed: " + locationHeader + " " + responseCode + HttpUtils.buildHttpErrorMessage(connection)); } catch (final IOException e) { throw new TechnicalException(e); } finally { HttpUtils.closeConnection(connection); } }