本文整理汇总了Java中org.glassfish.jersey.uri.UriComponent类的典型用法代码示例。如果您正苦于以下问题:Java UriComponent类的具体用法?Java UriComponent怎么用?Java UriComponent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UriComponent类属于org.glassfish.jersey.uri包,在下文中一共展示了UriComponent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createWebTarget
import org.glassfish.jersey.uri.UriComponent; //导入依赖的package包/类
private static WebTarget createWebTarget(String uri, Map<String, String> queryParams) throws URISyntaxException
{
WebTarget webTarget = null;
URI u = new URI(uri);
Client client = ClientBuilder.newClient();
webTarget = client.target(u);
if (MapUtils.isNotEmpty(queryParams))
{
for (Entry<String, String> entry : queryParams.entrySet())
{
if (StringUtils.isNotBlank(entry.getKey()) && StringUtils.isNotBlank(entry.getValue()))
{
String value = UriComponent.encode(
entry.getValue(),
UriComponent.Type.QUERY_PARAM_SPACE_ENCODED);
webTarget = webTarget.queryParam(entry.getKey(), value);
}
}
}
return webTarget;
}
示例2: testIdentifierPrefix
import org.glassfish.jersey.uri.UriComponent; //导入依赖的package包/类
@Test
public void testIdentifierPrefix() throws Exception {
String url = "http://arXiv.org/oai2";
String metadataPrefix = "marc21";
String identifierPrefix = "oai:arXiv.org:quant-ph/";
OaiCatalog c = new OaiCatalog(url, metadataPrefix, identifierPrefix);
WebTarget wr = c.buildOaiQuery(OaiCatalog.FIELD_ID, "4");
String resultQuery = wr.getUri().toString();
String encIdParam = "identifier=" + UriComponent.encode(
"oai:arXiv.org:quant-ph/4",
UriComponent.Type.QUERY_PARAM_SPACE_ENCODED);
assertTrue(resultQuery, resultQuery.contains(encIdParam));
// do not prefix ID with prefix
wr = c.buildOaiQuery(OaiCatalog.FIELD_ID, "oai:arXiv.org:quant-ph/4");
resultQuery = wr.getUri().toString();
assertTrue(resultQuery, resultQuery.contains(encIdParam));
// no prefix
c.setIdentifierPrefix(null);
wr = c.buildOaiQuery(OaiCatalog.FIELD_ID, "4");
resultQuery = wr.getUri().toString();
assertTrue(resultQuery, resultQuery.contains("identifier=4"));
}
示例3: makeSlug
import org.glassfish.jersey.uri.UriComponent; //导入依赖的package包/类
/** Apply slug conventions. In practice, this means
* (a) replacing punctuation with hyphens,
* (b) replacing whitespace with hyphen,
* (c) converting to lowercase,
* (d) encoding as a URL,
* (e) replacing percents with hyphens,
* (f) coalescing multiple consecutive hyphens into one,
* (g) removing any leading and trailing hyphens,
* (h) trimming the result to a maximum length of
* MAX_SLUG_COMPONENT_LENGTH,
* (i) removing any remaining trailing hyphen.
* @param aString The string that is to be converted.
* @return The value of aString with slug conventions applied.
*/
public static String makeSlug(final String aString) {
String slug = StringUtils.strip(
UriComponent.encode(aString.
replaceAll("\\p{Punct}", "-").
replaceAll("\\s", "-").
toLowerCase(),
UriComponent.Type.PATH_SEGMENT).
replaceAll("%", "-").
replaceAll("-+", "-"),
"-");
return StringUtils.stripEnd(
slug.substring(0, Math.min(MAX_SLUG_COMPONENT_LENGTH,
slug.length())),
"-");
}
示例4: query
import org.glassfish.jersey.uri.UriComponent; //导入依赖的package包/类
/**
* Query prometheus and return the result
*
* @param expression
* @return
* @throws PrometheusException
*/
public PrometheusResponse query(String expression) throws PrometheusException
{
WebTarget queryTarget = target.queryParam(
"expr",
UriComponent.encode(expression, UriComponent.Type.QUERY_PARAM_SPACE_ENCODED)
);
logger.debug(expression);
String json = queryTarget.request().get(String.class);
PrometheusResponse response = gson.fromJson(json, PrometheusResponse.class);
if (response instanceof PrometheusError) {
throw new PrometheusQueryException(expression, ((PrometheusError) response).getError());
}
return response;
}
示例5: getBatchToken
import org.glassfish.jersey.uri.UriComponent; //导入依赖的package包/类
public String getBatchToken() {
Link link = this.response.getLink("'next'");
if (link != null) {
MultivaluedMap<String, String> parameters = UriComponent.decodeQuery(link.getUri(), true);
return parameters.getFirst("batch_token");
}
return null;
}
示例6: getByEmail
import org.glassfish.jersey.uri.UriComponent; //导入依赖的package包/类
@Override
public Optional<User> getByEmail(String userEmail) {
String userEmailEncoded = UriComponent.encode(userEmail, QUERY_PARAM_SPACE_ENCODED);
Invocation.Builder builder = client
.target(USERS_URL)
.queryParam("filter[email]", userEmailEncoded)
.request(APPLICATION_JSON_TYPE);
return getPageable(builder, UserList.class)
.filter(user -> user.getEmail().equals(userEmail))
.getSingle();
}
示例7: getByName
import org.glassfish.jersey.uri.UriComponent; //导入依赖的package包/类
@Override
public Optional<Server> getByName(String serverName) {
String serverNameEncoded = UriComponent.encode(serverName, QUERY_PARAM_SPACE_ENCODED);
Invocation.Builder builder = client
.target(SERVERS_URL)
.queryParam("filter[name]", serverNameEncoded)
.request(APPLICATION_JSON_TYPE);
return getPageable(builder, ServerList.class)
.filter(application -> application.getName().equals(serverName))
.getSingle();
}
示例8: getByName
import org.glassfish.jersey.uri.UriComponent; //导入依赖的package包/类
@Override
public Optional<KeyTransaction> getByName(String keyTransactionName) {
String keyTransactionNameEncoded = UriComponent.encode(keyTransactionName, QUERY_PARAM_SPACE_ENCODED);
return client
.target(KEY_TRANSACTIONS_URL)
.queryParam("filter[name]", keyTransactionNameEncoded)
.request(APPLICATION_JSON_TYPE)
.get(KeyTransactionList.class)
.getSingle();
}
示例9: _createContext
import org.glassfish.jersey.uri.UriComponent; //导入依赖的package包/类
@Nonnull
private static WebappContext _createContext (final URI u,
final Class <? extends Servlet> aServletClass,
final Servlet aServlet,
final Map <String, String> aInitParams,
final Map <String, String> aContextInitParams)
{
String path = u.getPath ();
if (path == null)
throw new IllegalArgumentException ("The URI path, of the URI " + u + ", must be non-null");
if (path.isEmpty ())
throw new IllegalArgumentException ("The URI path, of the URI " + u + ", must be present");
if (path.charAt (0) != '/')
throw new IllegalArgumentException ("The URI path, of the URI " + u + ". must start with a '/'");
path = String.format ("/%s", UriComponent.decodePath (u.getPath (), true).get (1).toString ());
final WebappContext aContext = new WebappContext ("GrizzlyContext", path);
ServletRegistration registration;
if (aServletClass != null)
registration = aContext.addServlet (aServletClass.getName (), aServletClass);
else
registration = aContext.addServlet (aServlet.getClass ().getName (), aServlet);
registration.addMapping ("/*");
if (aContextInitParams != null)
for (final Map.Entry <String, String> e : aContextInitParams.entrySet ())
aContext.setInitParameter (e.getKey (), e.getValue ());
if (aInitParams != null)
registration.setInitParameters (aInitParams);
return aContext;
}
示例10: qpEncode
import org.glassfish.jersey.uri.UriComponent; //导入依赖的package包/类
/**
* Encodes query parameter as Jersey 2 uses query templates by default.
*/
private static String qpEncode(String p) {
return p == null || p.isEmpty()
? p
: UriComponent.encode(p, UriComponent.Type.QUERY_PARAM_SPACE_ENCODED);
}
示例11: make
import org.glassfish.jersey.uri.UriComponent; //导入依赖的package包/类
public Command make(Operation operation, String target, String parameters) {
return make(operation, target, UriComponent.decodeQuery(parameters, true));
}
示例12: makeParams
import org.glassfish.jersey.uri.UriComponent; //导入依赖的package包/类
private MultivaluedMap<String, String> makeParams(String params) {
return UriComponent.decodeQuery(params, true);
}
示例13: encode
import org.glassfish.jersey.uri.UriComponent; //导入依赖的package包/类
private String encode(final String input) {
// do not interpret template parameters
return UriComponent.encode(input, UriComponent.Type.QUERY_PARAM, false);
}
示例14: encodeQueryParam
import org.glassfish.jersey.uri.UriComponent; //导入依赖的package包/类
private static String encodeQueryParam(final String value) {
return UriComponent.encode(value, UriComponent.Type.QUERY_PARAM, false);
}
示例15: getEscapedUri
import org.glassfish.jersey.uri.UriComponent; //导入依赖的package包/类
/**
* Return the string representation of a URI when it is to be used when generating the URL for a request.
* @param uriToEscape - the URI that is to be escaped
* @return - the URI supplied encoded so that it can be used as part of a URL
*/
protected String getEscapedUri(String uriToEscape) {
return UriComponent.encode(uriToEscape, UriComponent.Type.PATH_SEGMENT);
}