@Override public String rewriteURL(@Nullable RuntimeIdentity identity, @Nullable String name, String url) throws InfrastructureException { if (externalIpOfContainers != null) { try { URI uri = UriBuilder.fromUri(url).host(externalIpOfContainers).build(); url = uri.toString(); } catch (UriBuilderException | IllegalArgumentException e) { throw new InternalInfrastructureException( format( "Rewriting of host '%s' in URL '%s' failed. Error: %s", externalIpOfContainers, url, e.getMessage())); } } return url; }
/** * Returns a Rest client configured with the specified properties. * * @param path * : path where the client is going to connect (e.g. * /infrastructures/asdalk-asd34/vms) * @param parameters * : extra parameters for the call (if needed) * @return : REST client */ public Builder configureClient(final String path, final RestParameter... parameters) throws ImClientException { try { WebTarget webtarget = getClient() .target(UriBuilder.fromUri(getTargetUrl()).build()).path(path); if (parameters != null && parameters.length > 0 && parameters[0] != null) { for (RestParameter parameter : parameters) { webtarget.queryParam(parameter.getName(), parameter.getValues()); } } return webtarget.request(MediaType.APPLICATION_JSON) .header(AUTH_HEADER_TAG, getParsedAuthFile()); } catch (IllegalArgumentException | UriBuilderException exception) { ImJavaApiLogger.severe(this.getClass(), exception); throw exception; } }
/** * @param baseUri * * @return * * @throws UnsupportedEncodingException * @throws UriBuilderException * @throws IllegalArgumentException */ private Invocation preparePOSTInvocationBuilder(final String mimeType, final String contentType, final String query) throws IllegalArgumentException, UriBuilderException, UnsupportedEncodingException { final UriBuilder baseBuilder = UriBuilder.fromUri(HOST).port(PORT); final URI targetUri = baseBuilder.path(QueryExecutor.ENDPOINT_NAME).build(); final Client client = ClientBuilder.newClient(); final WebTarget resourceTarget = client.target(targetUri); final Builder invocationBuilder = resourceTarget.request(mimeType); final Entity<String> entity = Entity.entity(query, Variant.mediaTypes(MediaType.valueOf(contentType)) .encodings("UTF-8") .build() .get(0), null); final Invocation invocation = invocationBuilder.buildPost(entity); return invocation; }
/** * Test http://dev.gbif.org/issues/browse/POR-2688 * We expect a client handler or uniform interface exception cause we did not setup the entire jersey stack properly. * We only want to make sure there is no UriBuilderException thrown */ @Test public void testCurlyBrackets() { try { WebResource api = Client.create().resource("http://api.gbif.org/v1/species/match"); WebResource q = api.queryParam("name", "Nereis southerni %7B%7Bnowrap Abdel-Moez & Humphries, 1955"); assertEquals( "http://api.gbif.org/v1/species/match?name=Nereis+southerni+%7B%7Bnowrap+Abdel-Moez+%26+Humphries,+1955", q.toString()); NameUsageMatchWsClient client = new NameUsageMatchWsClient(api); client.match("Nereis southerni {{nowrap Abdel-Moez & Humphries, 1955", null, null, false, false); } catch (RuntimeException e) { if (e instanceof UriBuilderException) { throw e; } System.out.println(e.toString()); } }
@Override public void init() throws UriBuilderException, IllegalArgumentException { testCOPY = false; Command com = new Command(); com.setName("Reaction Command"); com.setHardwareLevel(false); Trigger t = new Trigger(); t.setName("Reaction trigger"); Trigger t2 = new Trigger(); t2.setName("Second Trigger"); getApi().triggers().create(t); getApi().triggers().create(t2); getApi().commands().create(com); Reaction r = new Reaction(t, com); setItem(new ReactionRepresentation(r)); initPath(ReactionResource.class); setListType(new GenericType<List<ReactionRepresentation>>(){}); setSingleType(new GenericType<ReactionRepresentation>(){}); }
@Override public void init() throws UriBuilderException, IllegalArgumentException { setItem(new Zone()); getItem().setName("Test Zone"); getItem().setAsRoom(true); getItem().setDescription("Before editing"); e.setName("Test env for zone"); e.setUUID(getUuid()); el.setPojo(e); el.init(); getApi().environments().create(el); initPath(UriBuilder.fromResource(EnvironmentResource.class).path(e.getUUID()).path("/rooms").build().toString()); setListType(new GenericType<List<Zone>>(){}); setSingleType(new GenericType<Zone>(){}); }
private String getCallbackUri() throws UriBuilderException, IllegalArgumentException { return uriInfo.getBaseUriBuilder() .path("auth") .path("callback") .build() .toASCIIString(); }
Response getResponse(boolean updated, UriInfo info) throws UriBuilderException, IllegalArgumentException { if (updated) { return Response. noContent(). build(); } else { URI uri = info.getAbsolutePathBuilder(). build(); return Response. created(uri). build(); } }
private URI createURI(String uri) { try { return new URI(uri); } catch (URISyntaxException ex) { throw new UriBuilderException(ex); } }
private HttpServer createHttpServer() throws IOException, IllegalArgumentException, UriBuilderException, URISyntaxException { ResourceConfig resourceConfig = new ResourceConfig() .packages(true, Configuration.instance().getStrings("APP.Jersey.Resources").toArray(new String[0])) .register(FrontendFeature.class); EncodingFilter.enableFor(resourceConfig, GZipEncoder.class); return GrizzlyHttpServerFactory.createHttpServer(getURI(), resourceConfig, false); }
@Override public URI build(Object... values) throws IllegalArgumentException, UriBuilderException { String url = null; try { url = new Formatter().format(_pathFormat, values).toString(); } catch (Exception ex) { throw new UriBuilderException("Problem building url from format[" + _pathFormat + "] and values[" + values + "]", ex); } return URI.create(url); }
@Override public URI buildFromMap(Map<String, ?> values, boolean encodeSlashInPath) throws IllegalArgumentException, UriBuilderException { return rewrite(wrapped.buildFromEncoded(values, encodeSlashInPath)); }
/** * @param baseUri * * @return * * @throws UnsupportedEncodingException * @throws UriBuilderException * @throws IllegalArgumentException */ private Invocation prepareGETInvocationBuilder(final String mimeType, final String query) throws IllegalArgumentException, UriBuilderException, UnsupportedEncodingException { final UriBuilder baseBuilder = UriBuilder.fromUri(HOST).port(PORT); final URI targetUri = baseBuilder.path(QueryExecutor.ENDPOINT_NAME) .queryParam(QUERY_PARAM, URLEncoder.encode(query, "UTF-8").replace("+", "%20")).build(); final Client client = ClientBuilder.newClient(); final WebTarget resourceTarget = client.target(targetUri); final Builder invocationBuilder = resourceTarget.request(mimeType); final Invocation invocation = invocationBuilder.buildGet(); return invocation; }
/** * @throws IllegalMimeTypeException * @throws UnsupportedEncodingException * @throws UriBuilderException * @throws IllegalArgumentException */ @Test public void testQueryExecutionSuccessfulGET() throws IllegalMimeTypeException, IllegalArgumentException, UriBuilderException, UnsupportedEncodingException { testSuccessfulMethod(Method.GET); }
/** * @throws IllegalMimeTypeException * @throws UnsupportedEncodingException * @throws UriBuilderException * @throws IllegalArgumentException */ @Test public void testQueryExecutionSuccessfulURLPOST() throws IllegalMimeTypeException, IllegalArgumentException, UriBuilderException, UnsupportedEncodingException { testSuccessfulMethod(Method.URL_ENCODED_POST); }
/** * @throws IllegalMimeTypeException * @throws UnsupportedEncodingException * @throws UriBuilderException * @throws IllegalArgumentException */ @Test public void testQueryExecutionSuccessfulDirectPOST() throws IllegalMimeTypeException, IllegalArgumentException, UriBuilderException, UnsupportedEncodingException { testSuccessfulMethod(Method.DIRECT_POST); }
/** * @throws IllegalMimeTypeException * @throws UnsupportedEncodingException * @throws UriBuilderException * @throws IllegalArgumentException */ @Test public void testQueryExecutionInvalidFormatOnGET() throws IllegalMimeTypeException, IllegalArgumentException, UriBuilderException, UnsupportedEncodingException { testUnsuccessfulMethod(Method.GET, QueryExecutor.INVALID_FORMAT_STATUS_CODE); }
/** * @throws IllegalMimeTypeException * @throws UnsupportedEncodingException * @throws UriBuilderException * @throws IllegalArgumentException */ @Test public void testQueryExecutionInvalidFormatURLPOST() throws IllegalMimeTypeException, IllegalArgumentException, UriBuilderException, UnsupportedEncodingException { testUnsuccessfulMethod(Method.URL_ENCODED_POST, QueryExecutor.INVALID_FORMAT_STATUS_CODE); }
/** * @throws IllegalMimeTypeException * @throws UnsupportedEncodingException * @throws UriBuilderException * @throws IllegalArgumentException */ @Test public void testQueryExecutionInvalidFormatDirectPOST() throws IllegalMimeTypeException, IllegalArgumentException, UriBuilderException, UnsupportedEncodingException { testUnsuccessfulMethod(Method.DIRECT_POST, QueryExecutor.INVALID_FORMAT_STATUS_CODE); }
/** * @throws IllegalMimeTypeException * @throws UnsupportedEncodingException * @throws UriBuilderException * @throws IllegalArgumentException */ //@Test public void testQueryExecutionQuerySyntaxErrorOnGET() throws IllegalMimeTypeException, IllegalArgumentException, UriBuilderException, UnsupportedEncodingException { testInvalidQueryMethod(Method.GET); }
/** * @throws IllegalMimeTypeException * @throws UnsupportedEncodingException * @throws UriBuilderException * @throws IllegalArgumentException */ //@Test public void testQueryExecutionQuerySyntaxErrorURLPOST() throws IllegalMimeTypeException, IllegalArgumentException, UriBuilderException, UnsupportedEncodingException { testInvalidQueryMethod(Method.URL_ENCODED_POST); }
/** * @throws IllegalMimeTypeException * @throws UnsupportedEncodingException * @throws UriBuilderException * @throws IllegalArgumentException */ //@Test public void testQueryExecutionQuerySyntaxErrorDirectPOST() throws IllegalMimeTypeException, IllegalArgumentException, UriBuilderException, UnsupportedEncodingException { testInvalidQueryMethod(Method.DIRECT_POST); }
/** * Returns the resource formatted as json * * @return JSONObject * @throws JSONException */ @SuppressWarnings("unchecked") public JSONObject asJson() throws JSONException { JSONObject messagesAsJson = super.asJson(); // fill data JSONArray queuesArray = new JSONArray(); List<?> items = getItems(); if (items.size() > 0) { if (null != queueEntity){ for (Object[] messageEntity : (List<Object[]>) items) { try { queuesArray.put(GroupMessageResource.asJson( messageEntity, isMessageInQueue, needsPayload,UriBuilder.fromPath(getUriInfo().getPath()) .path(messageEntity[0].toString()).build() .getPath())); } catch (IllegalArgumentException | UriBuilderException | ParseException e) { // TODO Auto-generated catch block } } } } messagesAsJson.put("groupmessages", queuesArray); return messagesAsJson; }
private static URI stringToUri(String string) throws ConfigErrorException { try { return UriBuilder.fromUri(string).build(); } catch ( IllegalArgumentException | UriBuilderException e ) { throw new ConfigErrorException(string + " is not a valid URI."); } }
URI getAuthorizationUri(Scope... scopes) { checkState(!Strings.isNullOrEmpty(clientRedirectUri), "Can't create the login uri: redirect URI was not set."); try { String formattedScopes = getScopesAsString(scopes); return UriBuilder.fromUri(endpoint).path("/oauth/authorize") .queryParam("client_id", clientId) .queryParam("response_type", "code") .queryParam("redirect_uri", clientRedirectUri) .queryParam("scope", formattedScopes) .build(); } catch (UriBuilderException | IllegalArgumentException e) { throw new OsiamClientException("Unable to create redirect URI", e); } }
private static String checkInteractionModel(final List<String> links) { if (links == null) { return null; } try { for (String link : links) { final Link linq = Link.valueOf(link); if ("type".equals(linq.getRel())) { final Resource type = createResource(linq.getUri().toString()); if (type.equals(NON_RDF_SOURCE) || type.equals(BASIC_CONTAINER) || type.equals(DIRECT_CONTAINER) || type.equals(INDIRECT_CONTAINER)) { return "ldp:" + type.getLocalName(); } else { LOGGER.info("Invalid interaction model: {}", type); throw new CannotCreateResourceException("Invalid interaction model: " + type); } } } } catch (final RuntimeException e) { if (e instanceof IllegalArgumentException | e instanceof UriBuilderException) { throw new ClientErrorException("Invalid link specified: " + String.join(", ", links), BAD_REQUEST); } throw e; } return null; }
@GET @Path("/") @Produces(MediaType.APPLICATION_JSON) public Response getStatisticsIndex(@Context final UriInfo uriInfo) throws IllegalArgumentException, UriBuilderException, JSONException { final JSONObject result = new JSONObject(); result.put(MAX_RESULTS_PATH, uriInfo.getBaseUriBuilder().path(Settings.class).path(MAX_RESULTS_PATH).build()); result.put(PAGE_REFRESH_PATH, uriInfo.getBaseUriBuilder().path(Settings.class).path(PAGE_REFRESH_PATH).build()); return Response.ok(result.toString()).build(); }
@Override public void init() throws UriBuilderException, IllegalArgumentException { setItem(new Command()); getItem().setName("TestCmd"); getItem().setUUID(getUuid()); getItem().setProperty("prop1", "value1"); getItem().setReceiver("receiver.channel"); getItem().setHardwareLevel(true); initPath(HardwareCommandResource.class); setListType(new GenericType<List<Command>>() { }); setSingleType(new GenericType<Command>() { }); }
@Override public void init() throws UriBuilderException, IllegalArgumentException { setItem(new Command()); getItem().setName("TestCmd"); getItem().setUUID(getUuid()); getItem().setProperty("prop1", "value1"); getItem().setReceiver("receiver.channel"); initPath(UserCommandResource.class); setListType(new GenericType<List<Command>>(){}); setSingleType(new GenericType<Command>(){}); }
@Override void init() throws UriBuilderException, IllegalArgumentException { setItem(role); getItem().setName("TestRole"); getItem().getPermissions().add("read:*"); initPath(RoleResource.class); setListType(new GenericType<List<RoleRepresentation>>(){}); setSingleType(new GenericType<RoleRepresentation>(){}); }
@Override public void init() throws UriBuilderException, IllegalArgumentException { e.setName("Test env for zone"); e.setUUID(getUuid()); el.setPojo(e); el.init(); getApi().environments().create(el); setItem(obj); getItem().setName("TestObject"); getItem().setUUID(getUuid()); getItem().setHierarchy("com.freedomotic.things.impl.ElectricDevice"); getItem().setType("EnvObject.ElectricDevice"); getItem().setEnvironmentID(e.getUUID()); Representation r = new Representation(); r.setOffset(0, 0); r.setTangible(true); FreedomPolygon s = new FreedomPolygon(); s.append(0, 0); s.append(0, 1); s.append(1, 1); s.append(1, 0); r.setShape(s); getItem().getRepresentations().add(r); getItem().setCurrentRepresentation(0); BooleanBehavior b = new BooleanBehavior(); b.setName("powered"); b.setValue(true); getItem().getBehaviors().add(b); initPath(ThingResource.class); setListType(new GenericType<List<EnvObject>>() { }); setSingleType(new GenericType<EnvObject>() { }); }
@Override public void init() throws UriBuilderException, IllegalArgumentException { setItem(new Trigger()); getItem().setName("TestTrg"); getItem().setUUID(getUuid()); getItem().setChannel("test.trigger.channel"); initPath(TriggerResource.class); setListType(new GenericType<List<Trigger>>() { }); setSingleType(new GenericType<Trigger>() { }); }
@Override public void init() throws UriBuilderException, IllegalArgumentException { setItem(env); getItem().setName("TestEnv"); getItem().setUUID(getUuid()); initPath(EnvironmentResource.class); setListType(new GenericType<List<Environment>>(){}); setSingleType(new GenericType<Environment>(){}); }
@Override void init() throws UriBuilderException, IllegalArgumentException { SimpleRole r = new SimpleRole(); r.setName("admin"); r.add(new WildcardPermission("*")); getApi().getAuth().addRole(r); User u = new User("user","password","admin",getApi().getAuth()); setItem(new UserRepresentation(u)); initPath(UserResource.class); setListType(new GenericType<List<UserRepresentation>>(){}); setSingleType(new GenericType<UserRepresentation>(){}); testDELETE = false; }
@Override public Iterable<ListBlobItem> listBlobs(String prefix, boolean useFlatBlobListing, EnumSet<BlobListingDetails> listingDetails, BlobRequestOptions options, OperationContext opContext) throws URISyntaxException, StorageException { ArrayList<ListBlobItem> ret = new ArrayList<ListBlobItem>(); URI searchUri = null; if (prefix == null) { searchUri = uri; } else { try { searchUri = UriBuilder.fromUri(uri).path(prefix).build(); } catch (UriBuilderException e) { throw new AssertionError("Failed to encode path: " + prefix); } } String fullPrefix = convertUriToDecodedString(searchUri); boolean includeMetadata = listingDetails.contains(BlobListingDetails.METADATA); HashSet<String> addedDirectories = new HashSet<String>(); for (InMemoryBlockBlobStore.ListBlobEntry current : backingStore.listBlobs( fullPrefix, includeMetadata)) { int indexOfSlash = current.getKey().indexOf('/', fullPrefix.length()); if (useFlatBlobListing || indexOfSlash < 0) { if (current.isPageBlob()) { ret.add(new MockCloudPageBlobWrapper( convertKeyToEncodedUri(current.getKey()), current.getMetadata(), current.getContentLength())); } else { ret.add(new MockCloudBlockBlobWrapper( convertKeyToEncodedUri(current.getKey()), current.getMetadata(), current.getContentLength())); } } else { String directoryName = current.getKey().substring(0, indexOfSlash); if (!addedDirectories.contains(directoryName)) { addedDirectories.add(current.getKey()); ret.add(new MockCloudBlobDirectoryWrapper(new URI( directoryName + "/"))); } } } return ret; }
private HALLink createResourceLink(URI uri) throws IllegalArgumentException, UriBuilderException { return (new dk.nykredit.jackson.dataformat.hal.HALLink.Builder(uri)).title("Link to failed resource").build(); }
Form Locate(String componentName, String version, String descriptiveData, String contextParticipant, UriInfo uriInfo) throws UnableToLocateException, UnknownPropertyNameException, BadPropertyValueException, MalformedURLException, IllegalArgumentException, UriBuilderException;
@Override public URI buildFromEncodedMap(Map<String, ?> values) throws IllegalArgumentException, UriBuilderException { // EMODB-MODIFICATION: Templates are not supported, so buildFromMap is not supported throw new UnsupportedOperationException("Templates not supported"); }