Java Code Examples for org.apache.tomcat.util.buf.MessageBytes#recycle()

The following examples show how to use org.apache.tomcat.util.buf.MessageBytes#recycle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AjpMessage.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private void doGetBytes(MessageBytes mb, boolean terminated) {
    int length = getInt();
    if ((length == 0xFFFF) || (length == -1)) {
        mb.recycle();
        return;
    }
    if (terminated) {
        validatePos(pos + length + 1);
    } else {
        validatePos(pos + length);
    }
    mb.setBytes(buf, pos, length);
    mb.getCharChunk().recycle(); // not valid anymore
    pos += length;
    if (terminated) {
        pos++; // Skip the terminating \0
    }
}
 
Example 2
Source File: AjpMessage.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private void doGetBytes(MessageBytes mb, boolean terminated) {
    int length = getInt();
    if ((length == 0xFFFF) || (length == -1)) {
        mb.recycle();
        return;
    }
    if (terminated) {
        validatePos(pos + length + 1);
    } else {
        validatePos(pos + length);
    }
    mb.setBytes(buf, pos, length);
    mb.getCharChunk().recycle(); // not valid anymore
    pos += length;
    if (terminated) {
        pos++; // Skip the terminating \0
    }
}
 
Example 3
Source File: AjpMessage.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
private void doGetBytes(MessageBytes mb, boolean terminated) {
    int length = getInt();
    if ((length == 0xFFFF) || (length == -1)) {
        mb.recycle();
        return;
    }
    if (terminated) {
        validatePos(pos + length + 1);
    } else {
        validatePos(pos + length);
    }
    mb.setBytes(buf, pos, length);
    mb.getCharChunk().recycle(); // not valid anymore
    pos += length;
    if (terminated) {
        pos++; // Skip the terminating \0
    }
}
 
Example 4
Source File: TestMapper.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Test
public void testMap() throws Exception {
    MappingData mappingData = new MappingData();
    MessageBytes host = MessageBytes.newInstance();
    host.setString("iowejoiejfoiew");
    MessageBytes wildcard = MessageBytes.newInstance();
    wildcard.setString("foo.net");
    MessageBytes alias = MessageBytes.newInstance();
    alias.setString("iowejoiejfoiew_alias");
    MessageBytes uri = MessageBytes.newInstance();
    uri.setString("/foo/bar/blah/bobou/foo");
    uri.toChars();
    uri.getCharChunk().setLimit(-1);

    mapper.map(host, uri, null, mappingData);
    Assert.assertEquals("blah7", mappingData.host.getName());
    Assert.assertEquals("context2", mappingData.context.getName());
    Assert.assertEquals("wrapper5", mappingData.wrapper.getName());
    Assert.assertEquals("/foo/bar", mappingData.contextPath.toString());
    Assert.assertEquals("/blah/bobou", mappingData.wrapperPath.toString());
    Assert.assertEquals("/foo", mappingData.pathInfo.toString());
    Assert.assertTrue(mappingData.redirectPath.isNull());

    mappingData.recycle();
    uri.recycle();
    uri.setString("/foo/bar/bla/bobou/foo");
    uri.toChars();
    uri.getCharChunk().setLimit(-1);
    mapper.map(host, uri, null, mappingData);
    Assert.assertEquals("blah7", mappingData.host.getName());
    Assert.assertEquals("context3", mappingData.context.getName());
    Assert.assertEquals("wrapper7", mappingData.wrapper.getName());
    Assert.assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
    Assert.assertEquals("/bobou", mappingData.wrapperPath.toString());
    Assert.assertEquals("/foo", mappingData.pathInfo.toString());
    Assert.assertTrue(mappingData.redirectPath.isNull());

    mappingData.recycle();
    uri.recycle();
    uri.setString("/foo/bar/bla/bobou/foo");
    uri.toChars();
    uri.getCharChunk().setLimit(-1);
    mapper.map(wildcard, uri, null, mappingData);
    Assert.assertEquals("blah16", mappingData.host.getName());
    Assert.assertEquals("context4", mappingData.context.getName());
    Assert.assertEquals("context4-defaultWrapper", mappingData.wrapper.getName());
    Assert.assertEquals("", mappingData.contextPath.toString());
    Assert.assertEquals("/foo/bar/bla/bobou/foo", mappingData.wrapperPath.toString());
    Assert.assertTrue(mappingData.pathInfo.isNull());
    Assert.assertTrue(mappingData.redirectPath.isNull());

    mappingData.recycle();
    uri.setString("/foo/bar/bla/bobou/foo");
    uri.toChars();
    uri.getCharChunk().setLimit(-1);
    mapper.map(alias, uri, null, mappingData);
    Assert.assertEquals("blah7", mappingData.host.getName());
    Assert.assertEquals("context3", mappingData.context.getName());
    Assert.assertEquals("wrapper7", mappingData.wrapper.getName());
    Assert.assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
    Assert.assertEquals("/bobou", mappingData.wrapperPath.toString());
    Assert.assertEquals("/foo", mappingData.pathInfo.toString());
    Assert.assertTrue(mappingData.redirectPath.isNull());
}
 
Example 5
Source File: TestMapper.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Test
public void testMap() throws Exception {
    MappingData mappingData = new MappingData();
    MessageBytes host = MessageBytes.newInstance();
    host.setString("iowejoiejfoiew");
    MessageBytes alias = MessageBytes.newInstance();
    alias.setString("iowejoiejfoiew_alias");
    MessageBytes uri = MessageBytes.newInstance();
    uri.setString("/foo/bar/blah/bobou/foo");
    uri.toChars();
    uri.getCharChunk().setLimit(-1);

    mapper.map(host, uri, null, mappingData);
    assertEquals("blah7", mappingData.host);
    assertEquals("context2", mappingData.context);
    assertEquals("wrapper5", mappingData.wrapper);
    assertEquals("/foo/bar", mappingData.contextPath.toString());
    assertEquals("/blah/bobou", mappingData.wrapperPath.toString());
    assertEquals("/foo", mappingData.pathInfo.toString());
    assertTrue(mappingData.redirectPath.isNull());

    mappingData.recycle();
    uri.recycle();
    uri.setString("/foo/bar/bla/bobou/foo");
    uri.toChars();
    uri.getCharChunk().setLimit(-1);
    mapper.map(host, uri, null, mappingData);
    assertEquals("blah7", mappingData.host);
    assertEquals("context3", mappingData.context);
    assertEquals("wrapper7", mappingData.wrapper);
    assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
    assertEquals("/bobou", mappingData.wrapperPath.toString());
    assertEquals("/foo", mappingData.pathInfo.toString());
    assertTrue(mappingData.redirectPath.isNull());

    mappingData.recycle();
    uri.setString("/foo/bar/bla/bobou/foo");
    uri.toChars();
    uri.getCharChunk().setLimit(-1);
    mapper.map(alias, uri, null, mappingData);
    assertEquals("blah7", mappingData.host);
    assertEquals("context3", mappingData.context);
    assertEquals("wrapper7", mappingData.wrapper);
    assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
    assertEquals("/bobou", mappingData.wrapperPath.toString());
    assertEquals("/foo", mappingData.pathInfo.toString());
    assertTrue(mappingData.redirectPath.isNull());
}
 
Example 6
Source File: TestMapper.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Test
public void testMap() throws Exception {
    MappingData mappingData = new MappingData();
    MessageBytes host = MessageBytes.newInstance();
    host.setString("iowejoiejfoiew");
    MessageBytes alias = MessageBytes.newInstance();
    alias.setString("iowejoiejfoiew_alias");
    MessageBytes uri = MessageBytes.newInstance();
    uri.setString("/foo/bar/blah/bobou/foo");
    uri.toChars();
    uri.getCharChunk().setLimit(-1);

    mapper.map(host, uri, null, mappingData);
    assertEquals("blah7", mappingData.host);
    assertEquals("context2", mappingData.context);
    assertEquals("wrapper5", mappingData.wrapper);
    assertEquals("/foo/bar", mappingData.contextPath.toString());
    assertEquals("/blah/bobou", mappingData.wrapperPath.toString());
    assertEquals("/foo", mappingData.pathInfo.toString());
    assertTrue(mappingData.redirectPath.isNull());

    mappingData.recycle();
    uri.recycle();
    uri.setString("/foo/bar/bla/bobou/foo");
    uri.toChars();
    uri.getCharChunk().setLimit(-1);
    mapper.map(host, uri, null, mappingData);
    assertEquals("blah7", mappingData.host);
    assertEquals("context3", mappingData.context);
    assertEquals("wrapper7", mappingData.wrapper);
    assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
    assertEquals("/bobou", mappingData.wrapperPath.toString());
    assertEquals("/foo", mappingData.pathInfo.toString());
    assertTrue(mappingData.redirectPath.isNull());

    mappingData.recycle();
    uri.setString("/foo/bar/bla/bobou/foo");
    uri.toChars();
    uri.getCharChunk().setLimit(-1);
    mapper.map(alias, uri, null, mappingData);
    assertEquals("blah7", mappingData.host);
    assertEquals("context3", mappingData.context);
    assertEquals("wrapper7", mappingData.wrapper);
    assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
    assertEquals("/bobou", mappingData.wrapperPath.toString());
    assertEquals("/foo", mappingData.pathInfo.toString());
    assertTrue(mappingData.redirectPath.isNull());
}