本文整理汇总了Java中org.apache.tomcat.util.buf.MessageBytes.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java MessageBytes.newInstance方法的具体用法?Java MessageBytes.newInstance怎么用?Java MessageBytes.newInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tomcat.util.buf.MessageBytes
的用法示例。
在下文中一共展示了MessageBytes.newInstance方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPerformanceImpl
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
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;
}
示例2: mergeParameters
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
/**
* Merge the parameters from the saved query parameter string (if any), and
* the parameters already present on this request (if any), such that the
* parameter values from the query string show up first if there are
* duplicate parameter names.
*/
private void mergeParameters() {
if ((queryParamString == null) || (queryParamString.length() < 1))
return;
// Parse the query string from the dispatch target
Parameters paramParser = new Parameters();
MessageBytes queryMB = MessageBytes.newInstance();
queryMB.setString(queryParamString);
String encoding = getCharacterEncoding();
// No need to process null value, as ISO-8859-1 is the default encoding
// in MessageBytes.toBytes().
if (encoding != null) {
try {
queryMB.setCharset(B2CConverter.getCharset(encoding));
} catch (UnsupportedEncodingException ignored) {
// Fall-back to ISO-8859-1
}
}
paramParser.setQuery(queryMB);
paramParser.setQueryStringEncoding(encoding);
paramParser.handleQueryParameters();
// Insert the additional parameters from the dispatch target
Enumeration<String> dispParamNames = paramParser.getParameterNames();
while (dispParamNames.hasMoreElements()) {
String dispParamName = dispParamNames.nextElement();
String[] dispParamValues = paramParser.getParameterValues(dispParamName);
String[] originalValues = parameters.get(dispParamName);
if (originalValues == null) {
parameters.put(dispParamName, dispParamValues);
continue;
}
parameters.put(dispParamName, mergeValues(dispParamValues, originalValues));
}
}
示例3: mergeParameters
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
/**
* Merge the parameters from the saved query parameter string (if any), and
* the parameters already present on this request (if any), such that the
* parameter values from the query string show up first if there are
* duplicate parameter names.
*/
private void mergeParameters() {
if ((queryParamString == null) || (queryParamString.length() < 1))
return;
// Parse the query string from the dispatch target
Parameters paramParser = new Parameters();
MessageBytes queryMB = MessageBytes.newInstance();
queryMB.setString(queryParamString);
String encoding = getCharacterEncoding();
// No need to process null value, as ISO-8859-1 is the default encoding
// in MessageBytes.toBytes().
if (encoding != null) {
try {
queryMB.setCharset(B2CConverter.getCharset(encoding));
} catch (UnsupportedEncodingException ignored) {
// Fall-back to ISO-8859-1
}
}
paramParser.setQuery(queryMB);
paramParser.setQueryStringEncoding(encoding);
paramParser.handleQueryParameters();
// Insert the additional parameters from the dispatch target
Enumeration<String> dispParamNames = paramParser.getParameterNames();
while (dispParamNames.hasMoreElements()) {
String dispParamName = dispParamNames.nextElement();
String[] dispParamValues = paramParser.getParameterValues(dispParamName);
String[] originalValues = parameters.get(dispParamName);
if (originalValues == null) {
parameters.put(dispParamName, dispParamValues);
continue;
}
parameters.put(dispParamName, mergeValues(dispParamValues, originalValues));
}
}
示例4: DispatchData
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
public DispatchData() {
uriMB = MessageBytes.newInstance();
CharChunk uriCC = uriMB.getCharChunk();
uriCC.setLimit(-1);
mappingData = new MappingData();
}
示例5: testMap
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
@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());
}
示例6: testReloadContextVersion
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
@Test
public void testReloadContextVersion() throws Exception {
final String hostName = "iowejoiejfoiew";
final int iowPos = 3;
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.Host mappedHost = mapper.hosts[iowPos];
assertEquals(hostName, mappedHost.name);
Mapper.Context mappedContext = mappedHost.contextList.contexts[contextPos];
assertEquals(contextPath, mappedContext.name);
assertEquals(1, mappedContext.versions.length);
assertEquals("0", mappedContext.versions[0].name);
Object oldHost = mappedHost.object;
Object oldContext = mappedContext.versions[0].object;
assertEquals("context2", oldContext.toString());
Object oldContext1 = mappedHost.contextList.contexts[contextPos - 1].versions[0].object;
assertEquals("context1", oldContext1.toString());
mappingData.recycle();
mapper.map(hostMB, uriMB, null, mappingData);
assertEquals("blah7", mappingData.host.toString());
assertEquals("context2", mappingData.context.toString());
assertEquals("wrapper5", mappingData.wrapper.toString());
mappingData.recycle();
mapperForContext2.map(uriMB, mappingData);
assertEquals("wrapper5", mappingData.wrapper.toString());
// 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.toString());
assertEquals("context2", mappingData.context.toString());
// Wrapper is not mapped for incoming requests if context is paused
assertNull(mappingData.wrapper);
// 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(
"/", "newDefaultWrapper", false, false) }),
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.toString());
assertEquals("context2", mappingData.context.toString());
assertEquals("newDefaultWrapper", mappingData.wrapper.toString());
}
示例7: testContextListConcurrencyBug56653
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
@Test
public void testContextListConcurrencyBug56653() throws Exception {
final Object host = new Object(); // "localhost";
final Object contextRoot = new Object(); // "ROOT";
final Object context1 = new Object(); // "foo";
final Object context2 = new Object(); // "foo#bar";
final Object context3 = new Object(); // "foo#bar#bla";
final Object context4 = new Object(); // "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, false, false);
mapper.addContextVersion("localhost", host, "/foo", "0", context1,
new String[0], null, null, false, false);
mapper.addContextVersion("localhost", host, "/foo/bar", "0", context2,
new String[0], null, null, false, false);
mapper.addContextVersion("localhost", host, "/foo/bar/bla", "0",
context3, new String[0], null, null, false, false);
mapper.addContextVersion("localhost", host, "/foo/bar/bla/baz", "0",
context4, new String[0], null, null, false, false);
final AtomicBoolean running = new AtomicBoolean(true);
Thread t = new Thread() {
@Override
public void run() {
for (int i = 0; i < 100000; i++) {
mapper.removeContextVersion("localhost",
"/foo/bar/bla/baz", "0");
mapper.addContextVersion("localhost", host,
"/foo/bar/bla/baz", "0", context4, new String[0],
null, null, false, false);
}
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());
}
}
示例8: unregisterContext
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
/**
* Unregister context.
*/
private void unregisterContext(ObjectName objectName)
throws Exception {
String name = objectName.getKeyProperty("name");
// If the domain is the same with ours or the engine
// name attribute is the same... - then it's ours
String targetDomain=objectName.getDomain();
if( ! domain.equals( targetDomain )) {
try {
targetDomain = (String) mBeanServer.getAttribute
(objectName, "engineName");
} catch (Exception e) {
// Ignore
}
if( ! domain.equals( targetDomain )) {
// not ours
return;
}
}
String hostName = null;
String contextName = null;
if (name.startsWith("//")) {
name = name.substring(2);
}
int slash = name.indexOf("/");
if (slash != -1) {
hostName = name.substring(0, slash);
contextName = name.substring(slash);
} else {
return;
}
// Special case for the root context
if (contextName.equals("/")) {
contextName = "";
}
// Don't un-map a context that is paused
MessageBytes hostMB = MessageBytes.newInstance();
hostMB.setString(hostName);
MessageBytes contextMB = MessageBytes.newInstance();
contextMB.setString(contextName);
MappingData mappingData = new MappingData();
mapper.map(hostMB, contextMB, mappingData);
if (mappingData.context instanceof StandardContext &&
((StandardContext)mappingData.context).getPaused()) {
return;
}
if(log.isDebugEnabled())
log.debug(sm.getString
("mapperListener.unregisterContext", contextName));
mapper.removeContext(hostName, contextName);
}
示例9: getContext
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
/**
* Return a <code>ServletContext</code> object that corresponds to a
* specified URI on the server. This method allows servlets to gain
* access to the context for various parts of the server, and as needed
* obtain <code>RequestDispatcher</code> objects or resources from the
* context. The given path must be absolute (beginning with a "/"),
* and is interpreted based on our virtual host's document root.
*
* @param uri Absolute URI of a resource on the server
*/
@Override
public ServletContext getContext(String uri) {
// Validate the format of the specified argument
if (uri == null || !uri.startsWith("/")) {
return null;
}
Context child = null;
try {
// Look for an exact match
Container host = context.getParent();
child = (Context) host.findChild(uri);
// Non-running contexts should be ignored.
if (child != null && !child.getState().isAvailable()) {
child = null;
}
// Remove any version information and use the mapper
if (child == null) {
int i = uri.indexOf("##");
if (i > -1) {
uri = uri.substring(0, i);
}
// Note: This could be more efficient with a dedicated Mapper
// method but such an implementation would require some
// refactoring of the Mapper to avoid copy/paste of
// existing code.
MessageBytes hostMB = MessageBytes.newInstance();
hostMB.setString(host.getName());
MessageBytes pathMB = MessageBytes.newInstance();
pathMB.setString(uri);
MappingData mappingData = new MappingData();
((Engine) host.getParent()).getService().findConnectors()[0].getMapper().map(
hostMB, pathMB, null, mappingData);
child = (Context) mappingData.context;
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
return null;
}
if (child == null) {
return null;
}
if (context.getCrossContext()) {
// If crossContext is enabled, can always return the context
return child.getServletContext();
} else if (child == context) {
// Can still return the current context
return context.getServletContext();
} else {
// Nothing to return
return null;
}
}
示例10: DispatchData
import org.apache.tomcat.util.buf.MessageBytes; //导入方法依赖的package包/类
public DispatchData() {
uriMB = MessageBytes.newInstance();
CharChunk uriCC = uriMB.getCharChunk();
uriCC.setLimit(-1);
mappingData = new MappingData();
}