本文整理汇总了Java中javax.ws.rs.core.MultivaluedMap.getFirst方法的典型用法代码示例。如果您正苦于以下问题:Java MultivaluedMap.getFirst方法的具体用法?Java MultivaluedMap.getFirst怎么用?Java MultivaluedMap.getFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.MultivaluedMap
的用法示例。
在下文中一共展示了MultivaluedMap.getFirst方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PaginationOptionsFromQueryParams
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
/**
* Extracts the pagination options from the request.
* @param uri The request context.
*/
public PaginationOptionsFromQueryParams(UriInfo uri) {
MultivaluedMap<String, String> queryParams = uri.getQueryParameters();
String pageQuery = queryParams.getFirst("page");
if (pageQuery == null || pageQuery.isEmpty()) {
page = 1;
} else {
page = Integer.parseInt(pageQuery);
}
String perPageQuery = queryParams.getFirst("per_page");
if (perPageQuery == null || perPageQuery.isEmpty()) {
perPage = 20;
} else {
perPage = Integer.parseInt(perPageQuery);
}
}
示例2: receiveSlackCommand
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
/**
* Slack command endpoint. This is where the application is receiving slash commands from Slack
* and returning synchronous responses to them.
*
* @param params parameters posted from Slack
* @return synchronous response for the command
*/
@Path("/command")
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public SlackCommandResponse receiveSlackCommand(final MultivaluedMap<String, String> params) {
LOGGER.debug("Received Slack command: {}", params);
final String token = params.getFirst("token");
if (slackConfig().getCommandVerificationTokens().contains(token)) {
final String command = params.getFirst("command");
switch (command) {
case LIST_COMMAND:
return listDevices();
case SHOW_COMMAND:
return showDevice(params);
case CLAIM_COMMAND:
return claim(params);
case UNCLAIM_COMMAND:
return unclaim(params);
default:
throw new IllegalArgumentException("Unknown command: " + command);
}
} else {
throw new IllegalStateException("Token error");
}
}
示例3: getSessionId
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
protected Optional<SessionId> getSessionId() {
// Are there any uris in Policy that contain the session id as a query string rather than as part of the path or is this just here coz it was copied from shared-rest ?
String parameter = httpServletRequest.getParameter(Urls.SharedUrls.SESSION_ID_PARAM);
if (Strings.isNullOrEmpty(parameter)) {
parameter = httpServletRequest.getParameter(Urls.SharedUrls.RELAY_STATE_PARAM);
}
if (Strings.isNullOrEmpty(parameter)) {
MultivaluedMap<String, String> pathParameters = uriInfo.getPathParameters();
parameter = pathParameters.getFirst(Urls.SharedUrls.SESSION_ID_PARAM);
}
if (Strings.isNullOrEmpty(parameter)) {
return Optional.absent();
} else {
return Optional.fromNullable(new SessionId(parameter));
}
}
示例4: isIdentifierValid
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
private boolean isIdentifierValid(MultivaluedMap<String,String> sessionData, long validitySeconds) {
String stamp = sessionData.getFirst("B02K_STAMP");
if (null != stamp && stamp.length() == 20) {
try {
long creationTimeSec = Long.parseLong(stamp.substring(0, 13))/1000;
long nowSec = this.clock.millis()/1000;
if (nowSec < (creationTimeSec + validitySeconds)) {
return true;
}
} catch (NumberFormatException e) {
logger.warn("Unexpected B02K_STAMP in session data " + sessionData);
return false;
}
}
return false;
}
示例5: build
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
@GET
public Response build() {
MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
String service = params.getFirst(CASLoginProtocol.SERVICE_PARAM);
boolean renew = params.containsKey(CASLoginProtocol.RENEW_PARAM);
boolean gateway = params.containsKey(CASLoginProtocol.GATEWAY_PARAM);
checkSsl();
checkRealm();
checkClient(service);
AuthorizationEndpointChecks checks = getOrCreateAuthenticationSession(client, null);
if (checks.response != null) {
return checks.response;
}
authenticationSession = checks.authSession;
updateAuthenticationSession();
// So back button doesn't work
CacheControlUtil.noBackButtonCacheControlHeader();
if (renew) {
authenticationSession.setClientNote(CASLoginProtocol.RENEW_PARAM, "true");
}
this.event.event(EventType.LOGIN);
return handleBrowserAuthenticationRequest(authenticationSession, new CASLoginProtocol(session, realm, uriInfo, headers, event), gateway, false);
}
示例6: claim
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
/**
* @param params parameters posted from Slack
* @return an ephemeral info message for the sender
*/
private SlackCommandResponse claim(final MultivaluedMap<String, String> params) {
final String text = params.getFirst("text");
if (StringUtils.isEmpty(text)) {
final String command = params.getFirst("command");
return help(command);
} else {
final String username = params.getFirst("user_name");
return claimByText(text, username);
}
}
示例7: unclaim
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
private SlackCommandResponse unclaim(final MultivaluedMap<String, String> params) {
final String text = params.getFirst("text");
final String username = params.getFirst("user_name");
if (StringUtils.isEmpty(text)) {
final String command = params.getFirst("command");
return help(command);
} else if (UNCLAIM_ALL_ARG.equalsIgnoreCase(text)) {
return unclaimAll(username);
} else {
return unclaimByText(text, username);
}
}
示例8: multiParam
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
/**
* Provides a facility to retrieve a param by more than one name. Different libraries
* and frameworks, expect (in some cases) different names for the same param.
* @param queryParams the parameters from the querystring
* @param params an array of one or more param names
* @return the value of the param, or null if not found
*/
private String multiParam(MultivaluedMap<String, String> queryParams, String... params) {
for (String param: params) {
final String value = queryParams.getFirst(param);
if (StringUtils.isNotBlank(value)) {
return value;
}
}
return null;
}
示例9: verifyOutput
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
@Test
public void verifyOutput()
throws IOException, SAXException, ParserConfigurationException, ParseException {
Configuration configuration = mock(Configuration.class);
DatasetConfig datasetConfig = new DatasetConfig();
datasetConfig.setFullPathList(path.toPathList());
TableauMessageBodyGenerator generator = new TableauMessageBodyGenerator(configuration, NodeEndpoint.newBuilder().setAddress("foo").setUserPort(12345).build());
MultivaluedMap<String, Object> httpHeaders = new MultivaluedHashMap<>();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
assertTrue(generator.isWriteable(datasetConfig.getClass(), null, null, WebServer.MediaType.APPLICATION_TDS_TYPE));
generator.writeTo(datasetConfig, DatasetConfig.class, null, new Annotation[] {}, WebServer.MediaType.APPLICATION_TDS_TYPE, httpHeaders, baos);
// Convert the baos into a DOM Tree to verify content
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document document = factory.newDocumentBuilder().parse(new ByteArrayInputStream(baos.toByteArray()));
NodeList connections = document.getDocumentElement().getElementsByTagName("connection");
assertEquals(1, connections.getLength());
Element connection = (Element) connections.item(0);
assertEquals("genericodbc", connection.getAttribute("class"));
assertEquals("Dremio Connector", connection.getAttribute("odbc-driver"));
assertEquals("DREMIO", connection.getAttribute("dbname"));
assertEquals(path.toParentPath(), connection.getAttribute("schema"));
NodeList relations = connection.getElementsByTagName("relation");
assertEquals(1, relations.getLength());
Element relation = (Element) relations.item(0);
assertEquals("table", relation.getAttribute("type"));
assertEquals(tableName, relation.getAttribute("table"));
// Also check that Content-Disposition header is set with a filename ending by tds
ContentDisposition contentDisposition = new ContentDisposition((String) httpHeaders.getFirst(HttpHeaders.CONTENT_DISPOSITION));
assertTrue("filename should end with .tds", contentDisposition.getFileName().endsWith(".tds"));
}
示例10: getTokenFromHeader
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
private Optional<String> getTokenFromHeader(MultivaluedMap<String, String> headers) {
final String authorisationHeader = headers.getFirst(AUTHORIZATION);
if (authorisationHeader != null) {
int delimiterLocation = authorisationHeader.indexOf(' ');
if (delimiterLocation > 0) {
final String authenticationScheme = authorisationHeader.substring(0, delimiterLocation);
if (prefix.equalsIgnoreCase(authenticationScheme)) {
final String token = authorisationHeader.substring(delimiterLocation + 1);
return Optional.of(token);
}
}
}
return Optional.empty();
}
示例11: verifyTupasIdentification
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
private void verifyTupasIdentification(HttpServletRequest request, HttpServletResponse response) throws ExternalAuthenticationException, IOException {
// Identification. Requests have encoding ISO-8859-1
String queryString = request.getQueryString();
queryString.replaceAll("%20", "+");
List<NameValuePair> queryParams = URLEncodedUtils.parse(queryString, Charset.forName("ISO-8859-1"));
MultivaluedMap<String, String> requestParams = convertToMap(queryParams);
String sessionId = request.getSession().getId();
requestParams.putSingle("sessionId", sessionId);
String token = requestParams.getFirst("token");
if (StringUtils.isBlank(token)) {
throw new ExternalAuthenticationException("Bad request, no token");
}
TupasIdentification identification = authenticationHandlerService.buildSession(requestParams);
if ( identification == null ) {
throw new ExternalAuthenticationException("Authentication verification failed");
}
AuthenticationContext ac = ExternalAuthentication.getProfileRequestContext(identification.getCkey(), request).getSubcontext(AuthenticationContext.class);
if ( ac == null ) {
logger.warn("Authentication context not valid");
request.setAttribute(ExternalAuthentication.AUTHENTICATION_ERROR_KEY, "Bad authentication");
ExternalAuthentication.finishExternalAuthentication(identification.getCkey(), request, response);
return;
}
TupasContext tupasContext = new TupasContext(identification.getName(), identification.getHetu());
ac.addSubcontext(tupasContext);
request.setAttribute(ExternalAuthentication.PRINCIPAL_NAME_KEY, token);
/** External authentication success. Give control back to Shibboleth IdP (4.) */
ExternalAuthentication.finishExternalAuthentication(identification.getCkey(), request, response);
return;
}
示例12: parseSessionData
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
public TupasIdentification parseSessionData(final MultivaluedMap<String, String> sessionData) {
String tokenId = sessionData.getFirst("token");
MultivaluedMap<String, String> requestParams = purgeSession(tokenId);
if (!validateIdentification(sessionData, tokenId, requestParams)) {
return null;
}
logger.info("Accepting Tupas identification for token={} B02K_STAMP={}",
tokenId,
sessionData.getFirst("B02K_STAMP"));
return new TupasIdentification(sessionData.getFirst("B02K_CUSTID"), sessionData.getFirst("B02K_CUSTNAME"), requestParams.getFirst("ckey"));
}
示例13: writeTo
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
@Override
public void writeTo(DatasetConfig datasetConfig, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
throws IOException, WebApplicationException {
final String hostname;
if (httpHeaders.containsKey(WebServer.X_DREMIO_HOSTNAME)) {
hostname = (String) httpHeaders.getFirst(WebServer.X_DREMIO_HOSTNAME);
} else {
hostname = masterNode;
}
// Change headers to force download and suggest a filename.
String fullPath = Joiner.on(".").join(datasetConfig.getFullPathList());
httpHeaders.putSingle(HttpHeaders.CONTENT_DISPOSITION, format("attachment; filename=\"%s.tds\"", fullPath));
try {
final XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(entityStream, "UTF-8");
xmlStreamWriter.writeStartDocument("utf-8", "1.0");
writeDatasource(xmlStreamWriter, datasetConfig, hostname, mediaType);
xmlStreamWriter.writeEndDocument();
xmlStreamWriter.close();
} catch (XMLStreamException e) {
throw UserExceptionMapper.withStatus(
UserException.dataWriteError(e)
.message("Cannot generate TDS file")
.addContext("Details", e.getMessage()),
Status.INTERNAL_SERVER_ERROR
).build(logger);
}
}
示例14: getWholeForm
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
@POST
@Path("/wholeform")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public static String getWholeForm(final MultivaluedMap<String, String> form) {
return form.getFirst("test");
}
示例15: verifyNativeOutput
import javax.ws.rs.core.MultivaluedMap; //导入方法依赖的package包/类
@Test
public void verifyNativeOutput()
throws IOException, SAXException, ParserConfigurationException, ParseException {
Configuration configuration = mock(Configuration.class);
DatasetConfig datasetConfig = new DatasetConfig();
datasetConfig.setFullPathList(path.toPathList());
// create a schema to test the metadata output for native connectors
datasetConfig.setType(DatasetType.PHYSICAL_DATASET);
BatchSchema schema = BatchSchema.newBuilder()
.addField(new Field("string", FieldType.nullable(ArrowType.Utf8.INSTANCE), null))
.addField(new Field("bool", FieldType.nullable(ArrowType.Bool.INSTANCE), null))
.addField(new Field("decimal", FieldType.nullable(new ArrowType.Decimal(0, 0)), null))
.addField(new Field("int", FieldType.nullable(new ArrowType.Int(8, false)), null))
.addField(new Field("date", FieldType.nullable(new ArrowType.Date(DateUnit.MILLISECOND)), null))
.addField(new Field("time", FieldType.nullable(new ArrowType.Time(TimeUnit.MILLISECOND, 8)), null))
.build();
datasetConfig.setRecordSchema(schema.toByteString());
TableauMessageBodyGenerator generator = new TableauMessageBodyGenerator(configuration, NodeEndpoint.newBuilder().setAddress("foo").setUserPort(12345).build());
MultivaluedMap<String, Object> httpHeaders = new MultivaluedHashMap<>();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
assertTrue(generator.isWriteable(datasetConfig.getClass(), null, null, WebServer.MediaType.APPLICATION_TDS_DRILL_TYPE));
generator.writeTo(datasetConfig, DatasetConfig.class, null, new Annotation[] {}, WebServer.MediaType.APPLICATION_TDS_DRILL_TYPE, httpHeaders, baos);
// Convert the baos into a DOM Tree to verify content
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document document = factory.newDocumentBuilder().parse(new ByteArrayInputStream(baos.toByteArray()));
NodeList connections = document.getDocumentElement().getElementsByTagName("connection");
assertEquals(1, connections.getLength());
Element connection = (Element) connections.item(0);
assertEquals("drill", connection.getAttribute("class"));
assertEquals("Direct", connection.getAttribute("connection-type"));
assertEquals("foo", connection.getAttribute("server"));
assertEquals("12345", connection.getAttribute("port"));
assertEquals(path.toParentPath(), connection.getAttribute("schema"));
NodeList relations = connection.getElementsByTagName("relation");
assertEquals(1, relations.getLength());
Element relation = (Element) relations.item(0);
assertEquals("table", relation.getAttribute("type"));
assertEquals(tableName, relation.getAttribute("table"));
// metadata tests
NodeList metadataRecords = document.getDocumentElement().getElementsByTagName("metadata-record");
assertEquals(metadataRecords.getLength(), schema.getFieldCount());
assertEqualsMetadataRecord(metadataRecords.item(0), "[string]", "string");
assertEqualsMetadataRecord(metadataRecords.item(1), "[bool]", "boolean");
assertEqualsMetadataRecord(metadataRecords.item(2), "[decimal]", "real");
assertEqualsMetadataRecord(metadataRecords.item(3), "[int]", "integer");
assertEqualsMetadataRecord(metadataRecords.item(4), "[date]", "date");
assertEqualsMetadataRecord(metadataRecords.item(5), "[time]", "datetime");
// Also check that Content-Disposition header is set with a filename ending by tds
ContentDisposition contentDisposition = new ContentDisposition((String) httpHeaders.getFirst(HttpHeaders.CONTENT_DISPOSITION));
assertTrue("filename should end with .tds", contentDisposition.getFileName().endsWith(".tds"));
}