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 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 {
InputStream inputStream = getDownloadData(topicId);
try {
IOUtils.copy(inputStream, outputStream);
getServiceInterface().cleanupLongAction(topicId);
} finally {
inputStream.close();
}
}
} 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 Channel method checkin.
public long checkin(String baseAddress, String token, long poid, String comment, long deserializerOid, boolean merge, Flow flow, long fileSize, String filename, InputStream inputStream) throws ServerException, UserException {
String address = baseAddress + "/upload";
HttpPost httppost = new HttpPost(address);
try {
Long 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 = MultipartEntityBuilder.create();
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("" + (flow == Flow.SYNC), 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) {
JsonParser jsonParser = new JsonParser();
InputStreamReader in = new InputStreamReader(httpResponse.getEntity().getContent());
try {
JsonElement result = jsonParser.parse(new JsonReader(in));
if (result instanceof JsonObject) {
JsonObject jsonObject = (JsonObject) result;
if (jsonObject.has("exception")) {
JsonObject exceptionJson = jsonObject.get("exception").getAsJsonObject();
String exceptionType = exceptionJson.get("__type").getAsString();
String message = exceptionJson.has("message") ? exceptionJson.get("message").getAsString() : "unknown";
if (exceptionType.equals(UserException.class.getSimpleName())) {
throw new UserException(message);
} else if (exceptionType.equals(ServerException.class.getSimpleName())) {
throw new ServerException(message);
}
} else {
if (jsonObject.has("topicId")) {
return jsonObject.get("topicId").getAsLong();
} else {
throw new ServerException("No topicId found in response: " + jsonObject.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);
System.out.println(client.getServiceInterface().getFile(fileId));
SProject project = client.getServiceInterface().addProject("test23", "ifc2x3tc1");
SDeserializerPluginConfiguration deserializerForExtension = client.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
client.checkin(project.getOid(), "initial", deserializerForExtension.getOid(), false, Flow.SYNC, Paths.get("../TestData/data/AC11-FZK-Haus-IFC.ifc"));
project = client.getServiceInterface().getProjectByPoid(project.getOid());
SExtendedDataSchema extendedDataSchemaByNamespace = client.getServiceInterface().getExtendedDataSchemaByName("http://extend.bimserver.org/validationreport");
SExtendedData extendedData = new SExtendedData();
extendedData.setFileId(fileId);
extendedData.setTitle("test3");
extendedData.setSchemaId(extendedDataSchemaByNamespace.getOid());
client.getServiceInterface().addExtendedDataToRevision(project.getLastRevisionId(), extendedData);
} catch (ServiceException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.bimserver.shared.exceptions.PublicInterfaceNotFoundException in project BIMserver by opensourceBIM.
the class TestChangeDescription method start.
private void start() {
BimServerClientInterface client = LocalDevSetup.setupJson("http://localhost:8080");
try {
SProject project = client.getServiceInterface().getProjectsByName("dfgfgdf").get(0);
IfcModelInterface model = client.getModel(project, project.getLastRevisionId(), false, true);
for (IfcWall wall : model.getAllWithSubTypes(IfcWall.class)) {
wall.setDescription(wall.getDescription() + " Changed");
}
model.commit("test");
} catch (UserException e) {
e.printStackTrace();
} catch (ServerException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e) {
e.printStackTrace();
} catch (BimServerClientException e) {
e.printStackTrace();
}
}
Aggregations