use of org.bimserver.shared.exceptions.PublicInterfaceNotFoundException in project BIMserver by opensourceBIM.
the class BimServerClient method download.
public void download(long roid, long serializerOid, OutputStream outputStream) throws BimServerClientException {
try {
Long topicId = getServiceInterface().download(Collections.singleton(roid), DefaultQueries.allAsString(), serializerOid, false);
SLongActionState progress = getNotificationRegistryInterface().getProgress(topicId);
if (progress != null && progress.getState() == SActionState.AS_ERROR) {
throw new BimServerClientException(Joiner.on(", ").join(progress.getErrors()));
} else {
try (InputStream inputStream = getDownloadData(topicId)) {
IOUtils.copy(inputStream, outputStream);
getServiceInterface().cleanupLongAction(topicId);
}
}
} catch (ServerException e) {
LOGGER.error("", e);
} catch (UserException e) {
LOGGER.error("", e);
} catch (IOException e) {
LOGGER.error("", e);
} catch (PublicInterfaceNotFoundException e) {
LOGGER.error("", e);
}
}
use of org.bimserver.shared.exceptions.PublicInterfaceNotFoundException in project BIMserver by opensourceBIM.
the class BimServerClient method authenticate.
public void authenticate() throws ServerException, UserException {
try {
AuthInterface authInterface = channel.get(AuthInterface.class);
if (authenticationInfo instanceof UsernamePasswordAuthenticationInfo) {
UsernamePasswordAuthenticationInfo usernamePasswordAuthenticationInfo = (UsernamePasswordAuthenticationInfo) authenticationInfo;
setToken(authInterface.login(usernamePasswordAuthenticationInfo.getUsername(), usernamePasswordAuthenticationInfo.getPassword()));
} else if (authenticationInfo instanceof AutologinAuthenticationInfo) {
AutologinAuthenticationInfo autologinAuthenticationInfo = (AutologinAuthenticationInfo) authenticationInfo;
setToken(autologinAuthenticationInfo.getAutologinCode());
} else if (authenticationInfo instanceof TokenAuthentication) {
TokenAuthentication tokenAuthentication = (TokenAuthentication) authenticationInfo;
setToken(tokenAuthentication.getToken());
} else if (authenticationInfo instanceof UserTokenAuthentication) {
UserTokenAuthentication tokenAuthentication = (UserTokenAuthentication) authenticationInfo;
setToken(authInterface.loginUserToken(tokenAuthentication.getToken()));
} else if (authenticationInfo instanceof SystemAuthentication) {
}
} catch (PublicInterfaceNotFoundException e) {
LOGGER.error("", e);
}
}
use of org.bimserver.shared.exceptions.PublicInterfaceNotFoundException in project BIMserver by opensourceBIM.
the class Channel method bulkCheckin.
public void bulkCheckin(String baseAddress, String token, long poid, String comment, Path file) throws UserException, ServerException {
String address = baseAddress + "/bulkupload";
HttpPost httppost = new HttpPost(address);
try (InputStream inputStream = Files.newInputStream(file)) {
InputStreamBody data = new InputStreamBody(inputStream, file.getFileName().toString());
MultipartEntityBuilder multipartEntityBuilder = createMultiPart();
multipartEntityBuilder.addPart("token", new StringBody(token, ContentType.DEFAULT_TEXT));
multipartEntityBuilder.addPart("poid", new StringBody("" + poid, ContentType.DEFAULT_TEXT));
multipartEntityBuilder.addPart("comment", new StringBody("" + comment, 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);
}
}
} finally {
in.close();
}
}
} catch (ClientProtocolException e) {
throw new ServerException(e);
} catch (IOException e) {
throw new ServerException(e);
} catch (PublicInterfaceNotFoundException e) {
throw new ServerException(e);
} finally {
httppost.releaseConnection();
}
}
use of org.bimserver.shared.exceptions.PublicInterfaceNotFoundException in project BIMserver by opensourceBIM.
the class Channel method checkinAsync.
public long checkinAsync(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 {
// 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("" + false, 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 {
if (result.has("topicId")) {
return result.get("topicId").asLong();
} else {
throw new ServerException("No topicId found in response: " + result.toString());
}
}
} finally {
in.close();
}
}
} catch (ClientProtocolException e) {
throw new ServerException(e);
} catch (IOException e) {
throw new ServerException(e);
} catch (PublicInterfaceNotFoundException e) {
throw new ServerException(e);
} finally {
httppost.releaseConnection();
}
return -1;
}
use of org.bimserver.shared.exceptions.PublicInterfaceNotFoundException in project BIMserver by opensourceBIM.
the class TestAddExtendedData method start.
private void start() {
try {
BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
SFile file = new SFile();
file.setData("test".getBytes(Charsets.UTF_8));
file.setMime("text");
file.setFilename("test.txt");
long fileId = client.getServiceInterface().uploadFile(file);
SProject project = client.getServiceInterface().addProject("t2es035442t23", "ifc2x3tc1");
SDeserializerPluginConfiguration deserializerForExtension = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
SLongCheckinActionState checkinSync = client.checkinSync(project.getOid(), "initial", deserializerForExtension.getOid(), false, Paths.get("../../TestFiles/TestData/data/AC11-FZK-Haus-IFC.ifc"));
SExtendedDataSchema extendedDataSchemaByNamespace = client.getServiceInterface().getExtendedDataSchemaByName("GEOMETRY_GENERATION_REPORT_JSON_1_1");
SExtendedData extendedData = new SExtendedData();
extendedData.setFileId(fileId);
extendedData.setTitle("test3");
extendedData.setSchemaId(extendedDataSchemaByNamespace.getOid());
client.getServiceInterface().addExtendedDataToRevision(checkinSync.getRoid(), extendedData);
} catch (ServiceException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations