本文整理汇总了Java中org.simpleframework.http.Request类的典型用法代码示例。如果您正苦于以下问题:Java Request类的具体用法?Java Request怎么用?Java Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Request类属于org.simpleframework.http包,在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doHandle
import org.simpleframework.http.Request; //导入依赖的package包/类
/**
* Handle the HTTP request
*
* @param req the HTTP request.
* @param response where the HTTP response is written to.
* @throws RequestHandlingException thrown if the request could not be handled.
*/
private void doHandle(Request req, OutputStream response)
throws RequestHandlingException, RequestHandlers.RequestNotAuthorizedException {
String requestPath = req.getAddress().getPath().getPath();
// Ignore this, don't even log it.
if (requestPath.equals("/favicon.ico")) {
return;
}
LOG.info("Request Path: " + requestPath);
if (!requestPath.startsWith("/")) {
throw new RequestHandlingException("Cannot handle request: " + requestPath);
}
// Remove slash prefix.
mRequestHandlers.handleRequest(req.getAddress(), response);
}
示例2: removeAutoScalePolicy
import org.simpleframework.http.Request; //导入依赖的package包/类
private String removeAutoScalePolicy(Request request) {
String result = "";
Query query = request.getQuery();
String loadBalancerId = query.get("loadBalancerId");
if(loadBalancerId != null) {
// Remove Policy
storage.removeLoadBalancer(loadBalancerId);
log.debug("AutoScaling Policy to LoadBalancer "+loadBalancerId+" removed");
result = listLoadBalancer();
}
else {
result = "Could not remove AutoScaling Policy to LoadBalancer "+loadBalancerId+" - Missing Parameter";
log.error(result);
}
return result;
}
示例3: createServer
import org.simpleframework.http.Request; //导入依赖的package包/类
public static ServerCriteria createServer() throws Exception {
Container container = new Container() {
public void handle(Request request, Response response) {
try {
PrintStream out = response.getPrintStream();
response.setValue("Content-Type", "text/plain");
response.setValue("Connection", "close");
out.print("TEST " + new Date());
response.close();
}catch(Exception e) {
e.printStackTrace();
try {
response.close();
}catch(Exception ex) {
ex.printStackTrace();
}
}
}
};
ContainerServer server = new ContainerServer(container);
Connection connection = new SocketConnection(server);
InetSocketAddress address = (InetSocketAddress)connection.connect(null); // ephemeral port
return new ServerCriteria(connection, address);
}
示例4: getResponseParams
import org.simpleframework.http.Request; //导入依赖的package包/类
ResponseParams getResponseParams(Request req, String path) {
for (Map.Entry<RequestParams, ResponseParams> response : responses) {
if (response.getKey().matches(req)) {
return response.getValue();
}
}
String adjustedPath = path;
if (configReader.isFolder(adjustedPath)) {
adjustedPath += "/index.html";
}
if (getInputStreamOrNull(adjustedPath) != null) {
return new ResponseParams(adjustedPath, true, Collections.EMPTY_MAP);
}
LOGGER.warning("No response found for " + path + " : returning 404");
return new ResponseParams(404, "", DefaultValues.PARAMS, false, Collections.EMPTY_MAP);
}
示例5: handle
import org.simpleframework.http.Request; //导入依赖的package包/类
@Override
public void handle(Request request, Response response) {
PrintStream body = null;
try {
body = response.getPrintStream();
// Validate the request credentials
Credentials credentials = Decoder.decode(request, this.requestConfiguration);
validate(credentials);
// And we're done
response.setCode(ClientResponse.Status.OK.getStatusCode());
} catch (Exception e) {
e.printStackTrace();
response.setCode(ClientResponse.Status.INTERNAL_SERVER_ERROR.getStatusCode());
} finally {
// The response body has to be explicitly closed in order for this method to return a response
if (body != null) {
body.close();
}
}
}
示例6: handle
import org.simpleframework.http.Request; //导入依赖的package包/类
@Override
public void handle(Request req, Response resp) {
final String requestUrl = req.getAddress().toString();
// Ignore favicon requests.
if ("/favicon.ico".equals(requestUrl)) {
resp.setStatus(Status.NOT_FOUND);
return;
}
LOG.info("Request: " + requestUrl);
Optional<String> returnValue = Optional.empty();
if (requestUrl.startsWith(IO_PREFIX)) {
returnValue = handleIoRequest(requestUrl.substring(IO_PREFIX.length()));
}
try {
resp.setStatus(returnValue.isPresent() ? Status.OK : Status.NOT_FOUND);
resp.getPrintStream().append(returnValue.isPresent() ? returnValue.get() : "");
resp.close();
} catch (final IOException e) {
LOG.warn("Could not deliver response");
}
LOG.debug("Request handled");
}
示例7: formatRequest
import org.simpleframework.http.Request; //导入依赖的package包/类
/** Format the HTTP request path as a multiline string. */
public String formatRequest(Request request) {
Query query = request.getQuery();
// poss. optimization, but how to use it?:
boolean persistent = request.isKeepAlive();
Path path = request.getPath();
String directory = path.getDirectory();
String name = path.getName();
String[] segments = path.getSegments();
return "Query: " + query + (persistent ? " (persistent)\n" : "\n")
+ "Path: " + path + " (" + segments.length + " segments)\n"
+ "Directory: " + directory + "\n"
+ "Name: " + name + "\n";
}
示例8: handle
import org.simpleframework.http.Request; //导入依赖的package包/类
/** Dispatch a GET or POST request to the appropriate handler.
* FUTURE Explore Simple's asynchronous response mode.
* See "asynchronous services" here:
* http://www.simpleframework.org/doc/tutorial/tutorial.php
*/
public void handle(Request request, Response response) {
try {
String method = request.getMethod();
if(method.equals("POST") || method.equals("PUT")) {
this.handlePost(request, response);
} else if(method.equals("GET")) {
this.handleGet(request, response);
} else {
this.handleUnsupportedMethod(request, response);
}
} catch(Throwable t) {
// Desperately try to stay afloat, but don't try to write
// the response, because this error may have arisen from an
// attempt to respond.
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
log("Uncaught error in request " + (requestIndex - 1)
+ ": " + t + '\n' + sw);
}
}
示例9: handle
import org.simpleframework.http.Request; //导入依赖的package包/类
public void handle(Request request, Response response) {
try {
int request_number = ++total_requests;
log.info("Request " + request_number + " from " + request.getClientAddress().getHostName());
long time = System.currentTimeMillis();
response.setValue("Content-Type", "text/xml");
response.setValue("Server", "Stanford CoreNLP XML Server/1.0 (Simple 5.1.6)");
response.setDate("Date", time);
response.setDate("Last-Modified", time);
// pass "text" POST query to Stanford Core NLP parser
String text = request.getQuery().get("text");
PrintStream body = response.getPrintStream();
body.println(parse(text));
body.close();
long time2 = System.currentTimeMillis();
log.info("Request " + request_number + " done (" + (time2-time) + " ms)");
} catch(Exception e) {
log.log(Level.SEVERE, "Exception", e);
}
}
示例10: AsyncTask
import org.simpleframework.http.Request; //导入依赖的package包/类
public AsyncTask(Request request, Response response,
RequestHandlerImpl handler,
List<Subscriber> subscribers,
String responseContentType, ResponseBody responseBody,
MarshallerProvider marshallerProvider,
UnmarshallerProvider unmarshallerProvider) {
this.subscriberRequest = request;
this.subscriberResponse = response;
this.handler = handler;
this.subscribers = subscribers;
this.responseContentType = responseContentType;
this.responseBody = responseBody;
this.marshallerProvider = marshallerProvider;
this.unmarshallerProvider = unmarshallerProvider;
}
示例11: getPathParameter
import org.simpleframework.http.Request; //导入依赖的package包/类
@Test
public void getPathParameter() {
Request request = mock(Request.class);
Path path = mock(Path.class);
when(path.getPath()).thenReturn("/first-name/John/last-name/Doe");
when(request.getPath()).thenReturn(path);
Route route = new Route("/first-name/:firstName/last-name/:lastName");
SimpleHttpRequest req = new SimpleHttpRequest(request, null, route, null);
assertEquals("John", req.getPathParameter("firstName"));
assertEquals("Doe", req.getPathParameter("lastName"));
assertNull(req.getPathParameter("nonExistentPathParam"));
}
示例12: handle
import org.simpleframework.http.Request; //导入依赖的package包/类
/**
* Handle the incoming request on the tracker service.
*
* <p>
* This makes sure the request is made to the tracker's announce URL, and
* delegates handling of the request to the <em>process()</em> method after
* preparing the response object.
* </p>
*
* @param request The incoming HTTP request.
* @param response The response object.
*/
public void handle(Request request, Response response) {
// Reject non-announce requests
if (!Tracker.ANNOUNCE_URL.equals(request.getPath().toString())) {
response.setCode(404);
response.setText("Not Found");
return;
}
OutputStream body = null;
try {
body = response.getOutputStream();
this.process(request, response, body);
body.flush();
} catch (IOException ioe) {
logger.warn("Error while writing response: {}!", ioe.getMessage());
} finally {
IOUtils.closeQuietly(body);
}
}
示例13: handle
import org.simpleframework.http.Request; //导入依赖的package包/类
public void handle(Request request, Response response) {
try {
String path = request.getPath().getPath();
String method = request.getMethod();
if ("/users".equals(path) && "POST".equals(method))
this.createUser(request, response);
else if ("/projects".equals(path) && "POST".equals(method))
this.createProject(request, response);
else if ("/users".equals(path) && "GET".equals(method))
this.getAllUsers(response);
else if ("/issues".equals(path) && "GET".equals(method))
this.getAllIssues(response);
else if ("/projects".equals(path) && "GET".equals(method))
this.getAllProjects(response);
else
this.notFound(response);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
示例14: handle
import org.simpleframework.http.Request; //导入依赖的package包/类
public void handle(Request request, Response response) {
try {
String path = request.getPath().getPath();
String method = request.getMethod();
if ("/messages".equals(path) && "GET".equals(method))
this.getAll(response);
else if ("/messages".equals(path) && "POST".equals(method))
this.post(request, response);
else if (isMsgAccess(path) && "GET".equals(method))
this.get(getId(path), response);
else if (isMsgAccess(path) && "PUT".equals(method))
this.put(getId(path), request, response);
else if (isMsgAccess(path) && "DELETE".equals(method))
this.delete(getId(path), response);
else
this.notFound(response);
} catch (Exception e) {
e.printStackTrace();
}
}
示例15: handle
import org.simpleframework.http.Request; //导入依赖的package包/类
@Override
public void handle(Request req, Response response) {
try {
String msg = "unknown path";
int code = 200;
String path = req.getPath().getPath();
if (path.equals(WatsAgentCommand.request.getPath())) {
msg = "Requesting users ";
StandaloneAgentRequest agentRequest = getRequest(req.getInputStream());
if (agentRequest == null) {
msg = "Invalid StandaloneAgentRequest.";
code = 406;
} else if (agentRequest.getJobId() != null && agentRequest.getUsers() > 0) {
// launch the harness with the specified details.
agentStarter.startTest(agentRequest);
} else {
msg = "invalid request.";
code = 400;
}
}
long time = System.currentTimeMillis();
response.setCode(code);
response.set("Content-Type", "text/plain");
response.set("Server", "TAnk Agent/1.0");
response.setDate("Date", time);
response.setDate("Last-Modified", time);
PrintStream body = response.getPrintStream();
body.println(msg);
body.close();
} catch (Exception e) {
LOG.error("error sending response");
response.setCode(500);
}
}