当前位置: 首页>>代码示例>>Java>>正文


Java Response.getPrintStream方法代码示例

本文整理汇总了Java中org.simpleframework.http.Response.getPrintStream方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getPrintStream方法的具体用法?Java Response.getPrintStream怎么用?Java Response.getPrintStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.simpleframework.http.Response的用法示例。


在下文中一共展示了Response.getPrintStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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包/类
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

示例4: 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

示例5: 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

示例6: handle

import org.simpleframework.http.Response; //导入方法依赖的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

示例7: streamResponse

import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void streamResponse(Response resp, ResponseParams rp) throws IOException {
    OutputStream body = null;
    try {
        if (rp.staticFile) {
            String fileName = rp.message;

            body = resp.getOutputStream();

            byte[] buffer = new byte[32 * 1024];
            InputStream input = configReader.getStaticFile(fileName);
            int bytesRead;
            while ((bytesRead = input.read(buffer, 0, buffer.length)) > 0) {
                body.write(buffer, 0, bytesRead);
            }

        } else {
            body = resp.getPrintStream();
            if (body != null) {
                ((PrintStream) body).print(rp.message);
            }
        }
    } finally {
        if (body != null) {
            try {
                body.close();
            } catch (IOException e) {
                LOGGER.log(Level.SEVERE, "Exception on MockServer close", e);
            }
        }
    }
}
 
开发者ID:byoutline,项目名称:MockServer,代码行数:32,代码来源:ResponseHandler.java

示例8: handle

import org.simpleframework.http.Response; //导入方法依赖的package包/类
public void handle(Request request, Response response) {
    try {

        log.info("Request received {}",request);

        PrintStream body = response.getPrintStream();
        long time = System.currentTimeMillis();

        response.setValue("Content-Type", "text/plain");
        response.setValue("Server", "AkkaCrawler Server 1.0");
        response.setDate("Date", time);
        response.setDate("Last-Modified", time);

        final Query query = request.getQuery();
        final String responseAttribute = (String) query.get("request");

        if(responseAttribute != null){
            final String writeBackResponseBody = requestAndResponse.get(responseAttribute);
            body.print(writeBackResponseBody);
            log.info("Response sent back {} ",writeBackResponseBody);
        }

        body.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:tarjeir,项目名称:vitus-elasticsearch-webintegration,代码行数:28,代码来源:WebServer.java

示例9: respond

import org.simpleframework.http.Response; //导入方法依赖的package包/类
private boolean respond(Response response, String responseBody) {
    this.addResponseHeader(response);
    try {
        PrintStream body = response.getPrintStream();
        body.println(responseBody);
        body.close();
        return true;
    } catch (IOException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        log("Error writing response body: " + e + '\n' + sw);
        return false;
    }
}
 
开发者ID:coil-lighting,项目名称:udder,代码行数:15,代码来源:HttpServiceContainer.java

示例10: handleMethodNotAllowed

import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void handleMethodNotAllowed(Response resp){
	resp.setStatus(Status.METHOD_NOT_ALLOWED);
	resp.setValue("Content-Type", "text/plain");
	PrintStream body;
	try {
		body = resp.getPrintStream();
		body.println("METHOD_NOT_ALLOWED");	
		body.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:ael-code,项目名称:preston,代码行数:13,代码来源:RequestHandler.java

示例11: handleInternalServerError

import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void handleInternalServerError(Response resp){
	resp.setStatus(Status.INTERNAL_SERVER_ERROR);
	resp.setValue("Content-Type", "text/plain");
	PrintStream body;
	try {
		body = resp.getPrintStream();
		body.println("INTERNAL_SERVER_ERROR");	
		body.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:ael-code,项目名称:preston,代码行数:13,代码来源:RequestHandler.java

示例12: printBody

import org.simpleframework.http.Response; //导入方法依赖的package包/类
private PrintStream printBody(Response response, String contentType) throws IOException {
    
    PrintStream ps = response.getPrintStream();
    addStandardHeaders(response, contentType);
    ps.println(body);
    ps.flush();
    return ps;
}
 
开发者ID:lantunes,项目名称:fixd,代码行数:9,代码来源:StringResponseBody.java

示例13: print

import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void print(Status status, Response response, String str) throws Exception {
	PrintStream body = response.getPrintStream();
	response.setStatus(status);
	response.setValue("Content-Type", "application/json");
	if (str != null)
		body.println(str);
	body.close();
}
 
开发者ID:vdurmont,项目名称:apipixie,代码行数:9,代码来源:DistantAPISimulator.java

示例14: handle

import org.simpleframework.http.Response; //导入方法依赖的package包/类
public void handle(Request request, Response response)
{
	try
	{
		PrintStream body = response.getPrintStream();
	
		long time = System.currentTimeMillis();
		logWriter.println((new Date()).toString()+": request from "+request.getClientAddress().toString());
		String pageName = request.getPath().getPath();
		
		response.setValue("Content-Type", "text/html");
		response.setValue("Server", "PregroupSPARQL/1.0 (Simple)");
		response.setDate("Date", time);
		response.setDate("Last-Modified", time);

		if(pageName.equals("/reload"))
			sem.load("semantics.xml");
		
		System.out.println("Requested \""+pageName+"\"");
		if(pageName.equals("/index.html") || pageName.equals("/") || pageName.equals("/reload"))
			body.println(homePage);
		else if(pageName.equals("/process.html"))
			body.println(processSentence(request.getQuery().get("sentence")));
		else if(pageName.startsWith("/tmp/img/"))
		{
			//! TODO THIS IS A BACKDOOOOOOOOR
			response.setValue("Content-Type", "image/png");
			body.write(readBinary("."+pageName));
		}
		else
			body.println("404 Page Not Found\n");
		body.close();
	}
	catch (Exception e)
	{
		System.out.println("Exception caught in handle():");
		e.printStackTrace();
	}
	
}
 
开发者ID:wetneb,项目名称:MorozParser,代码行数:41,代码来源:WebApp.java

示例15: handle

import org.simpleframework.http.Response; //导入方法依赖的package包/类
@Override
public void handle(Request req, Response response) {
    try {
        String msg = "unknown path";
        String path = req.getPath().getPath();
        if (path.equals(WatsAgentCommand.start.getPath()) || path.equals(WatsAgentCommand.run.getPath())) {
            msg = "Starting Test " + APITestHarness.getInstance().getAgentRunData().getJobId();
            startTest();
        } else if (path.startsWith(WatsAgentCommand.stop.getPath())) {
            msg = "Stopping Test " + APITestHarness.getInstance().getAgentRunData().getJobId();
            APITestHarness.getInstance().setCommand(WatsAgentCommand.stop);
        } else if (path.startsWith(WatsAgentCommand.kill.getPath())) {
            msg = "Killing Test " + APITestHarness.getInstance().getAgentRunData().getJobId();
            System.exit(0);
        } else if (path.startsWith(WatsAgentCommand.pause.getPath())) {
            msg = "Pausing Test " + APITestHarness.getInstance().getAgentRunData().getJobId();
            APITestHarness.getInstance().setCommand(WatsAgentCommand.pause);
        } else if (path.startsWith(WatsAgentCommand.pause_ramp.getPath())) {
            msg = "Pausing Ramp for Test " + APITestHarness.getInstance().getAgentRunData().getJobId();
            APITestHarness.getInstance().setCommand(WatsAgentCommand.pause_ramp);
        } else if (path.startsWith(WatsAgentCommand.resume_ramp.getPath())) {
            msg = "Pausing Test " + APITestHarness.getInstance().getAgentRunData().getJobId();
            APITestHarness.getInstance().setCommand(WatsAgentCommand.resume_ramp);
        } else if (path.startsWith(WatsAgentCommand.status.getPath())) {
            msg = APITestHarness.getInstance().getStats().toString();
            APITestHarness.getInstance().setCommand(WatsAgentCommand.resume_ramp);
        }
        LOG.info(msg);
        PrintStream body = response.getPrintStream();

        long time = System.currentTimeMillis();

        response.set("Content-Type", "text/plain");
        response.set("Server", "Intuit Tank Agent/1.0");
        response.setDate("Date", time);
        response.setDate("Last-Modified", time);

        body.println(msg);
        body.close();
    } catch (IOException e) {
        LOG.error("");
        response.setCode(500);
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:45,代码来源:CommandListener.java


注:本文中的org.simpleframework.http.Response.getPrintStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。