Package mongrel2

Examples of mongrel2.Response


  public void deleteAttachment(ERS3Attachment attachment)
      throws MalformedURLException, IOException {
    AWSAuthConnection conn = attachment.awsConnection();
    String bucket = attachment.bucket();
    String key = attachment.key();
    Response response = conn.delete(bucket, key, null);
    if (failed(response)) {
      throw new IOException("Failed to delete '" + bucket + "/" + key
          + "' to S3: Error " + response.connection.getResponseCode()
          + ": " + response.connection.getResponseMessage());
    }
View Full Code Here


          headers.put("Content-Disposition", Arrays
              .asList(new String[] { "attachment; filename="
                  + originalFileName }));
        }

        Response response = conn.putStream(bucket, key,
            attachmentStreamObject, headers);
        if (failed(response)) {
          throw new IOException("Failed to write '" + bucket + "/"
              + key + "' to S3: Error "
              + response.connection.getResponseCode() + ": "
View Full Code Here

    try {
      send_raw(q.build().toByteArray());
    } catch (IOException ex) {
      throw new RqlDriverException(ex.getMessage());
    }
    Response rsp = get();

    // For this version we only support success :-(
    switch(rsp.getType()) {
    case SUCCESS_ATOM:
    case SUCCESS_SEQUENCE:
    case SUCCESS_PARTIAL:
      return new RqlCursor(this,rsp);
    case CLIENT_ERROR:
    case COMPILE_ERROR:
    case RUNTIME_ERROR:
    default:
      throw new RqlDriverException(rsp.toString());             
    }             
  }
View Full Code Here

        ExecuteMethod executeMethod = new ExecuteMethod();
        executeMethod.setParameters(parameters);
        executeMethod.setUrl(path);
        executeMethod.setHttpMethod(methodName);

        Response response = method.getResponse();
        if (response != null) {
            Representation representation = response.getRepresentation();
            if (representation != null) {
                String mediaType = representation.getMediaType();
                executeMethod.setResponseType(mediaType);
            }
        }
View Full Code Here

    while (this.handler.isActive()) {

      try {

        final HttpRequest req = new HttpRequest();
        this.handler.takeRequest(req);

        final long now = System.currentTimeMillis();
        System.out.printf("%tH:%tM:%tS - %s %s%n", now, now, now, this.senderId, req.getRequestURL());

        final HttpResponse rsp = new HttpResponse();
        rsp.setContent("Hello, world!\n");
        rsp.setStatus(HttpStatus.OK);
        // rsp.setStatus(HttpStatus.BadRequest.code, "Nice Try");
View Full Code Here

      @Override
      public void run() {

        while (handler.isActive()) {
          try {
            final HttpRequest req = new HttpRequest();
            final HttpResponse rsp = new HttpResponse();
            handler.takeRequest(req);
            rsp.setContent("Hello, world!\n");
            rsp.setStatus(HttpStatus.OK);
            handler.sendResponse(rsp, req);
View Full Code Here

        this.handler.takeRequest(req);

        final long now = System.currentTimeMillis();
        System.out.printf("%tH:%tM:%tS - %s %s%n", now, now, now, this.senderId, req.getRequestURL());

        final HttpResponse rsp = new HttpResponse();
        rsp.setContent("Hello, world!\n");
        rsp.setStatus(HttpStatus.OK);
        // rsp.setStatus(HttpStatus.BadRequest.code, "Nice Try");
        rsp.setHeader("Cache-Control", "public");
        rsp.setHeader("X-Handler-App", "TestApp");
        rsp.setHeader("X-Sender-Id", this.senderId);
        rsp.setDateHeader("Last-Updated", System.currentTimeMillis());

        this.handler.sendResponse(rsp, req);

      } catch (final IOException x) {
        x.printStackTrace();
View Full Code Here

      public void run() {

        while (handler.isActive()) {
          try {
            final HttpRequest req = new HttpRequest();
            final HttpResponse rsp = new HttpResponse();
            handler.takeRequest(req);
            rsp.setContent("Hello, world!\n");
            rsp.setStatus(HttpStatus.OK);
            handler.sendResponse(rsp, req);
          } catch (final IOException x) {
            Assert.fail(x.toString());
          }
        } // while
View Full Code Here

  public void testXmlHandler() throws Exception {

    final byte[] contents = "<myxml><msg>hello xml</msg></myxml>".getBytes();

    final Mongrel2Handler handler = new Mongrel2Handler(UUID.randomUUID().toString(), XML_RECV, XML_SEND);
    // handler.setLevel(Level.DEBUG);
    handler.setActive(true);

    final Socket s = new Socket(SERVER_ADDR.getAddress(), SERVER_ADDR.getPort());
    final InputStream in = s.getInputStream();
    final OutputStream out = s.getOutputStream();

    // send message
    // out.write("<myxml>".getBytes());
    out.write(contents);
    out.write(0);
    out.flush();

    // wait to receive message at handler
    final Request req = new Request();
    handler.takeRequest(req);

    // verify correctness
    Assert.assertEquals("server content length unequal", contents.length, req.getContent().length);
    Assert.assertTrue("server contents do not match", Arrays.equals(contents, req.getContent()));

    // echo message back to client
    final Response rsp = new Response();
    rsp.setPayload(contents);
    Assert.assertTrue(Arrays.equals(contents, rsp.getPayload()));
    handler.sendResponse(rsp, req);
    // handler.sendResponse(rsp, req);

    // read out message at client
    final byte[] msg1 = readInputStream(in, true);
    Assert.assertTrue("zero-length message", msg1.length > 0);
View Full Code Here

  private final String senderId;

  public TestApp(final String senderId) {
    this.senderId = senderId;
    this.handler = new Mongrel2Handler(this.senderId, RECV_ADDR, SEND_ADDR);
  }
View Full Code Here

TOP

Related Classes of mongrel2.Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.