本文整理汇总了Java中org.simpleframework.http.Request类的典型用法代码示例。如果您正苦于以下问题:Java Request类的具体用法?Java Request怎么用?Java Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Request类属于org.simpleframework.http包,在下文中一共展示了Request类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:shaeberling,项目名称:winston,代码行数:24,代码来源:MasterContainer.java
示例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;
}
开发者ID:hlipala,项目名称:autoscaling,代码行数:23,代码来源:ApiServer.java
示例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);
}
开发者ID:blobrobotics,项目名称:bstation,代码行数:27,代码来源:StopTest.java
示例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);
}
开发者ID:byoutline,项目名称:MockServer,代码行数:18,代码来源:ResponseHandler.java
示例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();
}
}
}
开发者ID:bazaarvoice,项目名称:jersey-hmac-auth,代码行数:25,代码来源:ValidatingHttpServer.java
示例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");
}
开发者ID:shaeberling,项目名称:winston,代码行数:25,代码来源:NodeContainer.java
示例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";
}
开发者ID:coil-lighting,项目名称:udder,代码行数:17,代码来源:HttpServiceContainer.java
示例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);
}
}
开发者ID:coil-lighting,项目名称:udder,代码行数:26,代码来源:HttpServiceContainer.java
示例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);
}
}
开发者ID:nlohmann,项目名称:StanfordCoreNLPXMLServer,代码行数:24,代码来源:StanfordCoreNLPXMLServer.java
示例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;
}
开发者ID:lantunes,项目名称:fixd,代码行数:17,代码来源:AsyncTask.java
示例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"));
}
开发者ID:lantunes,项目名称:fixd,代码行数:17,代码来源:TestSimpleHttpRequest.java
示例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);
}
}
开发者ID:DurandA,项目名称:bitworker,代码行数:32,代码来源:TrackerService.java
示例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);
}
}
开发者ID:vdurmont,项目名称:apipixie,代码行数:23,代码来源:DistantAPISimulator.java
示例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();
}
}
开发者ID:vdurmont,项目名称:apipixie,代码行数:22,代码来源:DistantAPISimulator.java
示例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);
}
}
开发者ID:intuit,项目名称:Tank,代码行数:36,代码来源:CommandListener.java
示例16: parseQuery
import org.simpleframework.http.Request; //导入依赖的package包/类
/**
* Parse the query parameters using our defined BYTE_ENCODING.
*
* <p>
* Because we're expecting byte-encoded strings as query parameters, we
* can't rely on SimpleHTTP's QueryParser which uses the wrong encoding for
* the job and returns us unparsable byte data. We thus have to implement
* our own little parsing method that uses BYTE_ENCODING to decode
* parameters from the URI.
* </p>
*
* <p>
* <b>Note:</b> array parameters are not supported. If a key is present
* multiple times in the URI, the latest value prevails. We don't really
* need to implement this functionality as this never happens in the
* Tracker HTTP protocol.
* </p>
*
* @param uri The request's full URI, including query parameters.
* @return The {@link AnnounceRequestMessage} representing the client's
* announce request.
*/
private HTTPAnnounceRequestMessage parseQuery(Request request)
throws IOException, MessageValidationException {
Map<String, BEValue> params = new HashMap<String, BEValue>();
try {
String uri = request.getAddress().toString();
for (String pair : uri.split("[?]")[1].split("&")) {
String[] keyval = pair.split("[=]", 2);
if (keyval.length == 1) {
this.recordParam(params, keyval[0], null);
} else {
this.recordParam(params, keyval[0], keyval[1]);
}
}
} catch (ArrayIndexOutOfBoundsException e) {
params.clear();
}
// Make sure we have the peer IP, fallbacking on the request's source
// address if the peer didn't provide it.
if (params.get("ip") == null) {
params.put("ip", new BEValue(
request.getClientAddress().getAddress().getHostAddress(),
TrackedTorrent.BYTE_ENCODING));
}
return HTTPAnnounceRequestMessage.parse(BEncoder.bencode(params));
}
开发者ID:KingJoker,项目名称:PiratePlayar,代码行数:52,代码来源:TrackerService.java
示例17: handle
import org.simpleframework.http.Request; //导入依赖的package包/类
public void handle(Request request, Response response) {
Path path = request.getPath();
String action = path.getDirectory()+path.getName();
String result = "";
log.debug("Request: "+action);
// Handle request
if(action.equals("/listLoadBalancer")) result = listLoadBalancer();
else if(action.equals("/addAutoScalePolicy")) result = addAutoScalePolicy(request);
else if(action.equals("/removeAutoScalePolicy")) result = removeAutoScalePolicy(request);
else result = "Not Supported";
// Handle response
try {
PrintStream body = response.getPrintStream();
long time = System.currentTimeMillis();
response.setValue("Content-Type", "text/javascript");
response.setValue("Server", "AutoScaleAPI/1.0");
response.setDate("Date", time);
response.setDate("Last-Modified", time);
body.println(result);
body.close();
} catch(Exception e) {
log.error("Could not connect to cloudstack api",e);
}
}
开发者ID:hlipala,项目名称:autoscaling,代码行数:32,代码来源:ApiServer.java
示例18: handle
import org.simpleframework.http.Request; //导入依赖的package包/类
public void handle(Request request, Response response) {
try {
process(request, response);
}catch(Exception e) {
e.printStackTrace();
assertTrue(false);
}
}
开发者ID:blobrobotics,项目名称:bstation,代码行数:9,代码来源:ReactorProcessorTest.java
示例19: handle
import org.simpleframework.http.Request; //导入依赖的package包/类
public void handle(Request req, Response resp) {
try {
System.err.println(req);
PrintStream out = resp.getPrintStream(1024);
resp.setValue("Content-Type", "text/plain");
out.print(message);
out.close();
}catch(Exception e) {
e.printStackTrace();
}
}
开发者ID:blobrobotics,项目名称:bstation,代码行数:13,代码来源:ConnectionTest.java
示例20: matches
import org.simpleframework.http.Request; //导入依赖的package包/类
/**
* Checks if HTTP request matches all fields specified in config.
* Fails on first mismatch. Both headers and query params can be configured as regex.
* @param req
* @return
*/
public boolean matches(Request req) {
if (!method.equals(req.getMethod())) return false;
if (useRegexForPath) {
if (!req.getPath().getPath().matches(basePath)) return false;
} else {
if (!basePath.equals(req.getPath().getPath())) return false;
}
if (!queries.keySet().containsAll(req.getQuery().keySet())) return false;
if (!req.getNames().containsAll(headers.keySet())) return false;
try {
if (!isEmpty(bodyMustContain) && !req.getContent().contains(bodyMustContain))
return false;
} catch (IOException e) {
return false;
}
for (Map.Entry<String, String> reqQuery : req.getQuery().entrySet()) {
String respRegex = queries.get(reqQuery.getKey());
if (!reqQuery.getValue().matches(respRegex)) return false;
}
for(Map.Entry<String, String> header : headers.entrySet()) {
String headerValueRegex = header.getValue();
if(!req.getValue(header.getKey()).matches(headerValueRegex)) return false;
}
return true;
}
开发者ID:byoutline,项目名称:MockServer,代码行数:34,代码来源:RequestParams.java
注:本文中的org.simpleframework.http.Request类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论