下面列出了怎么用javax.ws.rs.HeaderParam的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
@GET
@ValidationRequired(processor = RestViolationProcessor.class)
@ApiOperation(value = "Get metadata of map", httpMethod="GET", response=MetaDataDTO.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Metadata of map was found", response=MetaDataDTO.class),
@ApiResponse(code = 400, message = "Invalid input parameter (header)"),
@ApiResponse(code = 400, message = "Metadata of map was not found")})
public Response getMetaData(@Auth BasicAuth principal,
@ApiParam(value = "Application identifier", required = true) @NotBlank @NotNull @HeaderParam("api_key") String appIdentifier) throws AssemblyException, MetaDataNotExistsException {
// TODO Auto-generated method stub
validations.checkIsNotNullAndNotBlank(appIdentifier);
MetaData metaData = metaDataManagerImpl.getMetaData(appIdentifier);
MetaDataDTO metaDataDTO=metaDataAssemblerImpl.createDataTransferObject(metaData);
return Response.ok(metaDataDTO).build();
}
@GET
@Path("/{moduleTypeUID}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets a module type corresponding to the given UID.", response = ModuleTypeDTO.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = ModuleTypeDTO.class),
@ApiResponse(code = 404, message = "Module Type corresponding to the given UID does not found.") })
public Response getByUID(@HeaderParam("Accept-Language") @ApiParam(value = "language") String language,
@PathParam("moduleTypeUID") @ApiParam(value = "moduleTypeUID", required = true) String moduleTypeUID) {
Locale locale = localeService.getLocale(language);
final ModuleType moduleType = moduleTypeRegistry.get(moduleTypeUID, locale);
if (moduleType != null) {
return Response.ok(getModuleTypeDTO(moduleType)).build();
} else {
return Response.status(Status.NOT_FOUND).build();
}
}
@GET
@Path("api/v3/myTrades")
/**
* Get trades for a specific account and symbol.
*
* @param symbol
* @param limit optional, default 500; max 500.
* @param fromId optional, tradeId to fetch from. Default gets most recent trades.
* @param recvWindow optional
* @param timestamp
* @param apiKey
* @param signature
* @return
* @throws IOException
* @throws BinanceException
*/
List<BinanceTrade> myTrades(
@QueryParam("symbol") String symbol,
@QueryParam("limit") Integer limit,
@QueryParam("fromId") Long fromId,
@QueryParam("recvWindow") Long recvWindow,
@QueryParam("timestamp") long timestamp,
@HeaderParam(X_MBX_APIKEY) String apiKey,
@QueryParam(SIGNATURE) ParamsDigest signature)
throws IOException, BinanceException;
@Override
@Path("/{idFeature}")
@DELETE
@ValidationRequired(processor = RestViolationProcessor.class)
@ApiOperation(value = "Delete a feature", httpMethod="DELETE")
@ApiResponses(value = {
@ApiResponse(code = 204, message = "Feature was deleted"),
@ApiResponse(code = 400, message = "Invalid input parameter (header)"),
@ApiResponse(code = 404, message = "Feature was not found")})
public Response deleteFeature(@Auth BasicAuth principal,
@ApiParam(value = "Application identifier", required = true) @NotBlank @NotNull @HeaderParam("api_key") String appIdentifier,
@ApiParam(required=true, value="Feature identifier") @NotBlank @NotNull @PathParam("idFeature") String idFeature) throws FeatureNotExistException {
// TODO Auto-generated method stub
validations.checkIsNotNullAndNotBlank(appIdentifier,idFeature);
featureManager.deleteFeature(appIdentifier, idFeature);
return Response.noContent().build();
}
@PATCH
@Path("/{entitySetName}({entityId})")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
public Response patchEntity(
@Context final UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
@HeaderParam("If-Match") @DefaultValue(StringUtils.EMPTY) final String ifMatch,
@PathParam("entitySetName") final String entitySetName,
@PathParam("entityId") final String entityId,
final String changes) {
final Response response =
getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY);
return response.getStatus() >= 400 ?
postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, changes) :
patchEntityInternal(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId, changes);
}
@GET
@Path("_table")
public List<Map<String, Object>> listTables(@HeaderParam("X-BV-API-Key") String apiKey,
@QueryParam("limit") Integer limit) {
assertEquals(apiKey, API_KEY);
assertEquals(limit, new Integer(1));
return ImmutableList.<Map<String, Object>>of(
ImmutableMap.<String, Object>builder()
.put("name", "test:table")
.put("options", ImmutableMap.<String, Object>of(
"placement", "ugc_us:ugc",
"facades", ImmutableList.of()))
.put("template", ImmutableMap.<String, Object>of(
"type", "test"))
.put("availability", ImmutableMap.<String, Object>of(
"placement", "ugc_us:ugc",
"facade", false))
.build());
}
/**
* メッセージ送信API.
* @param version PCSバージョン
* @param uriInfo UriInfo
* @param reader リクエストボディ
* @return レスポンス
*/
@POST
@Path("send")
public Response messages(
@HeaderParam(DcCoreUtils.HttpHeaders.X_DC_VERSION) final String version,
@Context final UriInfo uriInfo,
final Reader reader) {
// アクセス制御
this.davRsCmp.checkAccessContext(this.accessContext, CellPrivilege.MESSAGE);
// データ登録
DcODataProducer 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;
}
@PUT
@Path("/multiLevelNestedActivity")
@LRA(value = LRA.Type.MANDATORY, end = false)
public Response multiLevelNestedActivity(
@HeaderParam(LRA_HTTP_RECOVERY_HEADER) URI recoveryId,
@HeaderParam(LRA_HTTP_CONTEXT_HEADER) URI nestedLRAId,
@QueryParam("nestedCnt") @DefaultValue("1") Integer nestedCnt) {
assertHeaderPresent(nestedLRAId, LRA_HTTP_CONTEXT_HEADER);
assertHeaderPresent(recoveryId, LRA_HTTP_RECOVERY_HEADER);
storeActivity(nestedLRAId, recoveryId);
// invoke resources that enlist nested LRAs
String[] lras = new String[nestedCnt + 1];
lras[0] = nestedLRAId.toASCIIString();
IntStream.range(1, lras.length).forEach(i -> lras[i] = restPutInvocation(nestedLRAId,"nestedActivity", ""));
return Response.ok(String.join(",", lras)).build();
}
@GET
@Path("/{id}/entries")
@ApiOperation(value = "Gets all entries from a shopping list.")
@ApiResponses(value = {
@ApiResponse(code = HTTP_BAD_REQUEST, message = HTTP_BAD_REQUEST_MESSAGE, response = ErrorResponse.class),
@ApiResponse(code = HTTP_UNAUTHORIZED, message = HTTP_UNAUTHORIZED_MESSAGE, response = ErrorResponse.class),
@ApiResponse(code = HTTP_NOT_FOUND, message = HTTP_NOT_FOUND_MESSAGE, response = ErrorResponse.class)
})
PagedResponse<ShoppingListEntry> getShoppingListEntries(
@ApiParam(value = "The id of the shopping list to return entries from.", required = true)
@PathParam("id")
String id,
@ApiParam(value = "Defines the number of entries to skip.")
@QueryParam(value = "offset")
@Min(value = 0)
Integer offset,
@ApiParam(value = "Defines the maximum number of entries to be returned.")
@QueryParam(value = "limit")
@Min(value = 0)
Integer limit,
@ApiParam(value = ACCEPT_LANGUAGE_DESC)
@HeaderParam(ACCEPT_LANGUAGE) String acceptLanguage
);
@GET
@Path("/{extensionId: [a-zA-Z_0-9-]+}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get extension with given ID.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = String.class),
@ApiResponse(code = 404, message = "Not found") })
public Response getById(@HeaderParam("Accept-Language") @ApiParam(value = "language") @Nullable String language,
@PathParam("extensionId") @ApiParam(value = "extension ID") String extensionId) {
logger.debug("Received HTTP GET request at '{}'.", uriInfo.getPath());
Locale locale = localeService.getLocale(language);
ExtensionService extensionService = getExtensionService(extensionId);
Extension responseObject = extensionService.getExtension(extensionId, locale);
if (responseObject != null) {
return Response.ok(responseObject).build();
}
return Response.status(404).build();
}
@GET
@Path("{ownerId}/{dataSetName}/changelist.xml")
@Produces(MediaType.APPLICATION_XML)
public Response getChangeList(@HeaderParam("authorization") String authHeader,
@PathParam("ownerId") String owner,
@PathParam("dataSetName") String dataSetName) throws IOException {
User user = getUser(authHeader);
Optional<Urlset> maybeChangeList = rsDocumentBuilder.getChangeList(user, owner, dataSetName);
if (maybeChangeList.isPresent()) {
return Response.ok(maybeChangeList.get()).build();
} else if (user != null) {
return Response.status(Response.Status.FORBIDDEN).build();
} else {
return Response.status(Response.Status.UNAUTHORIZED).build();
}
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets all available channel types.", response = ChannelTypeDTO.class, responseContainer = "Set")
@ApiResponses(value = @ApiResponse(code = 200, message = "OK", response = ChannelTypeDTO.class, responseContainer = "Set"))
public Response getAll(
@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") @Nullable String language,
@QueryParam("prefixes") @ApiParam(value = "filter UIDs by prefix (multiple comma-separated prefixes allowed, for example: 'system,mqtt')") @Nullable String prefixes) {
Locale locale = localeService.getLocale(language);
Stream<ChannelTypeDTO> channelStream = channelTypeRegistry.getChannelTypes(locale).stream()
.map(c -> convertToChannelTypeDTO(c, locale));
if (prefixes != null) {
Predicate<ChannelTypeDTO> filter = ct -> false;
for (String prefix : prefixes.split(",")) {
filter = filter.or(ct -> ct.UID.startsWith(prefix + ":"));
}
channelStream = channelStream.filter(filter);
}
return Response.ok(new Stream2JSONInputStream(channelStream)).build();
}
@GET
@Path("/People/{type:.*}")
public Response getPeople(
@Context final UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
@PathParam("type") final String type,
@QueryParam("$top") @DefaultValue(StringUtils.EMPTY) final String top,
@QueryParam("$skip") @DefaultValue(StringUtils.EMPTY) final String skip,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
@QueryParam("$count") @DefaultValue(StringUtils.EMPTY) final String count,
@QueryParam("$filter") @DefaultValue(StringUtils.EMPTY) final String filter,
@QueryParam("$search") @DefaultValue(StringUtils.EMPTY) final String search,
@QueryParam("$orderby") @DefaultValue(StringUtils.EMPTY) final String orderby,
@QueryParam("$skiptoken") @DefaultValue(StringUtils.EMPTY) final String skiptoken) {
return StringUtils.isBlank(filter) && StringUtils.isBlank(search) ?
NumberUtils.isNumber(type) ?
getEntityInternal(uriInfo.getRequestUri().toASCIIString(), accept, "People", type, format, null, null) :
getEntitySet(accept, "People", type) :
getEntitySet(uriInfo, accept, "People", top, skip, format, count, filter, orderby, skiptoken, type);
}
@PUT
@Path("/{entitySetName}/{entityId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
public Response putNewEntity(
@Context final UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) final String contentType,
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) final String prefer,
@PathParam("entitySetName") final String entitySetName,
@PathParam("entityId") final String entityId,
final String entity) {
return replaceServiceName(super
.replaceEntity(uriInfo, accept, contentType, prefer, entitySetName, entityId, entity));
}
@GET
@Path("/{thingUID}/firmwares")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all available firmwares for provided thing UID", response = StrippedThingTypeDTO.class, responseContainer = "Set")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 204, message = "No firmwares found.") })
public Response getFirmwares(@PathParam("thingUID") @ApiParam(value = "thingUID") String thingUID,
@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = HttpHeaders.ACCEPT_LANGUAGE) String language) {
ThingUID aThingUID = new ThingUID(thingUID);
Thing thing = thingRegistry.get(aThingUID);
if (null == thing) {
logger.info(
"Received HTTP GET request for listing available firmwares at {} for unknown thing with UID '{}'",
uriInfo.getPath(), thingUID);
return getThingNotFoundResponse(thingUID);
}
Collection<Firmware> firmwares = firmwareRegistry.getFirmwares(thing, localeService.getLocale(language));
if (firmwares.isEmpty()) {
return Response.status(Status.NO_CONTENT).build();
}
Stream<FirmwareDTO> firmwareStream = firmwares.stream().map(this::convertToFirmwareDTO);
return Response.ok().entity(new Stream2JSONInputStream(firmwareStream)).build();
}
@Path("action") // $NON-NLS-1$
@PUT
public Response putEventAction(String requestEntity, @HeaderParam("Content-Type") String contentType, // $NON-NLS-1$
@Context UriInfo uriInfo, @PathParam(EVENT) String id,
@QueryParam(URL_PARAM_ACTION_TYPE) String type) {
CALENDAR_SERVICE_LOGGER.traceEntry(this, "putEventAction"); // $NON-NLS-1$
CalendarService.beforeRequest(FEATURE_REST_API_CALENDAR_EVENT, STAT_MISC);
CalendarService.verifyDatabaseContext();
EventActionResource.putEventActionInternal(requestEntity, contentType, id, null, null, type);
ResponseBuilder builder = Response.ok();
Response response = builder.build();
CALENDAR_SERVICE_LOGGER.traceExit(this, "putEventAction", response); // $NON-NLS-1$
return response;
}
@GET
@Path("subscribers")
CoinbaseSubscriptions getsSubscriptions(
@QueryParam("page") Integer page,
@QueryParam("limit") Integer limit,
@HeaderParam("ACCESS_KEY") String apiKey,
@HeaderParam("ACCESS_SIGNATURE") ParamsDigest signer,
@HeaderParam("ACCESS_NONCE") SynchronizedValueFactory<Long> nonce)
throws IOException, CoinbaseException;
@POST
@Path("deposit/new")
BitfinexDepositAddressResponse requestDeposit(
@HeaderParam("X-BFX-APIKEY") String apiKey,
@HeaderParam("X-BFX-PAYLOAD") ParamsDigest payload,
@HeaderParam("X-BFX-SIGNATURE") ParamsDigest signature,
BitfinexDepositAddressRequest depositRequest)
throws IOException, BitfinexException;
@POST
@Path("buttons")
@Consumes(MediaType.APPLICATION_JSON)
CoinbaseButton createButton(
CoinbaseButton button,
@HeaderParam("ACCESS_KEY") String apiKey,
@HeaderParam("ACCESS_SIGNATURE") ParamsDigest signer,
@HeaderParam("ACCESS_NONCE") SynchronizedValueFactory<Long> nonce)
throws IOException, CoinbaseException;
@POST
public void setI(
@MatrixParam("") String matrixParam,
@QueryParam("") String queryParam,
@PathParam("") String pathParam,
@CookieParam("") String cookieParam,
@Suspended AsyncResponse suspendedParam,
@HeaderParam("") String headerParam,
@Context String context,
@FormParam("") String formParam,
I entityI) {
}
@POST
@Path("/subresource2/{n1:.*}")
@Consumes("text/plain")
@Produces("application/xml")
Book getTheBook2(@PathParam("n1") String name1,
@QueryParam("n2") String name2,
@MatrixParam("n3") String name3,
@MatrixParam("n33") String name33,
@HeaderParam("N4") String name4,
@CookieParam("n5") String name5,
String name6) throws BookNotFoundFault;
@PUT
@Path("/")
@Consumes(APPLICATION_JSON)
void setProblems(
@HeaderParam(AUTHORIZATION) AuthHeader authHeader,
@PathParam("contestJid") String contestJid,
List<ContestProblemData> data);
@PUT
@Path("/complete")
@Produces(MediaType.APPLICATION_JSON)
@Complete
public Response completeWork(@HeaderParam(LRA_HTTP_CONTEXT_HEADER) URI lraId,
@HeaderParam(LRA_HTTP_RECOVERY_HEADER) URI recoveryId,
String userData) {
lraMetricService.incrementMetric(LRAMetricType.Completed, lraId, LraResource.class.getName());
assertHeaderPresent(lraId, LRA_HTTP_CONTEXT_HEADER); // the TCK expects the implementation to invoke @Complete methods
assertHeaderPresent(recoveryId, LRA_HTTP_RECOVERY_HEADER); // the TCK expects the implementation to invoke @Complete methods
Activity activity = activityStore.getActivityAndAssertExistence(lraId, context);
activity.setEndData(userData);
if (activity.getAndDecrementAcceptCount() > 0) {
activity.setStatus(ParticipantStatus.Completing);
activity.setStatusUrl(String.format("%s/%s/%s/status", context.getBaseUri(),
LRA_RESOURCE_PATH, lraId));
return Response.accepted().location(URI.create(activity.getStatusUrl())).build();
}
activity.setStatus(ParticipantStatus.Completed);
activity.setStatusUrl(String.format("%s/%s/activity/completed", context.getBaseUri(), lraId.toASCIIString()));
LOGGER.info(String.format("LRA id '%s' was completed", lraId.toASCIIString()));
return Response.ok(activity.getStatusUrl()).build();
}
/**
* Box単位のRoleリソースのルート.
* Boxに紐付いたロール一覧を返す。
* Box名として__を指定されたときは、Cellレベルのロールとみなす。
* @param boxName boxName
* @param authzHeader authzHeader
* @return JAXRS Response
*/
@Path("{box}")
@GET
public final Response cellRole(
@PathParam("box") String boxName,
@HeaderParam(HttpHeaders.AUTHORIZATION) final String authzHeader) {
// アクセス制御
this.davRsCmp.checkAccessContext(this.davRsCmp.getAccessContext(), CellPrivilege.AUTH_READ);
// BoxパスがCell Levelであれば、Cell レベルロールを検索して一覧で返す。
if (BOX_PATH_CELL_LEVEL.equals(boxName)) {
// TODO Bodyの生成
// EntitiesResponse er = this.op.getEntities(Role.EDM_TYPE_NAME, null);
return Response.ok().entity(boxName).build();
}
try {
// EntityResponse boxEr = op.getEntity(Box.EDM_TYPE_NAME, OEntityKey.create(boxName), null);
// EntitiesResponse rolesEr = (EntitiesResponse) op.getNavProperty(Role.EDM_TYPE_NAME,
// OEntityKey.create(boxName),
// "_role", null);
// TODO Bodyの生成
return Response.ok().entity(boxName).build();
} catch (DcCoreException dce) {
if (DcCoreException.OData.NO_SUCH_ENTITY == dce) {
throw DcCoreException.Dav.BOX_NOT_FOUND;
}
throw dce;
}
}
@GET
@RolesAllowed({ Role.USER })
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets all available profile types.", response = ProfileTypeDTO.class, responseContainer = "Set")
@ApiResponses(value = @ApiResponse(code = 200, message = "OK", response = ProfileTypeDTO.class, responseContainer = "Set"))
public Response getAll(
@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = HttpHeaders.ACCEPT_LANGUAGE) String language,
@QueryParam("channelTypeUID") @ApiParam(value = "channel type filter", required = false) @Nullable String channelTypeUID,
@QueryParam("itemType") @ApiParam(value = "item type filter", required = false) @Nullable String itemType) {
Locale locale = localeService.getLocale(language);
return Response.ok(new Stream2JSONInputStream(getProfileTypes(locale, channelTypeUID, itemType))).build();
}
/**
* Get a new ID as plain text
*
* @param agent
* User Agent
* @return generated ID
*/
@GET
@Timed
@Produces(MediaType.TEXT_PLAIN)
@CacheControl(mustRevalidate = true, noCache = true, noStore = true)
public String getIdAsString(
@HeaderParam(HttpHeaders.USER_AGENT) final String agent) {
return String.valueOf(getId(agent));
}
/**
* @param authzHeaderValue Authorization ヘッダ
* @param host Host ヘッダ
* @param xDcUnitUser ヘッダ
* @param uriInfo UriInfo
* @return UnitCtlResourceオブジェクト
*/
@Path("__status")
public final StatusResource status(
@HeaderParam(HttpHeaders.AUTHORIZATION) final String authzHeaderValue,
@HeaderParam(HttpHeaders.HOST) final String host,
@HeaderParam(DcCoreUtils.HttpHeaders.X_DC_UNIT_USER) final String xDcUnitUser,
@Context final UriInfo uriInfo) {
return new StatusResource();
}
@POST
@Path("_move")
public Map<String, Object> moveAsync(@HeaderParam("X-BV-API-Key") String apiKey,
@QueryParam("from") String from, @QueryParam("to") String to) {
assertEquals(apiKey, API_KEY);
assertEquals(from, "test-queue-old");
assertEquals(to, "test-queue-new");
return ImmutableMap.<String, Object>of("id", "test-move");
}
@Path("requestHeaders")
@GET
public String getRequestHeaders(@HeaderParam(value = "x_cse_test") String testHeader,
HttpServletRequest request) {
String external1 = request.getHeader("external_1");
String external2 = request.getHeader("external_2");
String external3 = request.getHeader("external_3");
if (StringUtils.isEmpty(external3)) {
return testHeader + "_" + external1 + "_" + external2;
}
return testHeader + "_" + external1 + "_" + external2 + "_" + external3;
}
/**
* Cancel on family is set to <code>3xx</code>. The <code>3xx</code> return code
* has to cancel the LRA.
* @param lraId The LRA id generated for this action
* @return JAX-RS response
*/
@GET
@Path(CANCEL_ON_FAMILY_3XX)
@LRA(value = Type.REQUIRES_NEW,
cancelOnFamily = Family.REDIRECTION)
public Response cancelOnFamily3xx(@HeaderParam(LRA_HTTP_CONTEXT_HEADER) URI lraId) {
return Response.status(Status.SEE_OTHER).entity(lraId).build();
}