本文整理了Java中org.restlet.Request
类的一些代码示例,展示了Request
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request
类的具体详情如下:
包路径:org.restlet.Request
类名称:Request
[英]Generic request sent by client connectors. It is then received by server connectors and processed by Restlets. This request can also be processed by a chain of Restlets, on both client and server sides. Requests are uniform across all types of connectors, protocols and components.
[中]客户端连接器发送的通用请求。然后由服务器连接器接收,并由RESTlet处理。这个请求也可以由客户端和服务器端的RESTlet链来处理。所有类型的连接器、协议和组件的请求都是统一的。
代码示例来源:origin: org.apache.polygene.libraries/org.apache.polygene.library.rest-server
private boolean shouldShowCommandForm( Method interactionMethod )
{
// Show form on GET/HEAD
if( Request.getCurrent().getMethod().isSafe() )
{
return true;
}
if( interactionMethod.getParameterTypes().length > 0 )
{
return !( interactionMethod.getParameterTypes()[ 0 ].equals( Response.class ) || Request.getCurrent()
.getEntity()
.isAvailable() || Request.getCurrent().getEntityAsText() != null || Request.getCurrent()
.getResourceRef()
.getQuery() != null );
}
return false;
}
代码示例来源:origin: uber/chaperone
public Representation post(Representation entity) {
try {
final String topicName = (String) getRequest().getAttributes().get("topicName");
String jsonRequest = entity.getText();
TopicPartition topicPartitionInfo = null;
if ((jsonRequest == null || jsonRequest.isEmpty()) && topicName != null
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
return new StringRepresentation(String.format(
"Failed to add new topic: %s, it is already existed!", topicPartitionInfo.getTopic()));
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation(
String.format("Failed to add new topic, with exception: %s", e));
代码示例来源:origin: stackoverflow.com
Filter preferencesFilter = new Filter(getContext()) {
protected int beforeHandle(Request request, Response response) {
if (request.getClientInfo().getAcceptedMediaTypes().isEmpty()) {
request.getClientInfo().accept(MediaType.APPLICATION_JSON);
} else if ((request.getClientInfo().getAcceptedMediaTypes().size() == 1)
&& (request.getClientInfo().getAcceptedMediaTypes().get(0).getMetadata().equals(MediaType.ALL))) {
request.getClientInfo().accept(MediaType.APPLICATION_JSON);
}
return super.beforeHandle(request, response);
}
}
代码示例来源:origin: uber/chaperone
public Request getTopicCreationRequestUrl(String topic, int numPartitions) {
Request request = new Request(Method.POST, _baseUrl + "/topics/");
TopicPartition topicPartitionInfo = new TopicPartition(topic, numPartitions);
request.setEntity(topicPartitionInfo.toJSON().toJSONString(), MediaType.APPLICATION_JSON);
return request;
}
代码示例来源:origin: org.restlet.jee/org.restlet.ext.jaxrs
/**
* @see org.restlet.ext.jaxrs.internal.wrappers.params.ParameterList.ParamGetter#getValue()
*/
public Object getValue() throws InvocationTargetException,
ConvertRepresentationException, WebApplicationException {
return Request.getCurrent().getEntity();
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Indicates if the request entity should be chunked.
*
* @return True if the request should be chunked
*/
protected boolean shouldRequestBeChunked(Request request) {
return request.isEntityAvailable()
&& (request.getEntity() != null)
&& !request.getEntity().hasKnownSize();
}
}
代码示例来源:origin: jtalks-org/jcommune
private void addHeaderAttribute(ClientResource clientResource, String attrName, String attrValue) {
ConcurrentMap<String, Object> attrs = clientResource.getRequest().getAttributes();
Series<Header> headers = (Series<Header>) attrs.get(HeaderConstants.ATTRIBUTE_HEADERS);
if (headers == null) {
headers = new Series<>(Header.class);
Series<Header> prev = (Series<Header>) attrs.putIfAbsent(HeaderConstants.ATTRIBUTE_HEADERS, headers);
if (prev != null) {
headers = prev;
}
}
headers.add(attrName, attrValue);
}
代码示例来源:origin: uber/chaperone
@Override
@Delete
public Representation delete() {
final String topicName = (String) getRequest().getAttributes().get("topicName");
if (_autoTopicWhitelistingManager != null) {
_autoTopicWhitelistingManager.addIntoBlacklist(topicName);
}
if (!_helixMirrorMakerManager.isTopicExisted(topicName)) {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
return new StringRepresentation(
String.format("Failed to delete not existed topic: %s", topicName));
}
try {
_helixMirrorMakerManager.deleteTopicInMirrorMaker(topicName);
return new StringRepresentation(
String.format("Successfully finished delete topic: %s", topicName));
} catch (Exception e) {
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
LOGGER.error("Failed to delete topic: {}, with exception: {}", topicName, e);
return new StringRepresentation(
String.format("Failed to delete topic: %s, with exception: %s", topicName, e));
}
}
代码示例来源:origin: org.restlet.jse/org.restlet.example
@Override
public void handle(Request request, Response response) {
// Print the user name of the requested orders
String message = "Order \""
+ request.getAttributes().get("order")
+ "\" for user \""
+ request.getAttributes().get("user") + "\"";
response.setEntity(message, MediaType.TEXT_PLAIN);
}
};
代码示例来源:origin: uber/chaperone
@Override
@Get
public Representation get() {
final String opt = (String) getRequest().getAttributes().get("opt");
if ("disable_autobalancing".equalsIgnoreCase(opt)) {
_helixMirrorMakerManager.disableAutoBalancing();
LOGGER.info("Disabled autobalancing!");
return new StringRepresentation("Disabled autobalancing!\n");
} else if ("enable_autobalancing".equalsIgnoreCase(opt)) {
_helixMirrorMakerManager.enableAutoBalancing();
LOGGER.info("Enabled autobalancing!");
return new StringRepresentation("Enabled autobalancing!\n");
}
LOGGER.info("No valid input!");
return new StringRepresentation("No valid input!\n");
}
代码示例来源:origin: jtalks-org/jcommune
@SuppressWarnings("unchecked")
private void writeRequestInfoToLog(ClientResource clientResource) {
ConcurrentMap<String, Object> attrs = clientResource.getRequest().getAttributes();
Series<Header> headers = (Series<Header>) attrs.get(HeaderConstants.ATTRIBUTE_HEADERS);
logger.info("Request to Poulpe: requested URI - {}, request headers - {}, request body - {}",
new Object[]{clientResource.getRequest().getResourceRef(), headers, clientResource.getRequest()});
}
代码示例来源:origin: org.restlet.osgi/org.restlet
@Override
protected void handleLocal(Request request, Response response,
String decodedPath) {
String scheme = request.getResourceRef().getScheme();
if (scheme.equalsIgnoreCase(Protocol.CLAP.getSchemeName())) {
LocalReference cr = new LocalReference(request.getResourceRef());
ClassLoader classLoader = null;
Object classLoaderAttribute = request.getAttributes().get(
"org.restlet.clap.classLoader");
代码示例来源:origin: org.restlet.jse/org.restlet.example
public static void main(String[] args) throws Exception {
// Prepare the request
Request request = new Request(Method.GET,
"http://s3.amazonaws.com/quotes/nelson");
request.setChallengeResponse(new ChallengeResponse(
ChallengeScheme.HTTP_AWS_S3, "44CF9590006BF252F707",
"OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV"));
// Add some extra headers
Series<Header> extraHeaders = new Series<Header>(Header.class);
extraHeaders.add("X-Amz-Meta-Author", "foo@bar.com");
extraHeaders.add("X-Amz-Magic", "abracadabra");
// For the test we hard coded a special date header. Normally you don't
// need this as the
// HTTP client connector will automatically provide an accurate Date
// header and use it
// for authentication.
// extraHeaders.add("X-Amz-Date", "Thu, 17 Nov 2005 18:49:58 GMT");
request.getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS,
extraHeaders);
// Handle it using an HTTP client connector
Client client = new Client(Protocol.HTTP);
Response response = client.handle(request);
// Write the response entity on the console
Representation output = response.getEntity();
output.write(System.out);
}
代码示例来源:origin: org.restlet.jee/org.restlet.ext.net
@Override
public void handle(Request request, Response response) {
try {
if (Protocol.FTP.equals(request.getProtocol())) {
if (Method.GET.equals(request.getMethod())) {
Reference ftpRef = request.getResourceRef();
String userInfo = null;
if ((request.getChallengeResponse() != null)
&& ChallengeScheme.FTP_PLAIN.equals(request
.getChallengeResponse().getScheme())
&& (request.getChallengeResponse().getIdentifier() != null)) {
userInfo = request.getChallengeResponse()
.getIdentifier();
if (request.getChallengeResponse().getSecret() != null) {
userInfo += ":"
+ new String(request.getChallengeResponse()
.getSecret());
ftpRef.setUserInfo(userInfo);
Entity.updateMetadata(request.getResourceRef().getPath(),
response.getEntity(), true, getMetadataService());
} else {
getLogger()
response.setStatus(Status.CONNECTOR_ERROR_INTERNAL, e.getMessage());
代码示例来源:origin: org.restlet.gae/org.restlet.ext.platform
/**
* Generates a CallLog for the request and adds it to the buffer.
*
* @param request
* The Request object associated with the request.
* @param response
* The Response object associated with the request.
* @param duration
* The duration of the request in milliseconds.
* @param startTime
* The time at which the request arrived to the agent as an
* epoch.
*/
public void addCallLogToBuffer(Request request, Response response,
int duration, long startTime) {
CallLog callLog = new CallLog();
callLog.setDate(new Date(startTime));
callLog.setDuration(duration);
callLog.setMethod(request.getMethod().getName());
callLog.setPath(request.getResourceRef().getPath());
callLog.setRemoteIp(request.getClientInfo().getUpstreamAddress());
callLog.setStatusCode(response.getStatus().getCode());
callLog.setUserAgent(request.getClientInfo().getAgent());
callLog.setUserToken((request.getClientInfo().getUser() == null) ? ""
: request.getClientInfo().getUser().getIdentifier());
callLogs.add(callLog);
if (callLogs.size() >= bufferSize) {
flushLogs();
}
}
代码示例来源:origin: org.restlet.jse/org.restlet.ext.json
/**
* Assumes that there is a "callback" query parameter available in the URI
* query string, containing the name of the JavaScript callback method.
*/
@Override
public void afterHandle(Request request, Response response) {
// Check the presence of the callback parameter
String callback = request.getResourceRef().getQueryAsForm()
.getFirstValue("callback");
if (callback != null) {
Representation entity = response.getEntity();
if (entity != null
&& ("text".equals(entity.getMediaType().getMainType()) || MediaType.APPLICATION_JSON
.equals(entity.getMediaType()))) {
response.setEntity(new JsonpRepresentation(callback, response
.getStatus(), response.getEntity()));
response.setStatus(Status.SUCCESS_OK);
}
}
}
代码示例来源:origin: org.restlet.osgi/org.restlet
@Override
protected void afterHandle(Request request, Response response) {
if (getRangeService().isEnabled()) {
response.getServerInfo().setAcceptingRanges(true);
if (request.getMethod().isSafe() && response.isEntityAvailable()) {
Range responseRange = response.getEntity().getRange();
boolean rangedEntity = responseRange != null && isBytesRange(responseRange);
if (request.getRanges().size() == 1
&& (!request.getConditions().hasSomeRange()
|| request.getConditions().getRangeStatus(response.getEntity()).isSuccess())) {
Range requestedRange = request.getRanges().get(0);
if ((!response.getEntity().hasKnownSize())
&& ((requestedRange.getIndex() == Range.INDEX_LAST
|| requestedRange.getSize() == Range.SIZE_MAX)
if (response.getEntity().hasKnownSize()
&& requestedRange.getSize() > response.getEntity().getAvailableSize()) {
requestedRange.setSize(Range.SIZE_MAX);
response.setStatus(Status.SUCCESS_PARTIAL_CONTENT);
} else if (request.getRanges().size() > 1) {
response.setStatus(Status.SERVER_ERROR_NOT_IMPLEMENTED);
代码示例来源:origin: org.restlet.osgi/org.restlet
ClientCall httpCall) {
response.setStatus(status);
response.getServerInfo().setAddress(httpCall.getServerAddress());
response.getServerInfo().setPort(httpCall.getServerPort());
if (response.getEntity() != null) {
if (response.getEntity().isEmpty()) {
response.getEntity().release();
} else if (response.getRequest().getMethod().equals(Method.HEAD)) {
response.getEntity().release();
} else if (response.getStatus().equals(Status.SUCCESS_NO_CONTENT)) {
response.getEntity().release();
} else if (response.getStatus()
.equals(Status.SUCCESS_RESET_CONTENT)) {
response.getEntity().release();
response.setEntity(null);
} else if (response.getStatus().equals(
Status.REDIRECTION_NOT_MODIFIED)) {
response.getEntity().release();
代码示例来源:origin: org.restlet.jse/org.restlet.example
@Override
public void challenge(Response response, boolean stale) {
// Load the FreeMarker template
Representation ftl = new ClientResource(
LocalReference.createClapReference(getClass().getPackage())
+ "/Login.ftl").get();
// Wraps the bean with a FreeMarker representation
response.setEntity(new TemplateRepresentation(ftl, response
.getRequest().getResourceRef(), MediaType.TEXT_HTML));
response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
}
代码示例来源:origin: org.qi4j.library/org.qi4j.library.rest-server
private String getUsecaseName( Request request )
{
if( request.getMethod().equals( org.restlet.data.Method.DELETE ) )
{
return "delete";
}
else
{
return request.getResourceRef().getLastSegment();
}
}
内容来源于网络,如有侵权,请联系作者删除!