本文整理汇总了Java中org.restlet.util.Series.getFirstValue方法的典型用法代码示例。如果您正苦于以下问题:Java Series.getFirstValue方法的具体用法?Java Series.getFirstValue怎么用?Java Series.getFirstValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.restlet.util.Series
的用法示例。
在下文中一共展示了Series.getFirstValue方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: request
import org.restlet.util.Series; //导入方法依赖的package包/类
@Get("json")
public String request(final String entity)
{
try
{
final JSONObject answer = new JSONObject();
answer.put("version", RevisionHelper.getVerboseRevision());
answer.put("system_UUID", getSetting("system_UUID",""));
final Series<Parameter> ctxParams = getContext().getParameters();
final String hostId = ctxParams.getFirstValue("HOST_ID");
if (hostId != null)
answer.put("host",hostId);
return answer.toString();
}
catch (JSONException e)
{
e.printStackTrace();
return null;
}
}
示例2: request
import org.restlet.util.Series; //导入方法依赖的package包/类
@Get("json")
public String request(final String entity)
{
addAllowOrigin();
try
{
final JSONObject answer = new JSONObject();
answer.put("version", RevisionHelper.getVerboseRevision());
answer.put("system_UUID", getSetting("system_UUID",""));
final Series<Parameter> ctxParams = getContext().getParameters();
final String hostId = ctxParams.getFirstValue("HOST_ID");
if (hostId != null)
answer.put("host",hostId);
return answer.toString();
}
catch (JSONException e)
{
e.printStackTrace();
return null;
}
}
示例3: processHeaders
import org.restlet.util.Series; //导入方法依赖的package包/类
/**
* Updates the request method based on specific header.
*
* @param request
* The request to update.
*/
@SuppressWarnings("unchecked")
private void processHeaders(Request request) {
final TunnelService tunnelService = getTunnelService();
if (tunnelService.isMethodTunnel()) {
// get the headers
Series<Header> extraHeaders = (Series<Header>) request
.getAttributes().get(HeaderConstants.ATTRIBUTE_HEADERS);
if (extraHeaders != null) {
// look for the new value of the method
final String newMethodValue = extraHeaders.getFirstValue(
getTunnelService().getMethodHeader(), true);
if (newMethodValue != null
&& newMethodValue.trim().length() > 0) {
// set the current method to the new method
request.setMethod(Method.valueOf(newMethodValue));
}
}
}
}
示例4: createContentType
import org.restlet.util.Series; //导入方法依赖的package包/类
/**
* Creates a content type.
*
* @param mediaType
* The media type name.
* @param parameters
* The parameters parsed.
* @return The content type.
*/
private ContentType createContentType(StringBuilder mediaType,
Series<Parameter> parameters) {
// Attempt to extract the character set
CharacterSet characterSet = null;
if (parameters != null) {
String charSet = parameters.getFirstValue("charset");
if (charSet != null) {
parameters.removeAll("charset");
characterSet = new CharacterSet(charSet);
}
return new ContentType(new MediaType(mediaType.toString(),
parameters), characterSet);
}
return new ContentType(new MediaType(mediaType.toString()), null);
}
示例5: getOriginalRef
import org.restlet.util.Series; //导入方法依赖的package包/类
/**
* Returns the original reference especially by detecting potential proxy forwardings.
*
* @param resourceRef
* The request's resource reference.
* @param headers
* The set of request's headers.
* @return The original reference.
*/
public static Reference getOriginalRef(Reference resourceRef, Series<Header> headers) {
Reference originalRef = resourceRef.getTargetRef();
if (headers == null) {
return originalRef;
}
String value = headers.getFirstValue(HeaderConstants.HEADER_X_FORWARDED_PORT);
if (value != null) {
originalRef.setHostPort(Integer.parseInt(value));
}
value = headers.getFirstValue(HeaderConstants.HEADER_X_FORWARDED_PROTO);
if (value != null) {
originalRef.setScheme(value);
}
return originalRef;
}
示例6: getIP
import org.restlet.util.Series; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public String getIP()
{
final Series<Header> headers = (Series<Header>) getRequest().getAttributes().get("org.restlet.http.headers");
final String realIp = headers.getFirstValue("X-Real-IP", true);
if (realIp != null)
return realIp;
else
return getRequest().getClientInfo().getAddress();
}
示例7: getURL
import org.restlet.util.Series; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Reference getURL()
{
final Series<Header> headers = (Series<Header>) getRequest().getAttributes().get("org.restlet.http.headers");
final String realURL = headers.getFirstValue("X-Real-URL", true);
if (realURL != null)
return new Reference(realURL);
else
return getRequest().getOriginalRef();
}
示例8: formatResponse
import org.restlet.util.Series; //导入方法依赖的package包/类
@Override
public void formatResponse(ChallengeWriter cw, ChallengeResponse challenge,
Request request, Series<Header> httpHeaders) {
// Setup the Date header
String date = "";
if (httpHeaders.getFirstValue("x-ms-date", true) == null) {
// X-ms-Date header didn't override the standard Date header
date = httpHeaders.getFirstValue(HeaderConstants.HEADER_DATE, true);
if (date == null) {
// Add a fresh Date header
date = DateUtils.format(new Date(),
DateUtils.FORMAT_RFC_1123.get(0));
httpHeaders.add(HeaderConstants.HEADER_DATE, date);
}
} else {
date = httpHeaders.getFirstValue("x-ms-date", true);
}
// Setup the canonicalized path
String canonicalizedResource = getCanonicalizedResourceName(request
.getResourceRef());
// Setup the message part
StringBuilder rest = new StringBuilder();
rest.append(date).append('\n').append('/')
.append(challenge.getIdentifier())
.append(canonicalizedResource);
// Append the SharedKey credentials
cw.append(challenge.getIdentifier())
.append(':')
.append(Base64.encode(
DigestUtils.toHMacSha256(rest.toString(),
Base64.decode(challenge.getSecret())), true));
}
示例9: verify
import org.restlet.util.Series; //导入方法依赖的package包/类
@Override
public int verify(Request request, Response response) {
if (request.getChallengeResponse() == null)
return RESULT_MISSING;
@SuppressWarnings("unchecked")
Series<Header> headers = (Series<Header>) request.getAttributes().get(
HeaderConstants.ATTRIBUTE_HEADERS);
String userId = getIdentifier(request, response);
if (userId == null || (userId.length() == 0))
return RESULT_MISSING;
// A date header is always required
if (headers.getFirstValue(HeaderConstants.HEADER_DATE, true) == null)
return RESULT_INVALID;
// Make sure the date is not stale
if (getMaxRequestAge() > 0) {
Long date = DateUtils.parse(
headers.getFirstValue(HeaderConstants.HEADER_DATE, true))
.getTime();
Long now = System.currentTimeMillis();
if (now - date > getMaxRequestAge())
return RESULT_STALE;
}
char[] userSecret = getLocalSecret(userId);
char[] signature = getSecret(request, response);
String sigToCompare = AwsUtils.getS3Signature(request, userSecret);
if (!compare(signature, sigToCompare.toCharArray()))
return RESULT_INVALID;
request.getClientInfo().setUser(new User(userId));
return RESULT_VALID;
}
示例10: isChunkedEncoding
import org.restlet.util.Series; //导入方法依赖的package包/类
/**
* Indicates if the entity is chunked.
*
* @return True if the entity is chunked.
*/
public static boolean isChunkedEncoding(Series<Header> headers) {
boolean result = false;
if (headers != null) {
final String header = headers.getFirstValue(
HeaderConstants.HEADER_TRANSFER_ENCODING, true);
result = "chunked".equalsIgnoreCase(header);
}
return result;
}
示例11: isConnectionClose
import org.restlet.util.Series; //导入方法依赖的package包/类
/**
* Indicates if the connection must be closed.
*
* @param headers
* The headers to test.
* @return True if the connection must be closed.
*/
public static boolean isConnectionClose(Series<Header> headers) {
boolean result = false;
if (headers != null) {
String header = headers.getFirstValue(
HeaderConstants.HEADER_CONNECTION, true);
result = "close".equalsIgnoreCase(header);
}
return result;
}
示例12: getResponseEntity
import org.restlet.util.Series; //导入方法依赖的package包/类
/**
* Returns the response entity if available. Note that no metadata is
* associated by default, you have to manually set them from your headers.
*
* @param response
* the Response to get the entity from
* @return The response entity if available.
*/
public Representation getResponseEntity(Response response) {
Representation result = null;
// boolean available = false;
long size = Representation.UNKNOWN_SIZE;
// Compute the content length
Series<Header> responseHeaders = getResponseHeaders();
String transferEncoding = responseHeaders.getFirstValue(
HeaderConstants.HEADER_TRANSFER_ENCODING, true);
if ((transferEncoding != null)
&& !Encoding.IDENTITY.getName().equalsIgnoreCase(
transferEncoding)) {
size = Representation.UNKNOWN_SIZE;
} else {
size = getContentLength();
}
if (!getMethod().equals(Method.HEAD.getName())
&& !response.getStatus().isInformational()
&& !response.getStatus()
.equals(Status.REDIRECTION_NOT_MODIFIED)
&& !response.getStatus().equals(Status.SUCCESS_NO_CONTENT)
&& !response.getStatus().equals(Status.SUCCESS_RESET_CONTENT)) {
// Make sure that an InputRepresentation will not be instantiated
// while the stream is closed.
InputStream stream = getUnClosedResponseEntityStream(getResponseEntityStream(size));
if (stream != null) {
result = getRepresentation(stream);
}
}
if (result != null) {
result.setSize(size);
// Informs that the size has not been specified in the header.
if (size == Representation.UNKNOWN_SIZE) {
getLogger()
.debug("The length of the message body is unknown. The entity must be handled carefully and consumed entirely in order to surely release the connection.");
}
}
result = HeaderUtils.extractEntityHeaders(responseHeaders, result);
return result;
}
示例13: getS3StringToSign
import org.restlet.util.Series; //导入方法依赖的package包/类
/**
* Returns the S3 string to sign.
*
* @param request
* The request to generate the signature string from
* @param headers
* The HTTP headers associated with the request
* @return The string to sign
*/
public static String getS3StringToSign(Request request,
Series<Header> headers) {
String canonicalizedAmzHeaders = getCanonicalizedAmzHeaders(headers);
String canonicalizedResource = getCanonicalizedResourceName(request
.getResourceRef());
String contentMD5 = (headers == null) ? null : headers.getFirstValue(
HeaderConstants.HEADER_CONTENT_MD5, true);
String contentType = (headers == null) ? null : headers.getFirstValue(
HeaderConstants.HEADER_CONTENT_TYPE, true);
String date = (headers == null) ? null : headers.getFirstValue(
"X-Amz-Date", true);
String method = request.getMethod().getName();
// If amazon's date header wasn't found try to grab the regular date
// header
if (date == null || (date.length() == 0)) {
date = (headers == null) ? null : headers.getFirstValue(
HeaderConstants.HEADER_DATE, true);
}
// If no date header exists make one
if (date == null || (date.length() == 0)) {
date = DateUtils.format(new Date(),
DateUtils.FORMAT_RFC_1123.get(0));
if (headers != null) {
headers.add(HeaderConstants.HEADER_DATE, date);
}
}
if (contentType == null || (contentType.length() == 0)) {
boolean applyPatch = false;
// This patch seems to apply to Sun JVM only.
final String jvmVendor = System.getProperty("java.vm.vendor");
if ((jvmVendor != null)
&& (jvmVendor.toLowerCase()).startsWith("sun")) {
final int majorVersionNumber = SystemUtils
.getJavaMajorVersion();
final int minorVersionNumber = SystemUtils
.getJavaMinorVersion();
if (majorVersionNumber == 1) {
if (minorVersionNumber < 5) {
applyPatch = true;
} else if (minorVersionNumber == 5) {
// Sun fixed the bug in update 10
applyPatch = (SystemUtils.getJavaUpdateVersion() < 10);
}
}
}
if (applyPatch && !request.getMethod().equals(Method.PUT))
contentType = "application/x-www-form-urlencoded";
}
StringBuilder toSign = new StringBuilder();
toSign.append(method != null ? method : "").append("\n");
toSign.append(contentMD5 != null ? contentMD5 : "").append("\n");
toSign.append(contentType != null ? contentType : "").append("\n");
toSign.append(date != null ? date : "").append("\n");
toSign.append(canonicalizedAmzHeaders != null ? canonicalizedAmzHeaders
: "");
toSign.append(canonicalizedResource != null ? canonicalizedResource
: "");
return toSign.toString();
}
示例14: formatResponse
import org.restlet.util.Series; //导入方法依赖的package包/类
@Override
public void formatResponse(ChallengeWriter cw, ChallengeResponse challenge,
Request request, Series<Header> httpHeaders) {
// Setup the method name
final String methodName = request.getMethod().getName();
// Setup the Date header
String date = "";
if (httpHeaders.getFirstValue("x-ms-date", true) == null) {
// X-ms-Date header didn't override the standard Date header
date = httpHeaders.getFirstValue(HeaderConstants.HEADER_DATE, true);
if (date == null) {
// Add a fresh Date header
date = DateUtils.format(new Date(),
DateUtils.FORMAT_RFC_1123.get(0));
httpHeaders.add(HeaderConstants.HEADER_DATE, date);
}
}
// Setup the ContentType header
String contentMd5 = httpHeaders.getFirstValue(
HeaderConstants.HEADER_CONTENT_MD5, true);
if (contentMd5 == null) {
contentMd5 = "";
}
// Setup the ContentType header
String contentType = httpHeaders.getFirstValue(
HeaderConstants.HEADER_CONTENT_TYPE, true);
if (contentType == null) {
boolean applyPatch = false;
// This patch seems to apply to Sun JVM only.
final String jvmVendor = System.getProperty("java.vm.vendor");
if ((jvmVendor != null)
&& (jvmVendor.toLowerCase()).startsWith("sun")) {
final int majorVersionNumber = SystemUtils
.getJavaMajorVersion();
final int minorVersionNumber = SystemUtils
.getJavaMinorVersion();
if (majorVersionNumber == 1) {
if (minorVersionNumber < 5) {
applyPatch = true;
} else if (minorVersionNumber == 5) {
// Sun fixed the bug in update 10
applyPatch = (SystemUtils.getJavaUpdateVersion() < 10);
}
}
}
if (applyPatch && !request.getMethod().equals(Method.PUT)) {
contentType = "application/x-www-form-urlencoded";
} else {
contentType = "";
}
}
// Setup the canonicalized AzureHeaders
final String canonicalizedAzureHeaders = getCanonicalizedAzureHeaders(httpHeaders);
// Setup the canonicalized path
final String canonicalizedResource = getCanonicalizedResourceName(request
.getResourceRef());
// Setup the message part
final StringBuilder rest = new StringBuilder();
rest.append(methodName).append('\n').append(contentMd5).append('\n')
.append(contentType).append('\n').append(date).append('\n')
.append(canonicalizedAzureHeaders).append('/')
.append(challenge.getIdentifier())
.append(canonicalizedResource);
// Append the SharedKey credentials
cw.append(challenge.getIdentifier())
.append(':')
.append(Base64.encode(
DigestUtils.toHMacSha256(rest.toString(),
Base64.decode(challenge.getSecret())), true));
}