Exemplo n.º 1
0
  /**
   * Returns whether the following token exists.
   *
   * @return result
   */
  private boolean more() {
    if (all) return tokens.hasNext();

    while (tokens.hasNext()) {
      currToken = tokens.next();
      if (!currToken.isMark() && !currToken.isAttachedWord()) return true;
    }
    return false;
  }
Exemplo n.º 2
0
  /**
   * Tests RequestParser.parse() with multipart request.
   *
   * @throws IOException I/O Exception
   * @throws QueryException query exception
   */
  @Test
  public void parseMultipartReq() throws IOException, QueryException {
    final String multiReq =
        "<http:request "
            + "xmlns:http='http://expath.org/ns/http-client' "
            + "method='POST' href='"
            + REST_ROOT
            + "'>"
            + "<http:header name='hdr1' value='hdr1val'/>"
            + "<http:header name='hdr2' value='hdr2val'/>"
            + "<http:multipart media-type='multipart/mixed' boundary='xxxx'>"
            + "<http:header name='p1hdr1' value='p1hdr1val'/>"
            + "<http:header name='p1hdr2' value='p1hdr2val'/>"
            + "<http:body media-type='text/plain'>"
            + "Part1"
            + "</http:body>"
            + "<http:header name='p2hdr1' value='p2hdr1val'/>"
            + "<http:body media-type='text/plain'>"
            + "Part2"
            + "</http:body>"
            + "<http:body media-type='text/plain'>"
            + "Part3"
            + "</http:body>"
            + "</http:multipart>"
            + "</http:request>";

    final DBNode dbNode1 = new DBNode(new IOContent(multiReq));
    final HttpRequestParser rp = new HttpRequestParser(null);
    final HttpRequest r = rp.parse(dbNode1.children().next(), null);

    assertEquals(2, r.attributes.size());
    assertEquals(2, r.headers.size());
    assertTrue(r.isMultipart);
    assertEquals(3, r.parts.size());

    // check parts
    final Iterator<Part> i = r.parts.iterator();
    Part part = i.next();
    assertEquals(2, part.headers.size());
    assertEquals(1, part.bodyContent.size());
    assertEquals(1, part.bodyAttrs.size());

    part = i.next();
    assertEquals(1, part.headers.size());
    assertEquals(1, part.bodyContent.size());
    assertEquals(1, part.bodyAttrs.size());

    part = i.next();
    assertEquals(0, part.headers.size());
    assertEquals(1, part.bodyContent.size());
    assertEquals(1, part.bodyAttrs.size());
  }
Exemplo n.º 3
0
 /**
  * Returns the token which contains special characters.
  *
  * @return token
  */
 private byte[] getSC() {
   final Morpheme m = tokens.next();
   final String n = m.getSurface();
   if (m.isMark() || m.isAttachedWord()) {
     sc = true;
   } else {
     pos++;
     sc = false;
   }
   return token(n);
 }