use of org.bimserver.shared.json.ConvertException in project BIMserver by opensourceBIM.
the class Channel method checkinSync.
public SLongCheckinActionState checkinSync(String baseAddress, String token, long poid, String comment, long deserializerOid, boolean merge, long fileSize, String filename, InputStream inputStream, Long topicId) throws ServerException, UserException {
String address = baseAddress + "/upload";
HttpPost httppost = new HttpPost(address);
try {
if (topicId == null) {
topicId = getServiceInterface().initiateCheckin(poid, deserializerOid);
}
// TODO find some GzipInputStream variant that _compresses_ instead
// of _decompresses_ using deflate for now
InputStreamBody data = new InputStreamBody(new DeflaterInputStream(inputStream), filename);
MultipartEntityBuilder multipartEntityBuilder = createMultiPart();
multipartEntityBuilder.addPart("topicId", new StringBody("" + topicId, ContentType.DEFAULT_TEXT));
multipartEntityBuilder.addPart("token", new StringBody(token, ContentType.DEFAULT_TEXT));
multipartEntityBuilder.addPart("deserializerOid", new StringBody("" + deserializerOid, ContentType.DEFAULT_TEXT));
multipartEntityBuilder.addPart("merge", new StringBody("" + merge, ContentType.DEFAULT_TEXT));
multipartEntityBuilder.addPart("poid", new StringBody("" + poid, ContentType.DEFAULT_TEXT));
multipartEntityBuilder.addPart("comment", new StringBody("" + comment, ContentType.DEFAULT_TEXT));
multipartEntityBuilder.addPart("sync", new StringBody("" + true, ContentType.DEFAULT_TEXT));
multipartEntityBuilder.addPart("compression", new StringBody("deflate", ContentType.DEFAULT_TEXT));
multipartEntityBuilder.addPart("data", data);
httppost.setEntity(multipartEntityBuilder.build());
HttpResponse httpResponse = closeableHttpClient.execute(httppost);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
ObjectMapper objectMapper = new ObjectMapper();
InputStreamReader in = new InputStreamReader(httpResponse.getEntity().getContent());
try {
ObjectNode result = objectMapper.readValue(in, ObjectNode.class);
if (result.has("exception")) {
ObjectNode exceptionJson = (ObjectNode) result.get("exception");
String exceptionType = exceptionJson.get("__type").asText();
String message = exceptionJson.has("message") ? exceptionJson.get("message").asText() : "unknown";
if (exceptionType.equals(UserException.class.getSimpleName())) {
throw new UserException(message);
} else if (exceptionType.equals(ServerException.class.getSimpleName())) {
throw new ServerException(message);
}
} else {
SServicesMap sServicesMap = getSServicesMap();
try {
return (SLongCheckinActionState) getJsonConverter().fromJson(sServicesMap.getSType("SLongCheckinState"), null, result);
} catch (ConvertException e) {
throw new ServerException(e);
}
}
} finally {
in.close();
}
} else {
throw new ServerException("HTTP Status Code " + httpResponse.getStatusLine().getStatusCode() + " " + httpResponse.getStatusLine().getReasonPhrase());
}
} catch (ClientProtocolException e) {
throw new ServerException(e);
} catch (IOException e) {
throw new ServerException(e);
} catch (PublicInterfaceNotFoundException e) {
throw new ServerException(e);
} catch (Exception e) {
throw new ServerException(e);
} finally {
httppost.releaseConnection();
}
throw new ServerException("Null result");
}
use of org.bimserver.shared.json.ConvertException in project BIMserver by opensourceBIM.
the class WebSocketImpl method onMessage.
@OnWebSocketMessage
public void onMessage(String msg) {
try {
ObjectNode parse = new ObjectMapper().readValue(msg, ObjectNode.class);
// LOGGER.info(parse.toString());
if (parse instanceof ObjectNode) {
ObjectNode object = (ObjectNode) parse;
if (object.has("welcome")) {
String token = socketNotificationsClient.getBimServerClient().getToken();
session.getRemote().sendString("{\"token\":\"" + token + "\"}");
} else if (object.has("endpointid")) {
socketNotificationsClient.setEndpointId(object.get("endpointid").asLong());
countDownLatch.countDown();
// LOGGER.info("Counted down to " + countDownLatch.getCount());
} else {
try {
socketNotificationsClient.handleIncoming((ObjectNode) object.get("request"));
} catch (UserException e) {
LOGGER.error("", e);
} catch (ConvertException e) {
LOGGER.error("", e);
}
}
}
} catch (Exception e) {
LOGGER.error("", e);
}
}
Aggregations