本文整理汇总了Java中javax.ws.rs.core.UriInfo类的典型用法代码示例。如果您正苦于以下问题:Java UriInfo类的具体用法?Java UriInfo怎么用?Java UriInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UriInfo类属于javax.ws.rs.core包,在下文中一共展示了UriInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import javax.ws.rs.core.UriInfo; //导入依赖的package包/类
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{projectName}/statuses/{commit}")
@POST
public Response save(@PathParam("projectName") String projectName, @PathParam("commit") String commit,
Map<String, String> commitStatus, @Context UriInfo uriInfo) {
Project project = getProject(projectName);
if (!SecurityUtils.canWrite(project))
throw new UnauthorizedException();
String state = commitStatus.get("state").toUpperCase();
if (state.equals("PENDING"))
state = "RUNNING";
Verification verification = new Verification(Verification.Status.valueOf(state),
new Date(), commitStatus.get("description"), commitStatus.get("target_url"));
String context = commitStatus.get("context");
if (context == null)
context = "default";
verificationManager.saveVerification(project, commit, context, verification);
UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder();
uriBuilder.path(context);
commitStatus.put("id", "1");
return Response.created(uriBuilder.build()).entity(commitStatus).type(RestConstants.JSON_UTF8).build();
}
示例2: listAllCustomerEvents
import javax.ws.rs.core.UriInfo; //导入依赖的package包/类
@GET
@Produces({"application/hal+json", "application/hal+json;concept=events;v=1"})
@ApiOperation(
value = "obtain all events emitted by the customer-event service", response = EventsRepresentation.class,
notes = " the events are signalled by this resource as this this is the authoritative resource for all events that " +
"subscribers to the customers service should be able to listen for and react to. In other words this is the authoritative" +
"feed for the customers service",
authorizations = {
@Authorization(value = "oauth2", scopes = {}),
@Authorization(value = "oauth2-cc", scopes = {}),
@Authorization(value = "oauth2-ac", scopes = {}),
@Authorization(value = "oauth2-rop", scopes = {}),
@Authorization(value = "Bearer")
},
tags = {"interval", "events"},
produces = "application/hal+json, application/hal+json;concept=events;v=1",
nickname = "listAllCustomerEvents"
)
@ApiResponses(value = {
@ApiResponse(code = 415, message = "Content type not supported.")
})
public Response listAllCustomerEvents(@Context UriInfo uriInfo, @Context Request request,
@HeaderParam("Accept") String accept, @QueryParam("interval") String interval) {
return eventsProducers.getOrDefault(accept, this::handleUnsupportedContentType)
.getResponse(uriInfo, request, interval);
}
示例3: getCustomerServiceMetadata
import javax.ws.rs.core.UriInfo; //导入依赖的package包/类
@GET
@Produces({"application/hal+json", "application/hal+json;concept=metadata;v=1"})
@ApiOperation(
value = "metadata for the events endpoint", response = EventsMetadataRepresentation.class,
authorizations = {
@Authorization(value = "oauth2", scopes = {}),
@Authorization(value = "oauth2-cc", scopes = {}),
@Authorization(value = "oauth2-ac", scopes = {}),
@Authorization(value = "oauth2-rop", scopes = {}),
@Authorization(value = "Bearer")
},
notes = " the events are signalled by this resource as this this is the authoritative resource for all events that " +
"subscribers to the customer service should be able to listen for and react to. In other words this is the authoritative" +
"feed for the customer service",
tags = {"events"},
produces = "application/hal+json, application/hal+json;concept=metadata;v=1",
nickname = "getCustomerMetadata"
)
@ApiResponses(value = {
@ApiResponse(code = 415, message = "Content type not supported.")
})
public Response getCustomerServiceMetadata(@Context UriInfo uriInfo, @Context Request request, @HeaderParam("Accept") String accept) {
return eventMetadataProducers.getOrDefault(accept, this::handleUnsupportedContentType).getResponse(uriInfo, request);
}
示例4: beforeCreate_Normal_type_unitmaster
import javax.ws.rs.core.UriInfo; //导入依赖的package包/类
/**
* Test beforeCreate().
* normal.
* Type is UnitMaster.
* @throws Exception Unintended exception in test
*/
@Test
public void beforeCreate_Normal_type_unitmaster() throws Exception {
// Test method args
OEntityWrapper oEntityWrapper = PowerMockito.mock(OEntityWrapper.class);
// Mock settings
UriInfo uriInfo = mock(UriInfo.class);
URI uri = new URI("");
doReturn(uri).when(uriInfo).getBaseUri();
AccessContext accessContext = PowerMockito.mock(AccessContext.class);
unitCtlResource = spy(new UnitCtlResource(accessContext, uriInfo));
doReturn(accessContext).when(unitCtlResource).getAccessContext();
doReturn(AccessContext.TYPE_UNIT_MASTER).when(accessContext).getType();
// Expected result
// None.
// Run method
unitCtlResource.beforeCreate(oEntityWrapper);
// Confirm result
// None.
}
示例5: messages
import javax.ws.rs.core.UriInfo; //导入依赖的package包/类
/**
* メッセージ送信API.
* @param version PCSバージョン
* @param uriInfo UriInfo
* @param reader リクエストボディ
* @return レスポンス
*/
@WriteAPI
@POST
@Path("send")
public Response messages(
@HeaderParam(PersoniumCoreUtils.HttpHeaders.X_PERSONIUM_VERSION) final String version,
@Context final UriInfo uriInfo,
final Reader reader) {
// アクセス制御
this.davRsCmp.checkAccessContext(this.accessContext, CellPrivilege.MESSAGE);
// データ登録
PersoniumODataProducer producer = ModelFactory.ODataCtl.cellCtl(this.accessContext.getCell());
MessageODataResource moResource = new MessageODataResource(this, producer, SentMessagePort.EDM_TYPE_NAME);
moResource.setVersion(version);
Response respose = moResource.createMessage(uriInfo, reader);
return respose;
}
示例6: postNoBody
import javax.ws.rs.core.UriInfo; //导入依赖的package包/类
/**
* Build a response for POST create namespace with no properties specified.
* @param message value not used.
* @param headers value not used.
* @return response code.
*/
@POST
public Response postNoBody(final byte[] message,
final @Context UriInfo uriInfo, final @Context HttpHeaders headers) {
if (LOG.isDebugEnabled()) {
LOG.debug("POST " + uriInfo.getAbsolutePath());
}
servlet.getMetrics().incrementRequests(1);
try{
NamespacesInstanceModel model = new NamespacesInstanceModel(namespace);
return processUpdate(model, false, uriInfo);
}catch(IOException ioe){
servlet.getMetrics().incrementFailedPutRequests(1);
throw new RuntimeException("Cannot retrieve info for '" + namespace + "'.");
}
}
示例7: testCreate
import javax.ws.rs.core.UriInfo; //导入依赖的package包/类
@Test
public void testCreate() throws Exception {
Request request = mock(Request.class);
UriInfo ui = mock(UriInfo.class);
when(ui.getBaseUriBuilder()).then(new UriBuilderFactory(URI.create("http://mock")));
when(ui.getPath()).thenReturn("http://mock");
AccountUpdateRepresentation accountUpdate = mock(AccountUpdateRepresentation.class);
when(accountUpdate.getName()).thenReturn("new Account");
when(accountUpdate.getRegNo()).thenReturn("5479");
when(accountUpdate.getAccountNo()).thenReturn("12345678");
when(accountUpdate.getCustomer()).thenReturn("cust-1");
when(archivist.findAccount("5479", "12345678")).thenReturn(Optional.empty());
AccountRepresentation resp = (AccountRepresentation) service.createOrUpdate(ui, request, "5479", "12345678", accountUpdate).getEntity();
assertEquals("new Account", resp.getName());
assertEquals("5479", resp.getRegNo());
assertEquals("12345678", resp.getAccountNo());
assertEquals("http://mock/accounts/5479-12345678", resp.getSelf().getHref());
}
示例8: deleteZNode
import javax.ws.rs.core.UriInfo; //导入依赖的package包/类
@DELETE
@Produces( { MediaType.APPLICATION_JSON, "application/javascript",
MediaType.APPLICATION_XML, MediaType.APPLICATION_OCTET_STREAM })
public void deleteZNode(@PathParam("path") String path,
@DefaultValue("-1") @QueryParam("version") String versionParam,
@Context UriInfo ui) throws InterruptedException, KeeperException {
ensurePathNotNull(path);
int version;
try {
version = Integer.parseInt(versionParam);
} catch (NumberFormatException e) {
throw new WebApplicationException(Response.status(
Response.Status.BAD_REQUEST).entity(
new ZError(ui.getRequestUri().toString(), path
+ " bad version " + versionParam)).build());
}
zk.delete(path, version);
}
示例9: getUiPageRequestSimpleSort
import javax.ws.rs.core.UriInfo; //导入依赖的package包/类
/**
* Simple page request with default values but sorted column.
*/
@Test
public void getUiPageRequestSimpleSort() {
// create a mock URI info with pagination informations
final UriInfo uriInfo = newUriInfo();
uriInfo.getQueryParameters().add("sidx", "colX");
final UiPageRequest pageRequest = paginationJson.getUiPageRequest(uriInfo);
Assert.assertNotNull(pageRequest);
Assert.assertEquals(1, pageRequest.getPage());
Assert.assertEquals(10, pageRequest.getPageSize());
Assert.assertNotNull(pageRequest.getUiFilter());
Assert.assertNull(pageRequest.getUiFilter().getGroupOp());
Assert.assertNull(pageRequest.getUiFilter().getRules());
Assert.assertNotNull(pageRequest.getUiSort());
Assert.assertEquals("colX", pageRequest.getUiSort().getColumn());
Assert.assertEquals(Direction.ASC, pageRequest.getUiSort().getDirection());
}
示例10: list
import javax.ws.rs.core.UriInfo; //导入依赖的package包/类
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiImplicitParams({
@ApiImplicitParam(
name = "sort", value = "Sort the result list according to the given field value",
paramType = "query", dataType = "string"),
@ApiImplicitParam(
name = "direction", value = "Sorting direction when a 'sort' field is provided. Can be 'asc' " +
"(ascending) or 'desc' (descending)", paramType = "query", dataType = "string"),
@ApiImplicitParam(
name = "page", value = "Page number to return", paramType = "query", dataType = "integer", defaultValue = "1"),
@ApiImplicitParam(
name = "per_page", value = "Number of records per page", paramType = "query", dataType = "integer", defaultValue = "20"),
@ApiImplicitParam(
name = "query", value = "The search query to filter results on", paramType = "query", dataType = "string"),
})
default ListResult<T> list(@Context UriInfo uriInfo) {
Class<T> clazz = resourceKind().getModelClass();
return getDataManager().fetchAll(
clazz,
new ReflectiveFilterer<>(clazz, new FilterOptionsFromQueryParams(uriInfo).getFilters()),
new ReflectiveSorter<>(clazz, new SortOptionsFromQueryParams(uriInfo)),
new PaginationFilter<>(new PaginationOptionsFromQueryParams(uriInfo))
);
}
示例11: thrownErrorWithMDC
import javax.ws.rs.core.UriInfo; //导入依赖的package包/类
@Test
public void thrownErrorWithMDC() {
MDC.put(MDCKeys.REQUEST_ID, "abc");
MDC.put(MDCKeys.HOST, "localhost");
MDC.put(MDCKeys.REQUEST_URI, "http://hello");
MDC.put(MDCKeys.JWT_ID, "def");
final ErrorResponse response = new ErrorResponse(new IOException("ahem"), mock(UriInfo.class), true);
assertNotNull(response.getStackTrace());
assertNull(response.getCause());
assertEquals(URI.create("http://hello"), response.getRequestUri());
assertEquals("abc", response.getRequestId());
assertEquals("def", response.getJwtId());
assertEquals("localhost", response.getHost());
}
示例12: getPageRequestNoMappingOrder
import javax.ws.rs.core.UriInfo; //导入依赖的package包/类
/**
* Sorted direction with ordering but no mapping provided.
*/
@Test
public void getPageRequestNoMappingOrder() {
// create a mock URI info with pagination informations
final UriInfo uriInfo = newUriInfo();
uriInfo.getQueryParameters().add(DataTableAttributes.PAGE_LENGTH, "100");
uriInfo.getQueryParameters().add(DataTableAttributes.SORTED_COLUMN, "2");
uriInfo.getQueryParameters().add("columns[2][data]", "col1");
uriInfo.getQueryParameters().add(DataTableAttributes.SORT_DIRECTION, "asc");
final PageRequest pageRequest = paginationJson.getPageRequest(uriInfo, null);
Assert.assertNotNull(pageRequest);
Assert.assertFalse(pageRequest.getSort().isSorted());
Assert.assertEquals(0, pageRequest.getOffset());
Assert.assertEquals(0, pageRequest.getPageNumber());
Assert.assertEquals(100, pageRequest.getPageSize());
}
示例13: getOneComment
import javax.ws.rs.core.UriInfo; //导入依赖的package包/类
@GET
@Path("/{uuid}/{version}/comment/{commentuuid}")
@ApiOperation(value = "Retrieve a single comment for an item by ID.")
CommentBean getOneComment(
@Context
UriInfo info,
@ApiParam(APIDOC_ITEMUUID)
@PathParam("uuid")
String uuid,
@ApiParam(APIDOC_ITEMVERSION)
@PathParam("version")
int version,
@ApiParam(required = true)
@PathParam("commentuuid")
String commentUuid
);
示例14: testUpdate
import javax.ws.rs.core.UriInfo; //导入依赖的package包/类
@Test
public void testUpdate() throws Exception {
Request request = mock(Request.class);
UriInfo ui = mock(UriInfo.class);
when(ui.getBaseUriBuilder()).then(new UriBuilderFactory(URI.create("http://mock")));
when(ui.getPath()).thenReturn("http://mock");
Account existingAcc = new Account("5479", "12345678", "Savings account", "cust-1");
when(archivist.findAccount("5479", "12345678")).thenReturn(Optional.of(existingAcc));
AccountUpdateRepresentation accountUpdate = mock(AccountUpdateRepresentation.class);
when(accountUpdate.getName()).thenReturn("new name");
when(accountUpdate.getRegNo()).thenReturn("5479");
when(accountUpdate.getAccountNo()).thenReturn("12345678");
AccountRepresentation resp = (AccountRepresentation) service.createOrUpdate(ui, request, "5479", "12345678", accountUpdate).getEntity();
//name of the existing account should be updated
assertEquals("new name", existingAcc.getName());
assertEquals("new name", resp.getName());
assertEquals("5479", resp.getRegNo());
assertEquals("12345678", resp.getAccountNo());
assertEquals("0", existingAcc.getBalance().toString());
assertEquals("0", resp.getBalance().toString());
assertEquals("http://mock/accounts/5479-12345678", resp.getSelf().getHref());
}
示例15: filter
import javax.ws.rs.core.UriInfo; //导入依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
System.out.println("Response = " + requestContext + " " + responseContext);
Long start = concurrentRequests.get(requestContext);
concurrentRequests.remove(requestContext);
long duration = (System.nanoTime() - start);
System.out.println("Duration: " + duration);
UriInfo uriInfo = requestContext.getUriInfo();
String ipv4 = extractIpAddress(uriInfo);
System.out.println("ipv4 = " + ipv4);
String serviceName = extractServiceName(uriInfo);
System.out.println("serviceName = " + serviceName);
String spanName = extractSpanName(uriInfo);
System.out.println("spanName = " + spanName);
Optional<String> traceId = extractTraceId(requestContext);
String spanId = traceId.map(id -> this.tracee.saveChildSpan(id, spanName, serviceName, ipv4, 0)).
orElseGet(() -> this.tracee.saveParentSpan(spanName, serviceName, ipv4, duration));
System.out.println("Storing span id: " + spanId);
storeSpandId(responseContext, spanId);
}