List of usage examples for javax.xml.ws.http HTTPException HTTPException
public HTTPException(int statusCode)
From source file:io.mindmaps.engine.loader.DistributedLoader.java
public void submitBatch(Collection<Var> batch) { String batchedString = batch.stream().map(Object::toString).collect(Collectors.joining(";")); if (batchedString.length() == 0) { return;//w w w.j a va 2 s . co m } HttpURLConnection currentConn = acquireNextHost(); String query = REST.HttpConn.INSERT_PREFIX + batchedString; executePost(currentConn, query); int responseCode = getResponseCode(currentConn); if (responseCode != REST.HttpConn.HTTP_TRANSACTION_CREATED) { throw new HTTPException(responseCode); } markAsLoading(getResponseBody(currentConn)); LOG.info("Transaction sent to host: " + hostsArray[currentHost]); if (future == null) { startCheckingStatus(); } currentConn.disconnect(); }
From source file:io.mindmaps.loader.DistributedLoader.java
public void submitBatch(Collection<Var> batch) { String batchedString = batch.stream().map(Object::toString).collect(Collectors.joining(";")); if (batchedString.length() == 0) { return;/*from w ww . jav a 2 s. c om*/ } HttpURLConnection currentConn = acquireNextHost(); String query = RESTUtil.HttpConn.INSERT_PREFIX + batchedString; executePost(currentConn, query); int responseCode = getResponseCode(currentConn); if (responseCode != RESTUtil.HttpConn.HTTP_TRANSACTION_CREATED) { throw new HTTPException(responseCode); } markAsLoading(getResponseBody(currentConn)); LOG.info("Transaction sent to host: " + hostsArray[currentHost]); if (future == null) { startCheckingStatus(); } currentConn.disconnect(); }
From source file:ai.grakn.engine.loader.client.LoaderClient.java
public void sendQueriesToLoader(Collection<InsertQuery> queries) { HttpURLConnection currentConn = acquireNextHost(getPostParams()); String response = executePost(currentConn, getConfiguration(queries)); int responseCode = getResponseCode(currentConn); if (responseCode != REST.HttpConn.OK) { throw new HTTPException(responseCode); }/*from w ww . j a v a 2 s .c om*/ String job = Json.read(response).at("id").asString(); submitted.add(job); LOG.info("Job " + job + " sent to host: " + hosts.toArray()[currentHost]); if (future == null) { startCheckingStatus(); } }
From source file:com.microsoft.valda.oms.OmsAppender.java
private void sendLog(LoggingEvent event) throws NoSuchAlgorithmException, InvalidKeyException, IOException, HTTPException { //create JSON message JSONObject obj = new JSONObject(); obj.put("LOGBACKLoggerName", event.getLoggerName()); obj.put("LOGBACKLogLevel", event.getLevel().toString()); obj.put("LOGBACKMessage", event.getFormattedMessage()); obj.put("LOGBACKThread", event.getThreadName()); if (event.getCallerData() != null && event.getCallerData().length > 0) { obj.put("LOGBACKCallerData", event.getCallerData()[0].toString()); } else {/*from w w w . ja v a2s . co m*/ obj.put("LOGBACKCallerData", ""); } if (event.getThrowableProxy() != null) { obj.put("LOGBACKStackTrace", ThrowableProxyUtil.asString(event.getThrowableProxy())); } else { obj.put("LOGBACKStackTrace", ""); } if (inetAddress != null) { obj.put("LOGBACKIPAddress", inetAddress.getHostAddress()); } else { obj.put("LOGBACKIPAddress", "0.0.0.0"); } String json = obj.toJSONString(); String Signature = ""; String encodedHash = ""; String url = ""; // Todays date input for OMS Log Analytics Calendar calendar = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); String timeNow = dateFormat.format(calendar.getTime()); // String for signing the key String stringToSign = "POST\n" + json.length() + "\napplication/json\nx-ms-date:" + timeNow + "\n/api/logs"; byte[] decodedBytes = Base64.decodeBase64(sharedKey); Mac hasher = Mac.getInstance("HmacSHA256"); hasher.init(new SecretKeySpec(decodedBytes, "HmacSHA256")); byte[] hash = hasher.doFinal(stringToSign.getBytes()); encodedHash = DatatypeConverter.printBase64Binary(hash); Signature = "SharedKey " + customerId + ":" + encodedHash; url = "https://" + customerId + ".ods.opinsights.azure.com/api/logs?api-version=2016-04-01"; URL objUrl = new URL(url); HttpsURLConnection con = (HttpsURLConnection) objUrl.openConnection(); con.setDoOutput(true); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/json"); con.setRequestProperty("Log-Type", logType); con.setRequestProperty("x-ms-date", timeNow); con.setRequestProperty("Authorization", Signature); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(json); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); if (responseCode != 200) { throw new HTTPException(responseCode); } }
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
/** * Get a list of collaborations participants for instance. * @param learningObjectId/*from w w w . ja v a 2s .co m*/ * @param instanceId * @param collaborationIds The array of user IDs to filter by. * @return * @throws java.lang.Exception */ public List<CollaborationParticipant> getLearningObjectInstanceCollaborationsParticipants(int learningObjectId, int instanceId, int[] collaborationIds) throws Exception { String uri = String.format(_baseUri + "/LearningObjectService.svc/learningObjects/%s/instances/%s/collaborations/participants?collaborationIds=%s", learningObjectId, instanceId, intArrayToCsvString(collaborationIds)); HttpMethod method = getInitializedHttpMethod(_httpClient, uri, HttpMethodType.GET); List<CollaborationParticipant> collaborationParticipants = new ArrayList<CollaborationParticipant>(); try { int statusCode = _httpClient.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { throw new HTTPException(statusCode); } else { collaborationParticipants = deserializeXMLToListOfCollaborationParticipant( method.getResponseBodyAsStream()); } } catch (Exception ex) { ExceptionHandler.handle(ex); } finally { method.releaseConnection(); } return collaborationParticipants; }
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
public void sendNotification(Notification notification, int instanceId, int learningObjectId) throws Exception { String uri = String.format( _baseUri + "/LearningObjectService.svc/learningObjects/%s/instances/%s/Notification", learningObjectId, instanceId); PostMethod method = (PostMethod) getInitializedHttpMethod(_httpClient, uri, HttpMethodType.POST); String reportAsXml = serializeNotificationToXML(notification); InputStream is = new ByteArrayInputStream(reportAsXml.getBytes("UTF-8")); method.setRequestEntity(new InputStreamRequestEntity(is)); try {// w w w.j a v a2 s . c o m int statusCode = _httpClient.executeMethod(method); // POST methods, may return 200, 201, 204 if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED && statusCode != HttpStatus.SC_NOT_MODIFIED) { throw new HTTPException(statusCode); } } catch (Exception ex) { ExceptionHandler.handle(ex); } finally { method.releaseConnection(); } }
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
public void sendNotificationToUsers(Notification notification, int learningObjectId, int instanceId, int[] receiverUserIds, int senderUserId) throws Exception { String uri = String.format( _baseUri + "/LearningObjectService.svc/learningObjects/%s/instances/%s/NotificationToUsers", learningObjectId, instanceId); PostMethod method = (PostMethod) getInitializedHttpMethod(_httpClient, uri, HttpMethodType.POST); String reportAsXml = serializeNotificationToWrappedXML(notification); String userIdsAsXml = serializeUserIdsToWrappedXML(receiverUserIds); String senderUserIdAsXml = "<senderUserId>" + Integer.toString(senderUserId) + "</senderUserId>"; String openingTag = "<SendNotificationToUsers xmlns=\"http://tempuri.org/\">"; String closingTag = "</SendNotificationToUsers>"; StringBuilder xmlBuilder = new StringBuilder(); xmlBuilder.append(openingTag);/*from w w w .j a v a 2 s. co m*/ xmlBuilder.append(reportAsXml); xmlBuilder.append(userIdsAsXml); xmlBuilder.append(senderUserIdAsXml); xmlBuilder.append(closingTag); method.setRequestEntity(new StringRequestEntity(xmlBuilder.toString(), "text/xml", "UTF-8")); try { int statusCode = _httpClient.executeMethod(method); // POST methods, may return 200, 201, 204 if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED && statusCode != HttpStatus.SC_NOT_MODIFIED) { throw new HTTPException(statusCode); } } catch (Exception ex) { ExceptionHandler.handle(ex); } finally { method.releaseConnection(); } }
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
public void setUpdated(int instanceId, int learningObjectId) throws Exception { String uri = String.format(_baseUri + "/LearningObjectService.svc/learningObjects/%s/instances/%s/Updated", learningObjectId, instanceId); PostMethod method = (PostMethod) getInitializedHttpMethod(_httpClient, uri, HttpMethodType.POST); try {/*from w w w .j a v a 2 s .c o m*/ int statusCode = _httpClient.executeMethod(method); // POST methods, may return 200, 201, 204 if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED && statusCode != HttpStatus.SC_NOT_MODIFIED) { throw new HTTPException(statusCode); } } catch (Exception ex) { ExceptionHandler.handle(ex); } finally { method.releaseConnection(); } }
From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java
public LearningObjectInstance getLearningObjectInstance(int instanceId, int learningObjectId) throws Exception { String uri = String.format(_baseUri + "/LearningObjectService.svc/learningObjects/%s/instances/%s", learningObjectId, instanceId); HttpMethod method = getInitializedHttpMethod(_httpClient, uri, HttpMethodType.GET); LearningObjectInstance loi = null;//from w w w .jav a2 s. c o m try { int statusCode = _httpClient.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { throw new HTTPException(statusCode); } else { loi = deserializeXMLToLearningObjectInstance(method.getResponseBodyAsStream()); } } catch (Exception ex) { ExceptionHandler.handle(ex); } finally { method.releaseConnection(); } return loi; }