本文整理汇总了Java中org.glassfish.jersey.uri.UriTemplate类的典型用法代码示例。如果您正苦于以下问题:Java UriTemplate类的具体用法?Java UriTemplate怎么用?Java UriTemplate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UriTemplate类属于org.glassfish.jersey.uri包,在下文中一共展示了UriTemplate类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: parse
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
@Override
protected String parse(String input) {
String output = input;
if (pattern != null && template != null) {
UriTemplate uriTemplatePattern = new UriTemplate(pattern);
Map<String, String> map = new HashMap<>();
if (uriTemplatePattern.match(input, map)) {
UriTemplate replacement = new UriTemplate(template);
output = replacement.createURI(map);
} else {
LOG.debug("Pattern {} not matched with value {}", pattern, input);
}
}
return output;
}
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:19,代码来源:UriParameterMapper.java
示例2: resolveQueryParams
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
@SneakyThrows
private WebTarget resolveQueryParams(WebTarget target, SchemaLink link, String method) {
UriTemplate uriTemplate = link.getHref();
if (method.equalsIgnoreCase("get") && requestObject != null) {
List<String> vars = uriTemplate.getTemplateVariables();
Set<Field> matchingFields = ReflectionUtils.getAllFields(requestObject.getClass(),
f -> !vars.contains(f.getName()));
for (Field field : matchingFields) {
field.setAccessible(true);
if (field.get(requestObject) != null) {
if (Collection.class.isAssignableFrom(field.getType())) {
Collection<?> value = (Collection<?>) field.get(requestObject);
String[] values = value.stream().map(Object::toString).collect(Collectors.toList())
.toArray(new String[0]);
target = target.queryParam(field.getName(), values);
} else {
target = target.queryParam(field.getName(), field.get(requestObject).toString());
}
}
}
}
return target;
}
开发者ID:Mercateo,项目名称:rest-hateoas-client,代码行数:24,代码来源:OngoingResponseImpl.java
示例3: testCallWithRelAndTemplate_to_many_parameter_for_template
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
@Test
public void testCallWithRelAndTemplate_to_many_parameter_for_template() throws Exception {
SchemaLink mockLink = mock(SchemaLink.class);
when(mockLink.getMap())
.thenReturn(Maps.asMap(Sets.newHashSet(OngoingResponseImpl.METHOD_PARAM_KEY), k -> "get"));
UriTemplate uri = new UriTemplate("http://www.mercateo.com/{id}");
when(mockLink.getHref()).thenReturn(uri);
when(jsonHyperSchema.getByRel(any())).thenReturn(Optional.of(mockLink));
when(response.readEntity(String.class)).thenReturn("");
uut = uut.withRequestObject(new StringIdBean2());
try {
uut.callWithRel("test");
Assert.fail("No IllegalStateException thrown");
} catch (IllegalStateException e) {
assertEquals(
"There is more than one field for the template variable id: [java.lang.String com.mercateo.rest.hateoas.client.impl.OngoingResponseImpl0Test$StringIdBean.id, java.lang.String com.mercateo.rest.hateoas.client.impl.OngoingResponseImpl0Test$StringIdBean2.id]",
e.getMessage());
}
}
开发者ID:Mercateo,项目名称:rest-hateoas-client,代码行数:20,代码来源:OngoingResponseImpl0Test.java
示例4: testCallWithRelAndTemplate_missing_parameter_for_template_depr
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
@Test
public void testCallWithRelAndTemplate_missing_parameter_for_template_depr() throws Exception {
SchemaLink mockLink = mock(SchemaLink.class);
when(mockLink.getMap())
.thenReturn(Maps.asMap(Sets.newHashSet(OngoingResponseImpl.METHOD_PARAM_KEY), k -> "get"));
UriTemplate uri = new UriTemplate("http://www.mercateo.com/{id}");
when(mockLink.getHref()).thenReturn(uri);
when(jsonHyperSchema.getByRel(any())).thenReturn(Optional.of(mockLink));
when(response.readEntity(String.class)).thenReturn("");
uut = uut.withRequestObject(new Object());
try {
uut.callWithRel("test");
Assert.fail("No IllegalStateException thrown");
} catch (IllegalStateException e) {
assertEquals("No field found for the template variable id", e.getMessage());
}
}
开发者ID:Mercateo,项目名称:rest-hateoas-client,代码行数:18,代码来源:OngoingResponseImpl0Test.java
示例5: testCallWithRelAndTemplate_missing_parameter_for_template
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
@Test
public void testCallWithRelAndTemplate_missing_parameter_for_template() throws Exception {
SchemaLink mockLink = mock(SchemaLink.class);
when(mockLink.getMap())
.thenReturn(Maps.asMap(Sets.newHashSet(OngoingResponseImpl.METHOD_PARAM_KEY), k -> "get"));
UriTemplate uri = new UriTemplate("http://www.mercateo.com/{id}");
when(mockLink.getHref()).thenReturn(uri);
when(jsonHyperSchema.getByRel(any())).thenReturn(Optional.of(mockLink));
when(response.readEntity(String.class)).thenReturn("");
uut = uut.withRequestObject(new Object());
try {
uut.callWithRel("test");
Assert.fail("No IllegalStateException thrown");
} catch (IllegalStateException e) {
assertEquals("No field found for the template variable id", e.getMessage());
}
}
开发者ID:Mercateo,项目名称:rest-hateoas-client,代码行数:18,代码来源:OngoingResponseImpl0Test.java
示例6: testCallListWithRel_and_withRequestObject_with_validData
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
@Test
@UseDataProvider("validData")
public void testCallListWithRel_and_withRequestObject_with_validData(String method, String url,
Object requestObject, String expected) throws Exception {
// given
SchemaLink mockLink = mock(SchemaLink.class);
when(mockLink.getMap()).thenReturn(Maps.asMap(Sets.newHashSet(
OngoingResponseImpl.METHOD_PARAM_KEY), k -> method));
UriTemplate uri = new UriTemplate(url);
when(mockLink.getHref()).thenReturn(uri);
when(jsonHyperSchema.getByRel(any())).thenReturn(Optional.of(mockLink));
when(response.readEntity(String.class)).thenReturn("");
// when
uut = uut.withRequestObject(requestObject);
uut.callWithRel("test");
// then
verify(responseBuilder).buildResponse(any(), any(), any());
verify(client).target(eq(new URI(expected)));
}
开发者ID:Mercateo,项目名称:rest-hateoas-client,代码行数:24,代码来源:OngoingResponseImpl0Test.java
示例7: testCallListWithRel_and_withRequestObject_with_erroneousData
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
@Test
@UseDataProvider("erroneousData")
public void testCallListWithRel_and_withRequestObject_with_erroneousData(String method,
String url, Object requestObject, Class<? extends Exception> expected)
throws Exception {
// given
SchemaLink mockLink = mock(SchemaLink.class);
when(mockLink.getMap()).thenReturn(Maps.asMap(Sets.newHashSet(
OngoingResponseImpl.METHOD_PARAM_KEY), k -> method));
UriTemplate uri = new UriTemplate(url);
when(mockLink.getHref()).thenReturn(uri);
when(jsonHyperSchema.getByRel(any())).thenReturn(Optional.of(mockLink));
when(response.readEntity(String.class)).thenReturn("");
try {
// when
uut = uut.withRequestObject(requestObject);
uut.callWithRel("test");
fail("expected exception " + expected);
} catch (Exception e) {
// then
assertEquals(expected, e.getClass());
}
}
开发者ID:Mercateo,项目名称:rest-hateoas-client,代码行数:27,代码来源:OngoingResponseImpl0Test.java
示例8: getTemplatePath
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
private String getTemplatePath(ExtendedUriInfo uriInfo) {
StringBuilder builder = new StringBuilder();
for (UriTemplate template : uriInfo.getMatchedTemplates()) {
List<String> variables = template.getTemplateVariables();
String[] args = new String[variables.size()];
for (int i = 0; i < args.length; i++) {
args[i] = "{" + variables.get(i) + "}";
}
String uri = template.createURI(args);
if (!uri.equals("/") && !uri.equals(""))
builder.insert(0, uri);
}
return builder.toString();
}
开发者ID:icode,项目名称:ameba,代码行数:17,代码来源:DataViewMessageBodyWriter.java
示例9: newClient
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
public String newClient(String name, String email) {
ObjectNode clientDto = resourcesDtos.clientDto(name, email);
Response response = resourcesClient.postClient(clientDto);
response.close();
assertThat(response.getStatus(), equalTo(201));
Map<String, String> params = new HashMap<>();
UriTemplate clientUriTemplate = resourcesClient.getResourcesUrls().clientUriTemplate();
assertTrue(clientUriTemplate.match(response.getHeaderString("Location"), params));
return params.get("id");
}
开发者ID:andreschaffer,项目名称:event-sourcing-cqrs-examples,代码行数:11,代码来源:StateSetup.java
示例10: newAccount
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
public String newAccount(String clientId) {
Response response = resourcesClient.postAccount(resourcesDtos.accountDto(clientId));
response.close();
assertThat(response.getStatus(), equalTo(201));
Map<String, String> params = new HashMap<>();
UriTemplate accountUriTemplate = resourcesClient.getResourcesUrls().accountUriTemplate();
assertTrue(accountUriTemplate.match(response.getHeaderString("Location"), params));
return params.get("id");
}
开发者ID:andreschaffer,项目名称:event-sourcing-cqrs-examples,代码行数:10,代码来源:StateSetup.java
示例11: newAccount
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
@Test
public void newAccount() throws Exception {
String clientId = stateSetup.newClient("John", "[email protected]");
Response response = resourcesClient.postAccount(resourcesDtos.accountDto(clientId));
response.close();
assertThat(response.getStatus(), equalTo(201));
UriTemplate accountUriTemplate = resourcesClient.getResourcesUrls().accountUriTemplate();
assertTrue(accountUriTemplate.match(response.getHeaderString("Location"), new ArrayList<>()));
}
开发者ID:andreschaffer,项目名称:event-sourcing-cqrs-examples,代码行数:10,代码来源:AccountsIT.java
示例12: newClient
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
@Test
public void newClient() throws Exception {
ObjectNode clientDto = resourcesDtos.clientDto("John", "[email protected]");
Response response = resourcesClient.postClient(clientDto);
response.close();
assertThat(response.getStatus(), equalTo(201));
UriTemplate clientUriTemplate = resourcesClient.getResourcesUrls().clientUriTemplate();
assertTrue(clientUriTemplate.match(response.getHeaderString("Location"), new ArrayList<>()));
}
开发者ID:andreschaffer,项目名称:event-sourcing-cqrs-examples,代码行数:10,代码来源:ClientsIT.java
示例13: templatedUri
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
private static String templatedUri(RequestEvent event) {
final ExtendedUriInfo uriInfo = event.getUriInfo();
final List<UriTemplate> matchedTemplates = new ArrayList<>(uriInfo.getMatchedTemplates());
if (matchedTemplates.size() > 1) {
Collections.reverse(matchedTemplates);
}
final StringBuilder sb = new StringBuilder();
sb.append(uriInfo.getBaseUri().getPath());
for (UriTemplate uriTemplate : matchedTemplates) {
sb.append(uriTemplate.getTemplate());
}
return sb.toString().replaceAll("//+", "/");
}
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:14,代码来源:DefaultJerseyTagsProvider.java
示例14: event
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
private static RequestEvent event(String method, Integer status, Exception exception,
String baseUri, String... uriTemplateStrings) {
Builder builder = new RequestEventImpl.Builder();
ContainerRequest containerRequest = mock(ContainerRequest.class);
when(containerRequest.getMethod()).thenReturn(method);
builder.setContainerRequest(containerRequest);
ContainerResponse containerResponse = mock(ContainerResponse.class);
when(containerResponse.getStatus()).thenReturn(status);
builder.setContainerResponse(containerResponse);
builder.setException(exception, null);
ExtendedUriInfo extendedUriInfo = mock(ExtendedUriInfo.class);
when(extendedUriInfo.getBaseUri()).thenReturn(
URI.create("http://localhost:8080" + (baseUri == null ? "/" : baseUri)));
List<UriTemplate> uriTemplates = uriTemplateStrings == null ? Collections.emptyList()
: Arrays.stream(uriTemplateStrings).map(uri -> new UriTemplate(uri))
.collect(Collectors.toList());
// UriTemplate are returned in reverse order
Collections.reverse(uriTemplates);
when(extendedUriInfo.getMatchedTemplates()).thenReturn(uriTemplates);
builder.setExtendedUriInfo(extendedUriInfo);
return builder.build(Type.FINISHED);
}
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:28,代码来源:DefaultJerseyTagsProviderTest.java
示例15: setHref
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
public void setHref(String href) {
if (href.contains("%7B")) {
try {
href = URLDecoder.decode(href, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
this.href = new UriTemplate(href);
}
开发者ID:Mercateo,项目名称:rest-hateoas-client,代码行数:11,代码来源:SchemaLink.java
示例16: testCallWithRelAndTemplate
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
@Test
public void testCallWithRelAndTemplate() throws Exception {
SchemaLink mockLink = mock(SchemaLink.class);
when(mockLink.getMap())
.thenReturn(Maps.asMap(Sets.newHashSet(OngoingResponseImpl.METHOD_PARAM_KEY), k -> "get"));
UriTemplate uri = new UriTemplate("http://www.mercateo.com/{id}");
when(mockLink.getHref()).thenReturn(uri);
when(jsonHyperSchema.getByRel(any())).thenReturn(Optional.of(mockLink));
when(response.readEntity(String.class)).thenReturn("");
uut = uut.withRequestObject(new StringIdBean("id1"));
uut.callWithRel("test");
verify(responseBuilder).buildResponse(any(), any(), any());
verify(client).target(eq(new URI("http://www.mercateo.com/id1")));
}
开发者ID:Mercateo,项目名称:rest-hateoas-client,代码行数:15,代码来源:OngoingResponseImpl0Test.java
示例17: testCallWithRel_badRequest
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
@Test(expected = WebApplicationException.class)
public void testCallWithRel_badRequest() throws Exception {
SchemaLink mockLink = mock(SchemaLink.class);
when(mockLink.getMap())
.thenReturn(Maps.asMap(Sets.newHashSet(OngoingResponseImpl.METHOD_PARAM_KEY), k -> "put"));
UriTemplate uri = new UriTemplate("http://www.mercateo.com/");
when(mockLink.getHref()).thenReturn(uri);
when(jsonHyperSchema.getByRel(any())).thenReturn(Optional.of(mockLink));
when(response.readEntity(String.class)).thenReturn("");
when(response.getStatus()).thenReturn(400);
when(response.getStatusInfo()).thenReturn(Statuses.from(400));
uut.callWithRel("test");
}
开发者ID:Mercateo,项目名称:rest-hateoas-client,代码行数:14,代码来源:OngoingResponseImpl0Test.java
示例18: testCallWithRel_Object
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
@Test
public void testCallWithRel_Object() throws Exception {
SchemaLink mockLink = mock(SchemaLink.class);
when(mockLink.getMap())
.thenReturn(Maps.asMap(Sets.newHashSet(OngoingResponseImpl.METHOD_PARAM_KEY), k -> "put"));
UriTemplate uri = new UriTemplate("http://www.mercateo.com/");
when(mockLink.getHref()).thenReturn(uri);
when(jsonHyperSchema.getByRel(any())).thenReturn(Optional.of(mockLink));
when(response.readEntity(String.class)).thenReturn("");
uut = uut.withRequestObject(new Object());
uut.callWithRel("test");
verify(builder).method(any(), any(Entity.class));
verify(responseBuilder).buildResponse(any(), any(), any());
}
开发者ID:Mercateo,项目名称:rest-hateoas-client,代码行数:15,代码来源:OngoingResponseImpl0Test.java
示例19: testDoNotPassEntityForGet
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
@Test
public void testDoNotPassEntityForGet() throws Exception {
SchemaLink mockLink = mock(SchemaLink.class);
when(mockLink.getMap())
.thenReturn(Maps.asMap(Sets.newHashSet(OngoingResponseImpl.METHOD_PARAM_KEY), k -> "get"));
UriTemplate uri = new UriTemplate("http://www.mercateo.com/%7Bid%7D");
when(mockLink.getHref()).thenReturn(uri);
when(jsonHyperSchema.getByRel(any())).thenReturn(Optional.of(mockLink));
when(response.readEntity(String.class)).thenReturn("");
uut = uut.withRequestObject(new StringIdBean("bla"));
uut.callWithRel("test");
verify(builder, never()).method(any(), any(Entity.class));
}
开发者ID:Mercateo,项目名称:rest-hateoas-client,代码行数:14,代码来源:OngoingResponseImpl0Test.java
示例20: testCallListWithRel
import org.glassfish.jersey.uri.UriTemplate; //导入依赖的package包/类
@Test
public void testCallListWithRel() throws Exception {
SchemaLink mockLink = mock(SchemaLink.class);
when(mockLink.getMap())
.thenReturn(Maps.asMap(Sets.newHashSet(OngoingResponseImpl.METHOD_PARAM_KEY), k -> "put"));
UriTemplate uri = new UriTemplate("http://www.mercateo.com/");
when(mockLink.getHref()).thenReturn(uri);
when(jsonHyperSchema.getByRel(any())).thenReturn(Optional.of(mockLink));
when(response.readEntity(String.class)).thenReturn("");
uut.callListWithRel("test");
verify(responseBuilder).buildListResponse(any(), any(), any());
}
开发者ID:Mercateo,项目名称:rest-hateoas-client,代码行数:13,代码来源:OngoingResponseImpl0Test.java
注:本文中的org.glassfish.jersey.uri.UriTemplate类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论