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

The following examples show how to use org.apache.tomcat.util.buf.MessageBytes#toChars() . 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: TestMapperPerformance.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private long testPerformanceImpl(String requestedHostName) throws Exception {
    MappingData mappingData = new MappingData();
    MessageBytes host = MessageBytes.newInstance();
    host.setString(requestedHostName);
    MessageBytes uri = MessageBytes.newInstance();
    uri.setString("/foo/bar/blah/bobou/foo");
    uri.toChars();
    uri.getCharChunk().setLimit(-1);

    long start = System.currentTimeMillis();
    for (int i = 0; i < 1000000; i++) {
        mappingData.recycle();
        mapper.map(host, uri, null, mappingData);
    }
    long time = System.currentTimeMillis() - start;
    return time;
}
 
Example 2
Source File: TestMapper.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private long testPerformanceImpl() throws Exception {
    MappingData mappingData = new MappingData();
    MessageBytes host = MessageBytes.newInstance();
    host.setString("iowejoiejfoiew");
    MessageBytes uri = MessageBytes.newInstance();
    uri.setString("/foo/bar/blah/bobou/foo");
    uri.toChars();
    uri.getCharChunk().setLimit(-1);

    long start = System.currentTimeMillis();
    for (int i = 0; i < 1000000; i++) {
        mappingData.recycle();
        mapper.map(host, uri, null, mappingData);
    }
    long time = System.currentTimeMillis() - start;
    return time;
}
 
Example 3
Source File: TestMapper.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
private long testPerformanceImpl() throws Exception {
    MappingData mappingData = new MappingData();
    MessageBytes host = MessageBytes.newInstance();
    host.setString("iowejoiejfoiew");
    MessageBytes uri = MessageBytes.newInstance();
    uri.setString("/foo/bar/blah/bobou/foo");
    uri.toChars();
    uri.getCharChunk().setLimit(-1);

    long start = System.currentTimeMillis();
    for (int i = 0; i < 1000000; i++) {
        mappingData.recycle();
        mapper.map(host, uri, null, mappingData);
    }
    long time = System.currentTimeMillis() - start;
    return time;
}
 
Example 4
Source File: Mapper.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Map the specified host name and URI, mutating the given mapping data.
 *
 * @param host Virtual host name
 * @param uri URI
 * @param version The version, if any, included in the request to be mapped
 * @param mappingData This structure will contain the result of the mapping
 *                    operation
 * @throws IOException if the buffers are too small to hold the results of
 *                     the mapping.
 */
public void map(MessageBytes host, MessageBytes uri, String version,
                MappingData mappingData) throws IOException {

    if (host.isNull()) {
        host.getCharChunk().append(defaultHostName);
    }
    host.toChars();
    uri.toChars();
    internalMap(host.getCharChunk(), uri.getCharChunk(), version,
            mappingData);
}
 
Example 5
Source File: Mapper.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Map the specified host name and URI, mutating the given mapping data.
 *
 * @param host Virtual host name
 * @param uri URI
 * @param mappingData This structure will contain the result of the mapping
 *                    operation
 */
public void map(MessageBytes host, MessageBytes uri, String version,
                MappingData mappingData)
    throws Exception {

    if (host.isNull()) {
        host.getCharChunk().append(defaultHostName);
    }
    host.toChars();
    uri.toChars();
    internalMap(host.getCharChunk(), uri.getCharChunk(), version,
            mappingData);

}
 
Example 6
Source File: Mapper.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Map the specified URI relative to the context,
 * mutating the given mapping data.
 *
 * @param uri URI
 * @param mappingData This structure will contain the result of the mapping
 *                    operation
 */
public void map(MessageBytes uri, MappingData mappingData)
    throws Exception {

    uri.toChars();
    CharChunk uricc = uri.getCharChunk();
    uricc.setLimit(-1);
    internalMapWrapper(context, uricc, mappingData);

}
 
Example 7
Source File: Mapper.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Map the specified host name and URI, mutating the given mapping data.
 *
 * @param host Virtual host name
 * @param uri URI
 * @param mappingData This structure will contain the result of the mapping
 *                    operation
 */
public void map(MessageBytes host, MessageBytes uri, String version,
                MappingData mappingData)
    throws Exception {

    if (host.isNull()) {
        host.getCharChunk().append(defaultHostName);
    }
    host.toChars();
    uri.toChars();
    internalMap(host.getCharChunk(), uri.getCharChunk(), version,
            mappingData);

}
 
Example 8
Source File: Mapper.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Map the specified URI relative to the context,
 * mutating the given mapping data.
 *
 * @param uri URI
 * @param mappingData This structure will contain the result of the mapping
 *                    operation
 */
public void map(MessageBytes uri, MappingData mappingData)
    throws Exception {

    uri.toChars();
    CharChunk uricc = uri.getCharChunk();
    uricc.setLimit(-1);
    internalMapWrapper(context, uricc, mappingData);

}
 
Example 9
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 10
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 11
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());
}
 
Example 12
Source File: Mapper.java    From Tomcat8-Source-Read with MIT License 3 votes vote down vote up
/**
 * Map the specified URI relative to the context,
 * mutating the given mapping data.
 *
 * @param context The actual context
 * @param uri URI
 * @param mappingData This structure will contain the result of the mapping
 *                    operation
 * @throws IOException if the buffers are too small to hold the results of
 *                     the mapping.
 */
public void map(Context context, MessageBytes uri,
        MappingData mappingData) throws IOException {

    ContextVersion contextVersion =
            contextObjectToContextVersionMap.get(context);
    uri.toChars();
    CharChunk uricc = uri.getCharChunk();
    uricc.setLimit(-1);
    internalMapWrapper(contextVersion, uricc, mappingData);
}