private static RepoTO loadPlaintextRepoTO(File repoFile, ConfigTO configTO) throws Exception { logger.log(Level.INFO, "Loading (unencrypted) repo file from {0} ...", repoFile); return new Persister().read(RepoTO.class, repoFile); }
public static TransactionTO load(Transformer transformer, File transactionFile) throws Exception { InputStream is; if (transformer == null) { is = new FileInputStream(transactionFile); } else { is = transformer.createInputStream(new FileInputStream(transactionFile)); } return new Persister().read(TransactionTO.class, is); }
private PortTO readPortConfig(File portFile) { try { return new Persister().read(PortTO.class, portFile); } catch (Exception e) { logger.log(Level.SEVERE, "ERROR: Could not read portFile to connect to daemon.", e); showErrorAndExit("Cannot connect to daemon."); return null; // Never reached! } }
private String shortenLink(String applicationLink) { if (!LINK_PATTERN.matcher(applicationLink).matches()) { throw new IllegalArgumentException("Invalid link provided, must start with syncany:// and match link pattern."); } try { logger.log(Level.INFO, "Shortining link " + applicationLink + " via " + LINK_SHORT_API_URL_ADD + " ..."); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("l", applicationLink)); HttpPost postMethod = new HttpPost(LINK_SHORT_API_URL_ADD); postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse httpResponse = createHttpClient().execute(postMethod); ApplicationLinkShortenerResponse shortenerResponse = new Persister().read(ApplicationLinkShortenerResponse.class, httpResponse .getEntity().getContent()); return String.format(LINK_SHORT_URL_FORMAT, shortenerResponse.getShortLinkId()); } catch (Exception e) { logger.log(Level.WARNING, "Cannot shorten URL. Using long URL.", e); return applicationLink; } }
private static RepoTO loadEncryptedRepoTO(File repoFile, ConfigTO configTO) throws Exception { logger.log(Level.INFO, "Loading encrypted repo file from {0} ...", repoFile); SaltedSecretKey masterKey = configTO.getMasterKey(); if (masterKey == null) { throw new ConfigException("Repo file is encrypted, but master key not set in config file."); } String repoFileStr = new String(CipherUtil.decrypt(new FileInputStream(repoFile), masterKey)); return new Persister().read(RepoTO.class, repoFileStr); } }
public static DaemonConfigTO load(File file) throws ConfigException { try { return new Persister().read(DaemonConfigTO.class, file); } catch (Exception e) { throw new ConfigException("Config file does not exist or is invalid: " + file, e); } }
private PluginInfo getRemotePluginInfo(String pluginId) throws Exception { String remoteListStr = getRemoteListStr(pluginId); PluginListResponse pluginListResponse = new Persister().read(PluginListResponse.class, remoteListStr); if (pluginListResponse.getPlugins().size() > 0) { return pluginListResponse.getPlugins().get(0); } else { return null; } }
private TransferSettings createTransferSettings(byte[] plaintextPluginSettingsBytes) throws StorageException, IOException { // Find plugin ID and settings XML int pluginIdentifierLength = Ints.fromByteArray(Arrays.copyOfRange(plaintextPluginSettingsBytes, 0, INTEGER_BYTES)); String pluginId = new String(Arrays.copyOfRange(plaintextPluginSettingsBytes, INTEGER_BYTES, INTEGER_BYTES + pluginIdentifierLength)); byte[] gzippedPluginSettingsByteArray = Arrays.copyOfRange(plaintextPluginSettingsBytes, INTEGER_BYTES + pluginIdentifierLength, plaintextPluginSettingsBytes.length); String pluginSettings = IOUtils.toString(new GZIPInputStream(new ByteArrayInputStream(gzippedPluginSettingsByteArray))); // Create transfer settings object try { TransferPlugin plugin = Plugins.get(pluginId, TransferPlugin.class); if (plugin == null) { throw new StorageException("Link contains unknown connection type '" + pluginId + "'. Corresponding plugin not found."); } Class<? extends TransferSettings> pluginTransferSettingsClass = TransferPluginUtil.getTransferSettingsClass(plugin.getClass()); TransferSettings transferSettings = new Persister().read(pluginTransferSettingsClass, pluginSettings); logger.log(Level.INFO, "(Decrypted) link contains: " + pluginId + " -- " + pluginSettings); return transferSettings; } catch (Exception e) { throw new StorageException(e); } }
private List<PluginInfo> getRemotePluginInfoList() throws Exception { String remoteListStr = getRemoteListStr(null); PluginListResponse pluginListResponse = new Persister().read(PluginListResponse.class, remoteListStr); return pluginListResponse.getPlugins(); }
public static UserConfigTO load(File file) throws ConfigException { try { return new Persister(new AnnotationStrategy()).read(UserConfigTO.class, file); } catch (Exception e) { throw new ConfigException("User config file cannot be read or is invalid: " + file, e); } }
public static ConfigTO load(File file) throws ConfigException { try { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter()); registry.bind(String.class, new EncryptedTransferSettingsConverter()); return new Persister(strategy).read(ConfigTO.class, file); } catch (ClassNotFoundException ex) { // Ugly hack to catch common case of non-existing plugin String message = ex.getMessage(); if (!message.startsWith("org.syncany.plugins.")) { // Apparently there are other ClassNotFoundExceptions possible. throw new ConfigException("Config file does not exist or is invalid: " + file, ex); } message = message.replaceFirst("org.syncany.plugins.", ""); message = message.replaceAll("\\..*", ""); throw new ConfigException("Is the " + message + " plugin installed?"); } catch (Exception ex) { throw new ConfigException("Config file does not exist or is invalid: " + file, ex); } }
private UpdateOperationResult executeCheck() throws Exception { Version localAppVersion = Version.valueOf(Client.getApplicationVersion()); String appInfoResponseStr = getAppInfoResponseStr(); AppInfoResponse appInfoResponse = new Persister().read(AppInfoResponse.class, appInfoResponseStr); ArrayList<AppInfo> appInfoList = appInfoResponse.getAppInfoList(); if (appInfoList.size() > 0) { AppInfo remoteAppInfo = appInfoList.get(0); Version remoteAppVersion = Version.valueOf(remoteAppInfo.getAppVersion()); boolean newVersionAvailable = remoteAppVersion.greaterThan(localAppVersion); result.setResultCode(UpdateResultCode.OK); result.setAppInfo(remoteAppInfo); result.setNewVersionAvailable(newVersionAvailable); return result; } else { result.setResultCode(UpdateResultCode.NOK); return result; } }
public NFNota notaParaObjeto(final String xml) { try { return this.persister.read(NFNota.class, xml); } catch (final Exception e) { throw new IllegalArgumentException(String.format("Nao foi possivel parsear o xml: %s", e.getMessage())); } }
public NFNotaProcessada notaProcessadaParaObjeto(final String xml) { try { return this.persister.read(NFNotaProcessada.class, xml); } catch (final Exception e) { throw new IllegalArgumentException(String.format("Nao foi possivel parsear o xml: %s", e.getMessage())); } }
public NFNotaProcessada notaProcessadaParaObjeto(final File xml) { try { return this.persister.read(NFNotaProcessada.class, xml); } catch (final Exception e) { throw new IllegalArgumentException(String.format("Nao foi possivel parsear o xml: %s", e.getMessage())); } }
public NFEnviaEventoCancelamento enviaEventoCancelamentoParaObjeto(final File xml) { try { return this.persister.read(NFEnviaEventoCancelamento.class, xml); } catch (final Exception e) { throw new IllegalArgumentException(String.format("Nao foi possivel parsear o xml: %s", e.getMessage())); } }
public NFEnviaEventoInutilizacao enviaEventoInutilizacaoParaObjeto(final File xml) { try { return this.persister.read(NFEnviaEventoInutilizacao.class, xml); } catch (final Exception e) { throw new IllegalArgumentException(String.format("Nao foi possivel parsear o xml: %s", e.getMessage())); } }
public NFEnviaEventoCancelamento enviaEventoCancelamentoParaObjeto(final String xml) { try { return this.persister.read(NFEnviaEventoCancelamento.class, xml); } catch (final Exception e) { throw new IllegalArgumentException(String.format("Nao foi possivel parsear o xml: %s", e.getMessage())); } }
CTeConsultaRecLoteRet consultaLote(final String numeroRecibo) throws Exception { final OMElement omElementConsulta = AXIOMUtil.stringToOM(this.gerarDadosConsulta(numeroRecibo).toString()); WSRecepcaoLoteRetorno.LOGGER.info(omElementConsulta.toString()); final OMElement omElementResult = this.efetuaConsulta(omElementConsulta); WSRecepcaoLoteRetorno.LOGGER.info(omElementResult.toString()); return new Persister(new DFRegistryMatcher(), new Format(0)).read(CTeConsultaRecLoteRet.class, omElementResult.toString()); }
NFEnviaEventoRetorno corrigeNotaAssinada(final String xmlAssinado) throws Exception { final OMElement omElementResult = this.efetuaCorrecao(xmlAssinado, new DFParser() .enviaEventoCartaCorrecaoParaObjeto(xmlAssinado).getEvento().get(0).getInfoEvento().getChave()); return new Persister(new DFRegistryMatcher(), new Format(0)).read(NFEnviaEventoRetorno.class, omElementResult.toString()); }