use of org.apache.tomcat.util.buf.MessageBytes in project tomcat by apache.
the class Rfc6265CookieProcessor method parseCookieHeader.
@Override
public void parseCookieHeader(MimeHeaders headers, ServerCookies serverCookies) {
if (headers == null) {
// nothing to process
return;
}
// process each "cookie" header
int pos = headers.findHeader("Cookie", 0);
while (pos >= 0) {
MessageBytes cookieValue = headers.getValue(pos);
if (cookieValue != null && !cookieValue.isNull()) {
if (cookieValue.getType() != MessageBytes.T_BYTES) {
if (log.isDebugEnabled()) {
Exception e = new Exception();
// TODO: Review this in light of HTTP/2
log.debug("Cookies: Parsing cookie as String. Expected bytes.", e);
}
cookieValue.toBytes();
}
if (log.isDebugEnabled()) {
log.debug("Cookies: Parsing b[]: " + cookieValue.toString());
}
ByteChunk bc = cookieValue.getByteChunk();
Cookie.parseCookie(bc.getBytes(), bc.getOffset(), bc.getLength(), serverCookies);
}
// search from the next position
pos = headers.findHeader("Cookie", ++pos);
}
}
use of org.apache.tomcat.util.buf.MessageBytes in project tomcat by apache.
the class TestMapper method testAddRemoveContextVersion.
@Test
public void testAddRemoveContextVersion() throws Exception {
final String hostName = "iowejoiejfoiew";
final int iowPos = 4;
final String contextPath = "/foo/bar";
final int contextPos = 2;
MappingData mappingData = new MappingData();
MessageBytes hostMB = MessageBytes.newInstance();
MessageBytes uriMB = MessageBytes.newInstance();
hostMB.setString(hostName);
uriMB.setString("/foo/bar/blah/bobou/foo");
// Verifying configuration created by setUp()
Mapper.MappedHost mappedHost = mapper.hosts[iowPos];
assertEquals(hostName, mappedHost.name);
Mapper.MappedContext mappedContext = mappedHost.contextList.contexts[contextPos];
assertEquals(contextPath, mappedContext.name);
assertEquals(1, mappedContext.versions.length);
assertEquals("0", mappedContext.versions[0].name);
Host oldHost = mappedHost.object;
Context oldContext = mappedContext.versions[0].object;
assertEquals("context2", oldContext.getName());
Context oldContext1 = mappedHost.contextList.contexts[contextPos - 1].versions[0].object;
assertEquals("context1", oldContext1.getName());
mappingData.recycle();
mapper.map(hostMB, uriMB, null, mappingData);
assertEquals("blah7", mappingData.host.getName());
assertEquals("context2", mappingData.context.getName());
assertEquals("wrapper5", mappingData.wrapper.getName());
mappingData.recycle();
mapper.map(oldContext, uriMB, mappingData);
assertEquals("wrapper5", mappingData.wrapper.getName());
Context newContext = createContext("newContext");
mapper.addContextVersion(hostName, oldHost, contextPath, "1", newContext, null, null, Arrays.asList(new WrapperMappingInfo[] { new WrapperMappingInfo("/", createWrapper("newContext-default"), false, false) }));
assertEquals(2, mappedContext.versions.length);
assertEquals("0", mappedContext.versions[0].name);
assertEquals("1", mappedContext.versions[1].name);
mappingData.recycle();
mapper.map(hostMB, uriMB, null, mappingData);
assertEquals("newContext", mappingData.context.getName());
assertEquals("newContext-default", mappingData.wrapper.getName());
mappingData.recycle();
mapper.map(newContext, uriMB, mappingData);
assertEquals("newContext-default", mappingData.wrapper.getName());
mapper.removeContextVersion(oldContext, hostName, contextPath, "0");
assertEquals(1, mappedContext.versions.length);
assertEquals("1", mappedContext.versions[0].name);
mappingData.recycle();
mapper.map(hostMB, uriMB, null, mappingData);
assertEquals("newContext", mappingData.context.getName());
assertEquals("newContext-default", mappingData.wrapper.getName());
mappingData.recycle();
mapper.map(newContext, uriMB, mappingData);
assertEquals("newContext-default", mappingData.wrapper.getName());
mapper.removeContextVersion(oldContext, hostName, contextPath, "1");
assertNotSame(mappedContext, mappedHost.contextList.contexts[contextPos]);
assertEquals("/foo/bar/bla", mappedHost.contextList.contexts[contextPos].name);
mappingData.recycle();
mapper.map(hostMB, uriMB, null, mappingData);
assertEquals("context1", mappingData.context.getName());
assertEquals("context1-defaultWrapper", mappingData.wrapper.getName());
mappingData.recycle();
mapper.map(oldContext1, uriMB, mappingData);
assertEquals("context1-defaultWrapper", mappingData.wrapper.getName());
mapper.addContextVersion(hostName, oldHost, contextPath, "0", newContext, null, null, Arrays.asList(new WrapperMappingInfo[] { new WrapperMappingInfo("/", createWrapper("newContext-defaultWrapper2"), false, false) }));
mappedContext = mappedHost.contextList.contexts[contextPos];
assertEquals(contextPath, mappedContext.name);
assertEquals(1, mappedContext.versions.length);
assertEquals("0", mappedContext.versions[0].name);
mappingData.recycle();
mapper.map(hostMB, uriMB, null, mappingData);
assertEquals("newContext", mappingData.context.getName());
assertEquals("newContext-defaultWrapper2", mappingData.wrapper.getName());
mappingData.recycle();
mapper.map(newContext, uriMB, mappingData);
assertEquals("newContext-defaultWrapper2", mappingData.wrapper.getName());
}
use of org.apache.tomcat.util.buf.MessageBytes in project tomcat by apache.
the class TestMapper method testMap.
@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);
assertEquals("blah7", mappingData.host.getName());
assertEquals("context2", mappingData.context.getName());
assertEquals("wrapper5", mappingData.wrapper.getName());
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.getName());
assertEquals("context3", mappingData.context.getName());
assertEquals("wrapper7", mappingData.wrapper.getName());
assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
assertEquals("/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(wildcard, uri, null, mappingData);
assertEquals("blah16", mappingData.host.getName());
assertEquals("context4", mappingData.context.getName());
assertEquals("context4-defaultWrapper", mappingData.wrapper.getName());
assertEquals("", mappingData.contextPath.toString());
assertEquals("/foo/bar/bla/bobou/foo", mappingData.wrapperPath.toString());
assertTrue(mappingData.pathInfo.isNull());
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.getName());
assertEquals("context3", mappingData.context.getName());
assertEquals("wrapper7", mappingData.wrapper.getName());
assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
assertEquals("/bobou", mappingData.wrapperPath.toString());
assertEquals("/foo", mappingData.pathInfo.toString());
assertTrue(mappingData.redirectPath.isNull());
}
use of org.apache.tomcat.util.buf.MessageBytes in project tomcat by apache.
the class TestMapper method testContextListConcurrencyBug56653.
@Test
public void testContextListConcurrencyBug56653() throws Exception {
final Host host = createHost("localhost");
final Context contextRoot = createContext("ROOT");
final Context context1 = createContext("foo");
final Context context2 = createContext("foo#bar");
final Context context3 = createContext("foo#bar#bla");
final Context context4 = createContext("foo#bar#bla#baz");
mapper.addHost("localhost", new String[] { "alias" }, host);
mapper.setDefaultHostName("localhost");
mapper.addContextVersion("localhost", host, "", "0", contextRoot, new String[0], null, null);
mapper.addContextVersion("localhost", host, "/foo", "0", context1, new String[0], null, null);
mapper.addContextVersion("localhost", host, "/foo/bar", "0", context2, new String[0], null, null);
mapper.addContextVersion("localhost", host, "/foo/bar/bla", "0", context3, new String[0], null, null);
mapper.addContextVersion("localhost", host, "/foo/bar/bla/baz", "0", context4, new String[0], null, null);
final AtomicBoolean running = new AtomicBoolean(true);
Thread t = new Thread() {
@Override
public void run() {
for (int i = 0; i < 100000; i++) {
mapper.removeContextVersion(context4, "localhost", "/foo/bar/bla/baz", "0");
mapper.addContextVersion("localhost", host, "/foo/bar/bla/baz", "0", context4, new String[0], null, null);
}
running.set(false);
}
};
MappingData mappingData = new MappingData();
MessageBytes hostMB = MessageBytes.newInstance();
hostMB.setString("localhost");
MessageBytes aliasMB = MessageBytes.newInstance();
aliasMB.setString("alias");
MessageBytes uriMB = MessageBytes.newInstance();
char[] uri = "/foo/bar/bla/bobou/foo".toCharArray();
uriMB.setChars(uri, 0, uri.length);
mapper.map(hostMB, uriMB, null, mappingData);
assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
mappingData.recycle();
uriMB.setChars(uri, 0, uri.length);
mapper.map(aliasMB, uriMB, null, mappingData);
assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
t.start();
while (running.get()) {
mappingData.recycle();
uriMB.setChars(uri, 0, uri.length);
mapper.map(hostMB, uriMB, null, mappingData);
assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
mappingData.recycle();
uriMB.setChars(uri, 0, uri.length);
mapper.map(aliasMB, uriMB, null, mappingData);
assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
}
}
use of org.apache.tomcat.util.buf.MessageBytes in project tomcat by apache.
the class TestMapper method testReloadContextVersion.
@Test
public void testReloadContextVersion() throws Exception {
final String hostName = "iowejoiejfoiew";
final int iowPos = 4;
final String contextPath = "/foo/bar";
final int contextPos = 2;
MappingData mappingData = new MappingData();
MessageBytes hostMB = MessageBytes.newInstance();
MessageBytes uriMB = MessageBytes.newInstance();
hostMB.setString(hostName);
uriMB.setString("/foo/bar/blah/bobou/foo");
// Verifying configuration created by setUp()
Mapper.MappedHost mappedHost = mapper.hosts[iowPos];
assertEquals(hostName, mappedHost.name);
Mapper.MappedContext mappedContext = mappedHost.contextList.contexts[contextPos];
assertEquals(contextPath, mappedContext.name);
assertEquals(1, mappedContext.versions.length);
assertEquals("0", mappedContext.versions[0].name);
Host oldHost = mappedHost.object;
Context oldContext = mappedContext.versions[0].object;
assertEquals("context2", oldContext.getName());
Context oldContext1 = mappedHost.contextList.contexts[contextPos - 1].versions[0].object;
assertEquals("context1", oldContext1.getName());
mappingData.recycle();
mapper.map(hostMB, uriMB, null, mappingData);
assertEquals("blah7", mappingData.host.getName());
assertEquals("context2", mappingData.context.getName());
assertEquals("wrapper5", mappingData.wrapper.getName());
mappingData.recycle();
mapper.map(oldContext, uriMB, mappingData);
assertEquals("wrapper5", mappingData.wrapper.getName());
// Mark context as paused
// This is what happens when context reload starts
mapper.pauseContextVersion(oldContext, hostName, contextPath, "0");
mappingData.recycle();
mapper.map(hostMB, uriMB, null, mappingData);
assertEquals("blah7", mappingData.host.getName());
assertEquals("context2", mappingData.context.getName());
// Wrapper is not mapped for incoming requests if context is paused
assertNull(mappingData.wrapper);
mappingData.recycle();
mapper.map(oldContext, uriMB, mappingData);
// Wrapper is mapped for mapping method used by forward or include dispatch
assertEquals("wrapper5", mappingData.wrapper.getName());
// Re-add the same context, but different list of wrappers
// This is what happens when context reload completes
mapper.addContextVersion(hostName, oldHost, contextPath, "0", oldContext, null, null, Arrays.asList(new WrapperMappingInfo[] { new WrapperMappingInfo("/", createWrapper("newDefaultWrapper"), false, false) }));
mappedContext = mappedHost.contextList.contexts[contextPos];
assertEquals(contextPath, mappedContext.name);
assertEquals(1, mappedContext.versions.length);
assertEquals("0", mappedContext.versions[0].name);
mappingData.recycle();
mapper.map(hostMB, uriMB, null, mappingData);
assertEquals("blah7", mappingData.host.getName());
assertEquals("context2", mappingData.context.getName());
assertEquals("newDefaultWrapper", mappingData.wrapper.getName());
mappingData.recycle();
mapper.map(oldContext, uriMB, mappingData);
assertEquals("newDefaultWrapper", mappingData.wrapper.getName());
}
Aggregations