@Override public void kill(DataSegment segment) throws SegmentLoadingException { log.info("Killing segment [%s]", segment); Map<String, Object> loadSpec = segment.getLoadSpec(); final String containerName = MapUtils.getString(loadSpec, "containerName"); final String blobPath = MapUtils.getString(loadSpec, "blobPath"); final String dirPath = Paths.get(blobPath).getParent().toString(); try { azureStorage.emptyCloudBlobDirectory(containerName, dirPath); } catch (StorageException e) { Object extendedInfo = e.getExtendedErrorInformation() == null ? null : e.getExtendedErrorInformation().getErrorMessage(); throw new SegmentLoadingException(e, "Couldn't kill segment[%s]: [%s]", segment.getId(), extendedInfo); } catch (URISyntaxException e) { throw new SegmentLoadingException(e, "Couldn't kill segment[%s]: [%s]", segment.getId(), e.getReason()); } }
private J4pException mapException(Exception pException) throws J4pException { if (pException instanceof ConnectException) { return new J4pConnectException( "Cannot connect to " + requestHandler.getJ4pServerUrl() + ": " + pException.getMessage(), (ConnectException) pException); } else if (pException instanceof ConnectTimeoutException) { return new J4pTimeoutException( "Read timeout while request " + requestHandler.getJ4pServerUrl() + ": " + pException.getMessage(), (ConnectTimeoutException) pException); } else if (pException instanceof IOException) { return new J4pException("IO-Error while contacting the server: " + pException,pException); } else if (pException instanceof URISyntaxException) { URISyntaxException sExp = (URISyntaxException) pException; return new J4pException("Invalid URI " + sExp.getInput() + ": " + sExp.getReason(),pException); } else { return new J4pException("Exception " + pException,pException); } }
public static URI uncheckedToUri(final String uri) { try { return new URI(uri); } catch (URISyntaxException e) { throw new RuntimeException(String.format("Failed to convert %s to URI (%s)", uri, e.getReason()), e); } }
/** * ONLY to be used if the caller is <strong>certain</strong> that the supplied String is a valid URI. */ public static URI uncheckedCreate(final String uri) { try { return new URI(uri); } catch (URISyntaxException e) { throw new RuntimeException(String.format("%s is not a valid URI (%s)", uri, e.getReason()), e); } }
/** * ONLY to be used if the caller is <strong>certain</strong> that the supplied String is a valid URI. */ public static URI uncheckedCreate(final String uri) { try { return new URI(uri); } catch (URISyntaxException e) { throw new RuntimeException(String.format("%s is not a valid URI (%s)", uri, e.getReason()), e); } } /**
/** * @param uri URI string * @return new URI * @deprecated use {@link URI#create(String)} instead */ @Deprecated @Nonnull public static URI uncheckedToUri(final String uri) { try { return new URI(uri); } catch (URISyntaxException e) { throw new RuntimeException(String.format("Failed to convert %s to URI (%s)", uri, e.getReason()), e); } }
/** * ONLY to be used if the caller is <strong>certain</strong> that the base and path will form a valid URI when concatenated. */ public static URI uncheckedConcatenate(final URI base, final String... paths) { try { return concatenate(base, paths); } catch (URISyntaxException e) { throw new RuntimeException(String.format("Failed to concatenate %s to form URI (%s)", base, e.getReason()), e); } }
private URI getUri(final String key) { final String uri = (String) applinksAdminPropertySet.getProperty(key); if (uri == null) { return null; } try { return new URI(uri); } catch (URISyntaxException e) { // this will only happen if someone has manually hacked up the property store, and set an invalid URI throw new RuntimeException(String.format("Failed to deserialise stored %s URI (%s) reason: %s", key, uri, e.getReason())); } }
/** * ONLY to be used if the caller is <strong>certain</strong> that the base and path will form a valid URI when * concatenated. * * @param base base * @param paths paths * @return concatenated URI * @deprecated use {@link Uris#uncheckedConcatenate(URI, String...)} instead */ public static URI uncheckedConcatenate(final URI base, final String... paths) { try { return concatenate(base, paths); } catch (URISyntaxException e) { throw new RuntimeException(String.format("Failed to concatenate %s to form URI (%s)", base, e.getReason()), e); } }
/** * A variant of {@link #concatenate(String, String...)} that expects the resulting URI to be a valid URI, and * throws {@code IllegalArgumentException} otherwise. NOTE: this should only be used if the caller is * <strong>certain</strong> that the base and path will form a valid URI when concatenated. * * @param base base URI * @param components components to add * @return concatenated URI */ public static URI uncheckedConcatenate(final URI base, final String... components) throws IllegalArgumentException { try { return concatenate(base, components); } catch (URISyntaxException e) { throw new IllegalArgumentException(format("Failed to concatenate %s to form URI (%s)", base, e.getReason()), e); } }
public static URI buildSafeUri(String uri) throws URISyntaxException { try { return new URI(uri); } catch (URISyntaxException e) { String encodedInput = URLEncode(e.getInput()); throw new URISyntaxException(encodedInput, e.getReason()); } }
public static URI buildSafeUri(String scheme, String userInfo, String host, int port, String path, String query, String fragment) throws URISyntaxException { try { return new URI(scheme, userInfo, host, port, path, query, fragment); } catch (URISyntaxException e) { String encodedInput = URLEncode(e.getInput()); throw new URISyntaxException(encodedInput, e.getReason()); } }
private void validateSegment(String uri, String segment, int index, String legal) throws URISyntaxException { try { URIEncoderDecoder.validate(segment, legal); //$NON-NLS-1$ } catch (URISyntaxException e) { throw new URISyntaxException(uri, Messages.getString("luni.88", e.getReason()), index + e.getIndex()); } } private void validateQuery(String uri, String query, int index) throws URISyntaxException {
private void validateQuery(String uri, String query, int index) throws URISyntaxException { try { URIEncoderDecoder.validate(query, Uri.queryFragLegal); } catch (URISyntaxException e) { throw new URISyntaxException(uri, Messages.getString("luni.89", e.getReason()), index + e.getIndex()); } }
private void validateFragment(String uri, String fragment, int index) throws URISyntaxException { try { URIEncoderDecoder.validate(fragment, Uri.queryFragLegal); } catch (URISyntaxException e) { throw new URISyntaxException(uri, Messages.getString("luni.8A", e.getReason()), index + e.getIndex()); } }
private void validateUserinfo(String uri, String userinfo, int index) throws URISyntaxException { try { URIEncoderDecoder.validate(userinfo, Uri.userinfoLegal); //$NON-NLS-1$ } catch (URISyntaxException e) { throw new URISyntaxException(uri, Messages.getString("luni.8C", e.getReason()), index + e.getIndex()); } }
private void validateSsp(String uri, String ssp, int index) throws URISyntaxException { try { URIEncoderDecoder.validate(ssp, Uri.allLegalUnescaped); } catch (URISyntaxException e) { throw new URISyntaxException(uri, Messages.getString("luni.86", e.getReason()), index + e.getIndex()); } }
private void handleURISyntaxException(URISyntaxException e) { int actualIndex = e.getIndex(); String fullURI = e.getInput(); int indexFromRHS = fullURI.length()-actualIndex; int relativeIndex = getEntityName().length() - indexFromRHS; textField.setSelectionStart(relativeIndex); textField.setSelectionEnd(getEntityName().length()); displayWarningMessage("Invalid name: " + e.getReason()); }
private OWLOntologyID createOWLOntologyIDFromView() { try { ontologyIRIField.clearErrorMessage(); ontologyIRIField.clearErrorLocation(); String ontologyIRIString = ontologyIRIField.getText().trim(); if (ontologyIRIString.isEmpty()) { return new OWLOntologyID(); } URI ontURI = new URI(ontologyIRIString); IRI ontologyIRI = IRI.create(ontURI); String versionIRIString = ontologyVersionIRIField.getText().trim(); if (versionIRIString.isEmpty()) { return new OWLOntologyID(Optional.of(ontologyIRI), Optional.<IRI>absent()); } URI verURI = new URI(versionIRIString); IRI versionIRI = IRI.create(verURI); return new OWLOntologyID(Optional.of(ontologyIRI), Optional.of(versionIRI)); } catch (URISyntaxException e) { ontologyIRIField.setErrorMessage(e.getReason()); ontologyIRIField.setErrorLocation(e.getIndex()); return null; } }
@Override public void kill(DataSegment segment) throws SegmentLoadingException { log.info("Killing segment [%s]", segment); Map<String, Object> loadSpec = segment.getLoadSpec(); final String containerName = MapUtils.getString(loadSpec, "containerName"); final String blobPath = MapUtils.getString(loadSpec, "blobPath"); final String dirPath = Paths.get(blobPath).getParent().toString(); try { azureStorage.emptyCloudBlobDirectory(containerName, dirPath); } catch(StorageException e){ throw new SegmentLoadingException(e, "Couldn't kill segment[%s]: [%s]", segment.getIdentifier(), e.getExtendedErrorInformation() == null ? null : e.getExtendedErrorInformation().getErrorMessage()); } catch (URISyntaxException e) { throw new SegmentLoadingException(e, "Couldn't kill segment[%s]: [%s]", segment.getIdentifier(), e.getReason()); } }