本文整理汇总了Java中org.simpleframework.http.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于org.simpleframework.http包,在下文中一共展示了Response类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createServer
import org.simpleframework.http.Response; //导入依赖的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
示例2: handle
import org.simpleframework.http.Response; //导入依赖的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
示例3: handle
import org.simpleframework.http.Response; //导入依赖的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
示例4: testServingIndexHtml
import org.simpleframework.http.Response; //导入依赖的package包/类
@Test
public void testServingIndexHtml() throws IOException {
WebRequestContainer container =
new WebRequestContainer(123, mMockServerCreator, mImageServer, mMockResourceLoader);
when(mMockResourceLoader.load(anyString())).thenReturn(new byte[]{1, 2, 23, 42});
container.start();
ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
verify(mMockServer).startServing(containerCaptor.capture());
OutputStream mockOutputStream = mock(OutputStream.class);
Response mockResponse = mock(Response.class);
when(mockResponse.getOutputStream()).thenReturn(mockOutputStream);
// Simulate request to unavailable address.
containerCaptor.getValue().handle(createMockRequestForUrl("/"), mockResponse);
verify(mockResponse).setStatus(Status.OK);
verify(mockResponse).setContentType("text/html");
verify(mockResponse).close();
verify(mockOutputStream).write(eq(new byte[]{1, 2, 23, 42}));
verify(mockOutputStream).close();
}
开发者ID:shaeberling,项目名称:winston,代码行数:23,代码来源:WebRequestContainerTest.java
示例5: testServingImageFileNotSet
import org.simpleframework.http.Response; //导入依赖的package包/类
@Test
public void testServingImageFileNotSet() throws IOException {
WebRequestContainer container =
new WebRequestContainer(123, mMockServerCreator, mImageServer, mMockResourceLoader);
when(mMockResourceLoader.load(anyString())).thenReturn(new byte[]{1, 2, 23, 42});
container.start();
ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
verify(mMockServer).startServing(containerCaptor.capture());
OutputStream mockOutputStream = mock(OutputStream.class);
Response mockResponse = mock(Response.class);
when(mockResponse.getOutputStream()).thenReturn(mockOutputStream);
// Simulate request to image URL..
containerCaptor.getValue().handle(createMockRequestForUrl("/now.jpg"), mockResponse);
verify(mockResponse).setStatus(Status.OK);
verify(mockResponse).setContentType("image/jpeg");
verify(mockResponse).close();
// We never set the image
verify(mockOutputStream).write(eq(new byte[0]));
verify(mockOutputStream).close();
}
开发者ID:shaeberling,项目名称:winston,代码行数:25,代码来源:WebRequestContainerTest.java
示例6: testServingImageFileSet
import org.simpleframework.http.Response; //导入依赖的package包/类
@Test
public void testServingImageFileSet() throws IOException {
WebRequestContainer container =
new WebRequestContainer(123, mMockServerCreator, mImageServer, mMockResourceLoader);
when(mMockResourceLoader.load(anyString())).thenReturn(new byte[]{1, 2, 23, 42});
container.start();
mImageServer.updateCurrentFile(() -> Optional.of(new byte[]{1, 2, 3, 5, 8, 13, 21}));
ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
verify(mMockServer).startServing(containerCaptor.capture());
OutputStream mockOutputStream = mock(OutputStream.class);
Response mockResponse = mock(Response.class);
when(mockResponse.getOutputStream()).thenReturn(mockOutputStream);
// Simulate request to image URL..
containerCaptor.getValue().handle(createMockRequestForUrl("/now.jpg"), mockResponse);
verify(mockResponse).setStatus(Status.OK);
verify(mockResponse).setContentType("image/jpeg");
verify(mockResponse).close();
// We never set the image
verify(mockOutputStream).write(eq(new byte[]{1, 2, 3, 5, 8, 13, 21}));
verify(mockOutputStream).close();
}
开发者ID:shaeberling,项目名称:winston,代码行数:26,代码来源:WebRequestContainerTest.java
示例7: testServingThrowsException
import org.simpleframework.http.Response; //导入依赖的package包/类
@Test
public void testServingThrowsException() throws IOException {
WebRequestContainer container =
new WebRequestContainer(123, mMockServerCreator, mImageServer, mMockResourceLoader);
when(mMockResourceLoader.load(anyString())).thenReturn(new byte[]{1, 2, 23, 42});
container.start();
ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
verify(mMockServer).startServing(containerCaptor.capture());
OutputStream mockOutputStream = mock(OutputStream.class);
Response mockResponse = mock(Response.class);
doThrow(new IOException()).when(mockOutputStream).write(any());
when(mockResponse.getOutputStream()).thenReturn(mockOutputStream);
containerCaptor.getValue().handle(createMockRequestForUrl("/"), mockResponse);
// Even though it throws, response should be closed.
verify(mockResponse).close();
}
开发者ID:shaeberling,项目名称:winston,代码行数:20,代码来源:WebRequestContainerTest.java
示例8: testResponseCloseThrows
import org.simpleframework.http.Response; //导入依赖的package包/类
@Test
public void testResponseCloseThrows() throws IOException {
WebRequestContainer container =
new WebRequestContainer(123, mMockServerCreator, mImageServer, mMockResourceLoader);
when(mMockResourceLoader.load(anyString())).thenReturn(new byte[]{1, 2, 23, 42});
container.start();
ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
verify(mMockServer).startServing(containerCaptor.capture());
OutputStream mockOutputStream = mock(OutputStream.class);
Response mockResponse = mock(Response.class);
doThrow(new IOException()).when(mockResponse).close();
when(mockResponse.getOutputStream()).thenReturn(mockOutputStream);
containerCaptor.getValue().handle(createMockRequestForUrl("/"), mockResponse);
// Nothing horrible should happen if response.close throws.
}
开发者ID:shaeberling,项目名称:winston,代码行数:19,代码来源:WebRequestContainerTest.java
示例9: handle
import org.simpleframework.http.Response; //导入依赖的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
示例10: handle
import org.simpleframework.http.Response; //导入依赖的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
示例11: body
import org.simpleframework.http.Response; //导入依赖的package包/类
public ResponseBody body(HttpRequest request, Response resp,
MarshallerProvider marshallerProvider) {
if (httpHandler != null) {
SimpleHttpResponse response = new SimpleHttpResponse(request, resp);
httpHandler.handle(request, response);
this.contentType = response.getContentType();
this.statusCode = response.getStatusCode();
return response.getBody(marshallerProvider);
}
if (hasEntity()) {
Marshaller marshaller = marshallerProvider.getMarshaller(contentType);
if (marshaller == null) {
throw new RuntimeException("an entity has been set in the " +
"response, but no marshaller exists for " +
"content type: " + contentType);
}
return new MarshalledResponseBody(entity, marshaller);
}
return new InterpolatedResponseBody(body, request);
}
开发者ID:lantunes,项目名称:fixd,代码行数:27,代码来源:RequestHandlerImpl.java
示例12: AsyncTask
import org.simpleframework.http.Response; //导入依赖的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
示例13: handle
import org.simpleframework.http.Response; //导入依赖的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
示例14: handle
import org.simpleframework.http.Response; //导入依赖的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
示例15: handle
import org.simpleframework.http.Response; //导入依赖的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
示例16: handle
import org.simpleframework.http.Response; //导入依赖的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
示例17: serveError
import org.simpleframework.http.Response; //导入依赖的package包/类
/**
* Write a {@link HTTPTrackerErrorMessage} to the response with the given
* HTTP status code.
*
* @param response The HTTP response object.
* @param body The response output stream to write to.
* @param status The HTTP status code to return.
* @param error The error reported by the tracker.
*/
private void serveError(Response response, OutputStream body,
Status status, HTTPTrackerErrorMessage error) throws IOException {
response.setCode(status.getCode());
response.setText(status.getDescription());
logger.warn("Could not process announce request ({}) !",
error.getReason());
WritableByteChannel channel = Channels.newChannel(body);
channel.write(error.getData());
}
开发者ID:KingJoker,项目名称:PiratePlayar,代码行数:20,代码来源:TrackerService.java
示例18: serveError
import org.simpleframework.http.Response; //导入依赖的package包/类
/**
* Write a {@link HTTPTrackerErrorMessage} to the response with the given
* HTTP status code.
*
* @param response The HTTP response object.
* @param body The response output stream to write to.
* @param status The HTTP status code to return.
* @param error The error reported by the tracker.
*/
private void serveError(Response response, OutputStream body,
Status status, HTTPTrackerErrorMessage error) throws IOException {
response.setStatus(status);
LOG.warn("Could not process announce request ({}) !",
error.getReason());
BytesBEncoder encoder = new BytesBEncoder();
encoder.bencode(error.toBEValue());
body.write(encoder.toByteArray()); // This is the raw network stream.
}
开发者ID:letroll,项目名称:TtorrentAndroid,代码行数:19,代码来源:TrackerService.java
示例19: handle
import org.simpleframework.http.Response; //导入依赖的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
示例20: handle
import org.simpleframework.http.Response; //导入依赖的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
注:本文中的org.simpleframework.http.Response类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论