List of usage examples for java.net HttpURLConnection HTTP_CREATED
int HTTP_CREATED
To view the source code for java.net HttpURLConnection HTTP_CREATED.
Click Source Link
From source file:com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.java
/** * {@inheritDoc}//from w ww . j a v a 2 s . c om */ @Override public void postComment(String networkUpdateId, String commentText) { assertNotNullOrEmpty("network update id", networkUpdateId); assertNotNullOrEmpty("comment", commentText); LinkedInApiUrlBuilder builder = createLinkedInApiUrlBuilder(LinkedInApiUrls.POST_COMMENT); String apiUrl = builder.withField(ParameterNames.UPDATE_KEY, networkUpdateId).buildUrl(); UpdateComment comment = OBJECT_FACTORY.createUpdateComment(); comment.setComment(commentText); callApiMethod(apiUrl, marshallObject(comment), ApplicationConstants.CONTENT_TYPE_XML, HttpMethod.POST, HttpURLConnection.HTTP_CREATED); }
From source file:com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.java
/** * {@inheritDoc}/* w ww. j a v a 2 s . c o m*/ */ @Override public void postNetworkUpdate(String updateText) { assertNotNullOrEmpty("network update", updateText); LinkedInApiUrlBuilder builder = createLinkedInApiUrlBuilder(LinkedInApiUrls.POST_UPDATE); String apiUrl = builder.buildUrl(); Activity update = OBJECT_FACTORY.createActivity(); update.setBody(updateText); update.setLocale(Locale.getDefault().toString()); update.setContentType(NetworkUpdateContentType.LINKED_IN_HTML); update.setTimestamp(System.currentTimeMillis()); callApiMethod(apiUrl, marshallObject(update), ApplicationConstants.CONTENT_TYPE_XML, HttpMethod.POST, HttpURLConnection.HTTP_CREATED); }
From source file:org.openecomp.sdnc.sli.aai.AAIService.java
@Override public boolean postSitePairSetData(String linkName, SitePairSet request) throws AAIServiceException { InputStream inputStream = null; try {/*ww w . java 2s .c o m*/ ObjectMapper mapper = getObjectMapper(); String json_text = mapper.writeValueAsString(request); SSLSocketFactory sockFact = CTX.getSocketFactory(); String request_url = target_uri + site_pair_set_path; String encoded_vnf = encodeQuery(linkName); request_url = request_url.replace("{site-pair-set-id}", encoded_vnf); URL http_req_url = new URL(request_url); HttpURLConnection con = getConfiguredConnection(http_req_url, HttpMethod.PUT); OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream()); osw.write(json_text); osw.flush(); osw.close(); LOGwriteFirstTrace("PUT", request_url); LOGwriteDateTrace("link-name", linkName); LOGwriteDateTrace("SitePairSet", json_text); // Check for errors int responseCode = con.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) { inputStream = con.getInputStream(); } else { inputStream = con.getErrorStream(); } // Process the response BufferedReader reader; String line = null; reader = new BufferedReader(new InputStreamReader(inputStream)); if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) { StringBuilder stringBuilder = new StringBuilder(); while ((line = reader.readLine()) != null) { stringBuilder.append(line); } LOGwriteEndingTrace(responseCode, "SUCCESS", (stringBuilder != null) ? stringBuilder.toString() : "{no-data}"); return true; } else { ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class); LOGwriteEndingTrace(responseCode, "FAILURE", mapper.writeValueAsString(errorresponse)); throw new AAIServiceException(responseCode, errorresponse); } } catch (AAIServiceException aaiexc) { throw aaiexc; } catch (Exception exc) { LOG.warn("postSitePairSetData", exc); throw new AAIServiceException(exc); } finally { try { if (inputStream != null) inputStream.close(); } catch (Exception exc) { } } }
From source file:org.openecomp.sdnc.sli.aai.AAIService.java
@Override public boolean postServiceData(String linkName, Service request) throws AAIServiceException { InputStream inputStream = null; try {//from www . j a v a 2 s . c o m ObjectMapper mapper = getObjectMapper(); String json_text = mapper.writeValueAsString(request); SSLSocketFactory sockFact = CTX.getSocketFactory(); String request_url = target_uri + service_path; String encoded_vnf = encodeQuery(linkName); request_url = request_url.replace("{service-id}", encoded_vnf); URL http_req_url = new URL(request_url); HttpURLConnection con = getConfiguredConnection(http_req_url, HttpMethod.PUT); OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream()); osw.write(json_text); osw.flush(); osw.close(); LOGwriteFirstTrace("PUT", request_url); LOGwriteDateTrace("service-id", linkName); LOGwriteDateTrace("Service", json_text); // Check for errors int responseCode = con.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) { inputStream = con.getInputStream(); } else { inputStream = con.getErrorStream(); } // Process the response BufferedReader reader; String line = null; reader = new BufferedReader(new InputStreamReader(inputStream)); if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) { StringBuilder stringBuilder = new StringBuilder(); while ((line = reader.readLine()) != null) { stringBuilder.append(line); } LOGwriteEndingTrace(responseCode, "SUCCESS", (stringBuilder != null) ? stringBuilder.toString() : "{no-data}"); return true; } else { ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class); LOGwriteEndingTrace(responseCode, "FAILURE", mapper.writeValueAsString(errorresponse)); throw new AAIServiceException(responseCode, errorresponse); } } catch (AAIServiceException aaiexc) { throw aaiexc; } catch (Exception exc) { LOG.warn("postServiceData", exc); throw new AAIServiceException(exc); } finally { try { if (inputStream != null) inputStream.close(); } catch (Exception exc) { } } }
From source file:study.tdcc.act.MainCalendar.java
/** * Google??//from www. ja v a2 s . co m * * @return boolean true:??, false:?? */ public boolean updateGoogleCalendar() { Log.d("DEBUG", "MainCalendar updateGoogleCalendar Start"); boolean blResult = true; //ScheduleDatabaseHelper? sdhDB = new ScheduleDatabaseHelper(this); //? boolean blChangeScheduleResult = selectChangeSchedule(); if (blChangeScheduleResult == false) { Log.e("ERROR", "MainCalendar updateGoogleCalendar ?"); blResult = false; } else { //? GDataCalendarParser gcpObj = new GDataCalendarParser(this, sdhDB); //Delete??? String strDeleteResult = null; String strInsertTime = null; //Insert? for (GDataEvent gdeObj : alInsertGCEvents) { //Insert???POST???? //?parse??????? StringBuffer sbPostURL = new StringBuffer(); sbPostURL.append(DEFAULT_URL); sbPostURL.append("?oauth_token="); //Google?????? if (strRefreshToken != null && (lgAccessTokenExpire < Calendar.getInstance().getTimeInMillis())) { boolean blReToken = true; //???? blReToken = reacquisitionToken(); if (blReToken == false) { //????????? Log.e("ERROR", "MainCalendar updateGoogleCalendar ????"); blResult = false; break; } } sbPostURL.append(strAccessToken); //?? strInsertTime = DateUtil.toUTCString(new GregorianCalendar()); //?updated-min???????? sbPostURL.append("&updated-min="); sbPostURL.append(strInsertTime); ArrayList<String> alResult = new ArrayList<String>(); alResult = gcpObj.parse(httpPost(sbPostURL.toString(), gcpObj.insertSerializer(gdeObj)), gdeObj.getLgAlarmFlag()); if (blHttpSucceeded && alResult != null && alResult.get(1) == null && intResponseCode == HttpURLConnection.HTTP_CREATED) { //?? //SQL?(ID) Schedule objSchedule = new Schedule(); objSchedule.setLgId(gdeObj.getLgId()); //SCHEDULE(?) blResult = sdhDB.deleteScheduleId(objSchedule); if (blResult == false) { //SCHEDULE?? Log.e("ERROR", "MainCalendar updateGoogleCalendar Insert??? " + gdeObj.getLgId()); //?(OutOfMemoryError) alResult = null; break; } //?(OutOfMemoryError) alResult = null; } else if (blHttpSucceeded && alResult != null && alResult.get(1) == null && intResponseCode == HttpURLConnection.HTTP_OK) { //?????Google????????? Log.e("ERROR", "MainCalendar updateGoogleCalendar Insert???200? " + gdeObj.getLgId()); //?(OutOfMemoryError) alResult = null; } else { //HttpPost?? Log.e("ERROR", "MainCalendar updateGoogleCalendar Insert? " + gdeObj.getLgId()); blResult = false; //?(OutOfMemoryError) alResult = null; break; } } //Insert?????????Update? if (blResult == true) { //Update? for (GDataEvent gdeObj : alUpdateGCEvents) { //URL? StringBuffer sbPostURL = new StringBuffer(); sbPostURL.append(gdeObj.getStrEditUrl()); sbPostURL.append("?oauth_token="); //Google?????? if (strRefreshToken != null && (lgAccessTokenExpire < Calendar.getInstance().getTimeInMillis())) { boolean blReToken = true; //???? blReToken = reacquisitionToken(); if (blReToken == false) { //????????? Log.e("ERROR", "MainCalendar updateGoogleCalendar ????"); blResult = false; break; } } sbPostURL.append(strAccessToken); //????? ArrayList<String> alResult = new ArrayList<String>(); alResult = gcpObj.parse( httpPut(sbPostURL.toString(), gcpObj.updateSerializer(httpGet(sbPostURL.toString()), gdeObj)), gdeObj.getLgAlarmFlag()); //??Google?????? //Modified???????????????? //???????????MODIFIED????????? //???????????) if (alResult == null || !(blHttpSucceeded && alResult.get(1) == null)) { //HttpPut????DB? Log.e("ERROR", "MainCalendar updateGoogleCalendar Update? " + gdeObj.getLgId()); blResult = false; //?(OutOfMemoryError) alResult = null; break; } //?(OutOfMemoryError) alResult = null; } } //Insert?orUpdate?????????Delete? if (blResult == true) { //Delete? for (GDataEvent gdeObj : alDeleteGCEvents) { //URL???httpDelete?? StringBuffer sbPostURL = new StringBuffer(); sbPostURL.append(gdeObj.getStrEditUrl()); sbPostURL.append("?oauth_token="); //Google?????? if (strRefreshToken != null && (lgAccessTokenExpire < Calendar.getInstance().getTimeInMillis())) { boolean blReToken = true; //???? blReToken = reacquisitionToken(); if (blReToken == false) { //????????? Log.e("ERROR", "MainCalendar updateGoogleCalendar ????"); blResult = false; break; } } sbPostURL.append(strAccessToken); InputStream isResult = httpDelete(sbPostURL.toString()); if (isResult != null) { strDeleteResult = InputCheckUtil.convertStreamToString(isResult); } else { strDeleteResult = null; } if (blHttpSucceeded && (strDeleteResult != null && strDeleteResult.equals(""))) { //? //SQL?(ID) Schedule objSchedule = new Schedule(); objSchedule.setLgId(gdeObj.getLgId()); //SCHEDULE(?) blResult = sdhDB.deleteScheduleId(objSchedule); if (blResult == false) { //SCHEDULE?? Log.e("ERROR", "MainCalendar updateGoogleCalendar Delete??? " + gdeObj.getLgId()); break; } } else if (blHttpSucceeded && (strDeleteResult != null && strDeleteResult.equals("") == false)) { //?????Google???????? Log.e("ERROR", "MainCalendar updateGoogleCalendar Delete???200??????? " + gdeObj.getLgId()); } else { //HttpPost?? Log.e("ERROR", "MainCalendar updateGoogleCalendar Delete? " + gdeObj.getLgId()); blResult = false; break; } } } //?(OutOfMemoryError) gcpObj = null; alInsertGCEvents = null; alUpdateGCEvents = null; alDeleteGCEvents = null; } Log.d("DEBUG", "MainCalendar updateGoogleCalendar End"); return blResult; }
From source file:com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.java
/** * {@inheritDoc}/*from w w w. j a v a 2 s . c o m*/ */ @Override public void sendInviteByEmail(String email, String firstName, String lastName, String subject, String message) { assertNotNullOrEmpty("email", email); assertNotNullOrEmpty("firstName", firstName); assertNotNullOrEmpty("lastName", lastName); assertNotNullOrEmpty("subject", subject); assertNotNullOrEmpty("message", message); LinkedInApiUrlBuilder builder = createLinkedInApiUrlBuilder(LinkedInApiUrls.SEND_MESSAGE); String apiUrl = builder.buildUrl(); MailboxItem invite = OBJECT_FACTORY.createMailboxItem(); invite.setBody(message); invite.setSubject(subject); invite.setRecipients(OBJECT_FACTORY.createRecipients()); Person person = OBJECT_FACTORY.createPerson(); person.setPath(createLinkedInApiUrlBuilder(LinkedInApiUrls.SEND_INVITE_EMAIL_PERSON_PATH) .withField(ParameterNames.EMAIL, email).buildUrl()); person.setFirstName(firstName); person.setLastName(lastName); Recipient recepient = OBJECT_FACTORY.createRecipient(); recepient.setPerson(person); invite.getRecipients().getRecipientList().add(recepient); invite.setItemContent(OBJECT_FACTORY.createItemContent()); InvitationRequest request = OBJECT_FACTORY.createInvitationRequest(); request.setConnectType(InviteConnectType.FRIEND); invite.getItemContent().setInvitationRequest(request); callApiMethod(apiUrl, marshallObject(invite), ApplicationConstants.CONTENT_TYPE_XML, HttpMethod.POST, HttpURLConnection.HTTP_CREATED); }
From source file:com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.java
/** * {@inheritDoc}/*from w w w . ja v a 2s. c o m*/ */ @Override public void sendInviteById(String recepientId, String subject, String message, String authHeader) { assertNotNullOrEmpty("recepient id", recepientId); assertNotNullOrEmpty("subject", subject); assertNotNullOrEmpty("message", message); assertNotNullOrEmpty("auth header", authHeader); LinkedInApiUrlBuilder builder = createLinkedInApiUrlBuilder(LinkedInApiUrls.SEND_MESSAGE); String apiUrl = builder.buildUrl(); MailboxItem invite = OBJECT_FACTORY.createMailboxItem(); invite.setBody(message); invite.setSubject(subject); invite.setRecipients(OBJECT_FACTORY.createRecipients()); Person person = OBJECT_FACTORY.createPerson(); person.setPath(createLinkedInApiUrlBuilder(LinkedInApiUrls.SEND_INVITE_ID_PERSON_PATH) .withField(ParameterNames.ID, recepientId).buildUrl()); Recipient recepient = OBJECT_FACTORY.createRecipient(); recepient.setPerson(person); invite.getRecipients().getRecipientList().add(recepient); invite.setItemContent(OBJECT_FACTORY.createItemContent()); InvitationRequest request = OBJECT_FACTORY.createInvitationRequest(); request.setConnectType(InviteConnectType.FRIEND); String[] authTuple = authHeader.split(":"); if (authTuple.length == 2) { Authorization authorization = OBJECT_FACTORY.createAuthorization(); authorization.setName(authTuple[0]); authorization.setValue(authTuple[1]); request.setAuthorization(authorization); } invite.getItemContent().setInvitationRequest(request); callApiMethod(apiUrl, marshallObject(invite), ApplicationConstants.CONTENT_TYPE_XML, HttpMethod.POST, HttpURLConnection.HTTP_CREATED); }
From source file:org.openecomp.sdnc.sli.aai.AAIService.java
public boolean sendNotify(NotifyEvent event, String serviceInstanceId, String pathCode) throws AAIServiceException { InputStream inputStream = null; try {/*from w ww.j av a 2s . c om*/ String selfLink = selflink_fqdn; if (SELFLINK_AVPN != null && SELFLINK_AVPN.equals(pathCode)) { selfLink = selflink_avpn; } selfLink = selfLink.replace("{service-instance-id}", encodeQuery(serviceInstanceId)); event.setSelflink(selfLink); ObjectMapper mapper = getObjectMapper(); String json_text = mapper.writeValueAsString(event); SSLSocketFactory sockFact = CTX.getSocketFactory(); String request_url = target_uri + ubb_notify_path; URL http_req_url = new URL(request_url); HttpURLConnection con = getConfiguredConnection(http_req_url, HttpMethod.PUT); OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream()); osw.write(json_text); osw.flush(); osw.close(); LOGwriteFirstTrace("PUT", request_url); LOGwriteDateTrace("NotifyEvent", json_text); // Check for errors int responseCode = con.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) { inputStream = con.getInputStream(); } else { inputStream = con.getErrorStream(); } // Process the response BufferedReader reader; String line = null; reader = new BufferedReader(new InputStreamReader(inputStream)); if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) { StringBuilder stringBuilder = new StringBuilder(); while ((line = reader.readLine()) != null) { stringBuilder.append(line); } LOGwriteEndingTrace(responseCode, "SUCCESS", (stringBuilder != null) ? stringBuilder.toString() : "{no-data}"); return true; } else { ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class); LOGwriteEndingTrace(responseCode, "FAILURE", mapper.writeValueAsString(errorresponse)); throw new AAIServiceException(responseCode, errorresponse); } } catch (AAIServiceException aaiexc) { throw aaiexc; } catch (Exception exc) { LOG.warn("sendNotify", exc); throw new AAIServiceException(exc); } finally { try { if (inputStream != null) inputStream.close(); } catch (Exception exc) { } } }
From source file:com.google.code.linkedinapi.client.impl.BaseLinkedInApiClient.java
/** * {@inheritDoc}//from ww w. j a va2 s . c o m */ @Override public void sendMessage(List<String> recepientIds, String subject, String message) { assertNotNullOrEmpty("recepient ids", recepientIds); assertNotNullOrEmpty("subject", subject); assertNotNullOrEmpty("message", message); LinkedInApiUrlBuilder builder = createLinkedInApiUrlBuilder(LinkedInApiUrls.SEND_MESSAGE); String apiUrl = builder.buildUrl(); MailboxItem messageItem = OBJECT_FACTORY.createMailboxItem(); messageItem.setBody(message); messageItem.setSubject(subject); messageItem.setRecipients(OBJECT_FACTORY.createRecipients()); for (String recepientId : recepientIds) { Person person = OBJECT_FACTORY.createPerson(); person.setPath(createLinkedInApiUrlBuilder(LinkedInApiUrls.SEND_MESSAGE_PERSON_PATH) .withField(ParameterNames.ID, recepientId).buildUrl()); Recipient recepient = OBJECT_FACTORY.createRecipient(); recepient.setPerson(person); messageItem.getRecipients().getRecipientList().add(recepient); } callApiMethod(apiUrl, marshallObject(messageItem), ApplicationConstants.CONTENT_TYPE_XML, HttpMethod.POST, HttpURLConnection.HTTP_CREATED); }
From source file:study.tdcc.act.MainCalendar.java
/** * XML?????//w ww . ja va 2 s . c o m * * @param strUrl * @param strXml * @param strMethod (PUT,DELETE) * @return InputStream ???InputStream */ public InputStream httpPostXml(String strUrl, String strXml, String strMethod) { Log.d("DEBUG", "MainCalendar httpPostXml Start"); blHttpSucceeded = false; try { while (strUrl != null) { URL urlObj = new URL(strUrl); //URL????? HttpURLConnection httpURLCObj = (HttpURLConnection) urlObj.openConnection(); //?POST? httpURLCObj.setRequestMethod("POST"); //GData-Version? httpURLCObj.setRequestProperty(GDATA_VERSION_TAG, GDATA_VERSION); if (strMethod != null) { //POST??????If-Match:*?X-HTTP-Method-Override httpURLCObj.setRequestProperty("If-Match", "*"); httpURLCObj.setRequestProperty("X-HTTP-Method-Override", strMethod); } // httpURLCObj.setDoOutput(true); //Content-Type??XML httpURLCObj.setRequestProperty("Content-Type", CONTENT_TYPE_AA); // httpURLCObj.setUseCaches(false); //OutputStreamWriter??XML?? OutputStreamWriter outputStreamWriter = new OutputStreamWriter(httpURLCObj.getOutputStream(), "UTF-8"); outputStreamWriter.write(strXml); outputStreamWriter.close(); //HTTP?? intResponseCode = 0; intResponseCode = httpURLCObj.getResponseCode(); strUrl = null; Log.d("DEBUG", "MainCalendar httpPostXml HttpResponseCode : " + intResponseCode); if (intResponseCode == HttpURLConnection.HTTP_OK || intResponseCode == HttpURLConnection.HTTP_CREATED) { //??OK???CREATED????? blHttpSucceeded = true; Log.d("DEBUG", "MainCalendar httpPostXml End(1)"); //?InputStream?? return httpURLCObj.getInputStream(); } else if (intResponseCode == HttpURLConnection.HTTP_MOVED_TEMP) { //??MOVED_TEMP????????? //?Location????URL????(?while? Map<String, List<String>> mResponseHeaders = httpURLCObj.getHeaderFields(); if (mResponseHeaders.containsKey("Location")) { strUrl = mResponseHeaders.get("Location").get(0); } else if (mResponseHeaders.containsKey("location")) { strUrl = mResponseHeaders.get("location").get(0); } } else { //??OK???CREATED???MOVED_TEMP?? blHttpSucceeded = false; Log.d("DEBUG", "MainCalendar httpPostXml End(2) ??OK,CREATED,MOVED_TEMP??"); } } } catch (Exception e) { Log.e("ERROR", "MainCalendar httpPostXml ERROR", e); } Log.d("DEBUG", "MainCalendar httpPostXml End(3)"); return null; }