Пример #1
0
  /**
   * Tests method setRequestContent of HttpClient.
   *
   * @throws IOException I/O Exception
   */
  @Test
  public void writeMultipartMessage() throws IOException {
    final HttpRequest req = new HttpRequest();
    req.isMultipart = true;
    req.payloadAttrs.put("media-type", "multipart/alternative");
    req.payloadAttrs.put("boundary", "boundary42");
    final Part p1 = new Part();
    p1.headers.put("Content-Type", "text/plain; charset=us-ascii");
    p1.bodyAttrs.put("media-type", "text/plain");
    final String plain = "...plain text....";
    p1.bodyContent.add(Str.get(plain + '\n'));

    final Part p2 = new Part();
    p2.headers.put("Content-Type", "text/richtext");
    p2.bodyAttrs.put("media-type", "text/richtext");
    final String rich = ".... richtext version...";
    p2.bodyContent.add(Str.get(rich));

    final Part p3 = new Part();
    p3.headers.put("Content-Type", "text/x-whatever");
    p3.bodyAttrs.put("media-type", "text/x-whatever");
    final String fancy = ".... fanciest formatted version...";
    p3.bodyContent.add(Str.get(fancy));

    req.parts.add(p1);
    req.parts.add(p2);
    req.parts.add(p3);

    final FakeHttpConnection fakeConn = new FakeHttpConnection(new URL("http://www.test.com"));
    HttpClient.setRequestContent(fakeConn.getOutputStream(), req);
    final String expResult =
        "--boundary42"
            + CRLF
            + "Content-Type: text/plain; charset=us-ascii"
            + CRLF
            + CRLF
            + plain
            + Prop.NL
            + CRLF
            + "--boundary42"
            + CRLF
            + "Content-Type: text/richtext"
            + CRLF
            + CRLF
            + rich
            + CRLF
            + "--boundary42"
            + CRLF
            + "Content-Type: text/x-whatever"
            + CRLF
            + CRLF
            + fancy
            + CRLF
            + "--boundary42--"
            + CRLF;

    // Compare results
    assertEquals(expResult, fakeConn.getOutputStream().toString());
  }
 @Override
 protected void setCommonHeaders(HttpRequest req) {
   super.setCommonHeaders(req);
   if (filter != null) {
     req.setHeader(X_MOBC3_FILTER, filter);
     filter = null;
   }
 }
Пример #3
0
 /**
  * Creates an new request for the app server from an HTTP request.
  *
  * @param request HTTP request to create
  * @return the request
  */
 public AppRequest createRequest(HttpRequest request) {
   return createRequest(request, request.getHost(), request.getURI());
 }