我在 openbravo 中收到此 "String index out of range " 3 错误
i m getting this "String index out of range " 3 error in openbravo
[http-apr-8080-exec-6] 错误 org.openbravo.client.kernel.KernelServlet - 字符串索引超出范围:3
java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:3
在 java.lang.String.charAt(来源不明)
在 org.apache.catalina.loader.WebappClassLoaderBase.filter(WebappClassLoaderBase.java:2780)
在 org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1253)
在 org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1142)
在 org.mozilla.javascript.Kit.classOrNull(Kit.java:92)
在 org.mozilla.javascript.NativeJavaPackage.getPkgProperty(NativeJavaPackage.java:159)
在 org.mozilla.javascript.NativeJavaPackage.get(NativeJavaPackage.java:114)
在 org.mozilla.javascript.NativeJavaTopPackage.init(NativeJavaTopPackage.java:128)
在 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
在 sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)
在 sun.reflect.DelegatingMethodAccessorImpl.invoke(来源不明)
在 java.lang.reflect.Method.invoke(来源不明)
在 org.mozilla.javascript.ScriptableObject.buildClassCtor(ScriptableObject.java:1030)
在 org.mozilla.javascript.LazilyLoadedCtor.buildValue(LazilyLoadedCtor.java:110)
在 org.mozilla.javascript.LazilyLoadedCtor.init(LazilyLoadedCtor.java:89)
在 org.mozilla.javascript.ScriptableObject.sealObject(ScriptableObject.java:1567)
在 com.googlecode.jslint4java.JSLint.(JSLint.java:113)
在 com.googlecode.jslint4java.JSLintBuilder.fromReader(JSLintBuilder.java:121)
在 com.googlecode.jslint4java.JSLintBuilder.fromClasspathResource(JSLintBuilder.java:54)
在 com.googlecode.jslint4java.JSLintBuilder.fromClasspathResource(JSLintBuilder.java:37)
在 com.googlecode.jslint4java.JSLintBuilder.fromDefault(JSLintBuilder.java:66)
在 org.openbravo.client.kernel.JSLintChecker.check(JSLintChecker.java:55)
在 org.openbravo.client.kernel.ComponentGenerator.generate(ComponentGenerator.java:68)
在 org.openbravo.client.kernel.KernelServlet.processComponentRequest(KernelServlet.java:242)
在 org.openbravo.client.kernel.KernelServlet.doGet(KernelServlet.java:188)
在 javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
在 org.openbravo.base.HttpBaseServlet.serviceInitialized(HttpBaseServlet.java:214)
在 org.openbravo.base.secureApp.HttpSecureAppServlet.service(HttpSecureAppServlet.java:428)
在 org.openbravo.client.kernel.BaseKernelServlet.callServiceInSuper(基础KernelServlet.java:88)
在 org.openbravo.client.kernel.BaseKernelServlet.service(基础KernelServlet.java:59)
在 org.openbravo.client.kernel.KernelServlet.service(KernelServlet.java:168)
在 javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
在 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
在 org.openbravo.utils.SessionExpirationFilter.doFilter(SessionExpirationFilter.java:66)
在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
在 org.openbravo.utils.CharsetFilter.doFilter(CharsetFilter.java:35)
在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
在 org.openbravo.client.kernel.KernelFilter$1.doAction(KernelFilter.java:62)
在 org.openbravo.dal.core.ThreadHandler.run(ThreadHandler.java:46)
在 org.openbravo.client.kernel.KernelFilter.doFilter(KernelFilter.java:71)
在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
在 org.openbravo.dal.core.DalRequestFilter$1.doAction(DalRequestFilter.java:81)
在 org.openbravo.dal.core.ThreadHandler.run(ThreadHandler.java:46)
在 org.openbravo.dal.core.DalRequestFilter.doFilter(DalRequestFilter.java:103)
在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
在 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
在 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
在 org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2500)
在 org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2489)
在 java.util.concurrent.ThreadPoolExecutor.runWorker(来源不明)
在 java.util.concurrent.ThreadPoolExecutor$Worker.run(未知来源)
在 org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
在 java.lang.Thread.run(来源不明)
[http-apr-8080-exec-6] 错误 org.openbravo.client.kernel.KernelUtils - 字符串索引超出范围:3
java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:3
请帮助我任何人在 openbravo 中遇到以上错误?
我被那个错误困住了,我正在尽我最大的努力来解决这个错误,但我无法解决这个问题,所以请帮助我.. 我为此附上了我的错误日志。
谢谢你..
我的 kernelservlet.java class
package org.openbravo.client.kernel;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.openbravo.base.ConfigParameters;
import org.openbravo.base.HttpBaseUtils;
import org.openbravo.base.exception.OBSecurityException;
import org.openbravo.base.util.OBClassLoader;
import org.openbravo.base.weld.WeldUtils;
import org.openbravo.dal.core.OBContext;
import org.openbravo.portal.PortalAccessible;
import org.openbravo.service.web.WebServiceUtil;
public class KernelServlet extends BaseKernelServlet {
// private static final Logger log = Logger.getLogger(DataSourceServlet.class);
private static final Logger log = Logger.getLogger(KernelServlet.class);
// this is needed to support logout deep in the code...
// TODO: make it easier to get to the authentication manager from
// the
public static final String KERNEL_SERVLET = "kernelServletInstance";
private static final String REQUEST_HEADER_IFMODIFIEDSINCE = "If-Modified-Since";
private static final String REQUEST_HEADER_IFNONEMATCH = "If-None-Match";
private static final long serialVersionUID = 1L;
private static String servletPathPart = "org.openbravo.client.kernel";
// are used to compute the relative path
private static ConfigParameters globalParameters;
private static ServletContext servletContext;
/**
* @return the parameters as they are defined in the servlet context.
*/
public static ConfigParameters getGlobalParameters() {
return globalParameters;
}
public static String getServletPathPart() {
return servletPathPart;
}
// the inc and dec by passauthentication count must be synchronized
// and static, there might be multiple kernelservlets and multiple threads
// may use the same kernelservlet
private static synchronized void incBypassAuthenticationCount(HttpServletRequest request) {
HttpSession session = request.getSession(true);
OBContext context = OBContext.getOBContext();
boolean sessionForThisRequest = context == null
|| session.getAttribute("#Authenticated_user") == null;
if (sessionForThisRequest) {
session.setAttribute("forceLogin", "Y");
}
if (session != null && "Y".equals(session.getAttribute("forceLogin"))) {
// session has been created to retrieve a non authenticated component, it might be several
// non authenticated components sharing the same session, count them to invalidate the
// session after all of them are done
Integer count = (Integer) session.getAttribute("forcedSessionsRequestCount");
if (count == null || count == 0) {
count = 1;
} else {
count += 1;
}
session.setAttribute("forcedSessionsRequestCount", count);
log.warn("The KernelServlet should not be used for unauthenticated access (this request url: "
+ request.getRequestURL()
+ " - "
+ request.getQueryString()
+ "). This functionality is deprecated, "
+ "use 'org.openbravo.mobile.core' instead of 'org.openbravo.client.kernel'; "
+ "see this issue https://issues.openbravo.com/view.php?id=27248 for more information");
}
}
private static synchronized void decBypassAuthenticationCount(HttpSession session,
HttpServletRequest request) {
if (session != null && "Y".equals(session.getAttribute("forceLogin"))) {
Integer count = (Integer) session.getAttribute("forcedSessionsRequestCount");
count = (count != null ? count : 0) - 1;
if (count <= 0) {
session.invalidate();
log.debug("Invalidating session created for bypass authentication elements");
} else {
session.setAttribute("forcedSessionsRequestCount", count);
}
log.warn("The KernelServlet should not be used for unauthenticated access (this request url: "
+ request.getRequestURL()
+ " - "
+ request.getQueryString()
+ "). This functionality is deprecated, "
+ "use 'org.openbravo.mobile.core' instead of 'org.openbravo.client.kernel'; "
+ "see this issue https://issues.openbravo.com/view.php?id=27248 for more information");
}
}
@Inject
@Any
private Instance<ComponentProvider> componentProviders;
@Inject
private WeldUtils weldUtils;
public void init(ServletConfig config) {
super.init(config);
globalParameters = ConfigParameters.retrieveFrom(config.getServletContext());
servletContext = config.getServletContext();
}
public void service(final HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
boolean bypassAuthentication = false;
final String action = request.getParameter(KernelConstants.ACTION_PARAMETER);
if (action == null) {
Component component = getComponent(request);
if (component instanceof BaseComponent && ((BaseComponent) component).bypassAuthentication()) {
bypassAuthentication = true;
incBypassAuthenticationCount(request);
}
}
super.service(request, response);
if (bypassAuthentication) {
HttpSession session = request.getSession(false);
decBypassAuthenticationCount(session, request);
}
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException {
if (!request.getRequestURI().contains("/" + servletPathPart)) {
throw new UnsupportedOperationException("Invalid url " + request.getRequestURI());
}
final String action = request.getParameter(KernelConstants.ACTION_PARAMETER);
if (action != null) {
processActionRequest(request, response);
} else {
processComponentRequest(request, response);
}
}
// NOTE: this exact same method is present in the MobileCoreComponentServlet in the mobile core
// module, if changed here, please also check the method in the MobileCoreComponentServlet class
private Component getComponent(HttpServletRequest request) {
final int nameIndex = request.getRequestURI().indexOf(servletPathPart);
final String servicePart = request.getRequestURI().substring(nameIndex);
final String[] pathParts = WebServiceUtil.getInstance().getSegments(servicePart);
if (pathParts.length < 2) {
throw new UnsupportedOperationException("No service name present in url "
+ request.getRequestURI());
}
final String componentProviderName = pathParts[1];
final ComponentProvider componentProvider = componentProviders.select(
new ComponentProvider.Selector(componentProviderName)).get();
final String componentId;
if (pathParts.length > 2) {
componentId = pathParts[2];
} else {
componentId = null;
}
final Map<String, Object> parameters = getParameterMap(request);
final Component component = componentProvider.getComponent(componentId, parameters);
return component;
}
// NOTE: this exact same method is present in the MobileCoreComponentServlet in the mobile core
// module, if changed here, please also check the method in the MobileCoreComponentServlet class
protected void processComponentRequest(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
Component component = getComponent(request);
OBContext.setAdminMode();
String eTag;
try {
eTag = component.getETag();
} finally {
OBContext.restorePreviousMode();
}
final String requestETag = request.getHeader(REQUEST_HEADER_IFNONEMATCH);
if (requestETag != null && eTag.equals(requestETag)) {
response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
response.setDateHeader(RESPONSE_HEADER_LASTMODIFIED,
request.getDateHeader(REQUEST_HEADER_IFMODIFIEDSINCE));
return;
}
try {
final String result = ComponentGenerator.getInstance().generate(component);
response.setHeader(RESPONSE_HEADER_ETAG, eTag);
response.setDateHeader(RESPONSE_HEADER_LASTMODIFIED, component.getLastModified().getTime());
response.setContentType(component.getContentType());
response.setHeader(RESPONSE_HEADER_CONTENTTYPE, component.getContentType());
response.setHeader(RESPONSE_HEADER_CACHE_CONTROL, RESPONSE_NO_CACHE);
final PrintWriter pw = response.getWriter();
pw.write(result);
pw.close();
} catch (Exception e) {
log.error(e.getMessage(), e);
if (!response.isCommitted()) {
response.setContentType(KernelConstants.JAVASCRIPT_CONTENTTYPE);
response.setHeader(RESPONSE_HEADER_CONTENTTYPE, KernelConstants.JAVASCRIPT_CONTENTTYPE);
response.setHeader(RESPONSE_HEADER_CACHE_CONTROL, RESPONSE_NO_CACHE);
response.getWriter().write(KernelUtils.getInstance().createErrorJavaScript(e));
}
}
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException {
doGet(request, response);
}
protected void processActionRequest(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
final String action = request.getParameter(KernelConstants.ACTION_PARAMETER);
response.setContentType(KernelConstants.JAVASCRIPT_CONTENTTYPE);
response.setHeader(RESPONSE_HEADER_CONTENTTYPE, KernelConstants.JAVASCRIPT_CONTENTTYPE);
response.setHeader(RESPONSE_HEADER_CACHE_CONTROL, RESPONSE_NO_CACHE);
try {
@SuppressWarnings("unchecked")
final Class<ActionHandler> actionHandlerClass = (Class<ActionHandler>) OBClassLoader
.getInstance().loadClass(action);
final ActionHandler actionHandler = weldUtils.getInstance(actionHandlerClass);
if (OBContext.getOBContext() != null && OBContext.getOBContext().isPortalRole()) {
if (!(actionHandler instanceof PortalAccessible)) {
log.error("Portal user " + OBContext.getOBContext().getUser() + " with role "
+ OBContext.getOBContext().getRole()
+ " is trying to access to non granted action handler " + request.getRequestURL()
+ "?" + request.getQueryString());
throw new OBSecurityException("Portal role has no access to this handler");
}
}
actionHandler.execute();
} catch (Exception e) {
log.error("Error executing action " + action + " error: " + e.getMessage(), e);
if (!response.isCommitted()) {
response.setContentType(KernelConstants.JAVASCRIPT_CONTENTTYPE);
response.setHeader(RESPONSE_HEADER_CONTENTTYPE, KernelConstants.JAVASCRIPT_CONTENTTYPE);
response.setHeader(RESPONSE_HEADER_CACHE_CONTROL, RESPONSE_NO_CACHE);
response.getWriter().write(KernelUtils.getInstance().createErrorJavaScript(e));
}
}
}
@Override
public void doDelete(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
throw new UnsupportedOperationException("Only GET/POST is supported");
}
@Override
public void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException {
throw new UnsupportedOperationException("Only GET/POST is supported");
}
@SuppressWarnings("rawtypes")
private Map<String, Object> getParameterMap(HttpServletRequest request) {
final Map<String, Object> parameterMap = new HashMap<String, Object>();
for (Enumeration keys = request.getParameterNames(); keys.hasMoreElements();) {
final String key = (String) keys.nextElement();
parameterMap.put(key, request.getParameter(key));
}
if (!parameterMap.containsKey(KernelConstants.HTTP_SESSION)) {
parameterMap.put(KernelConstants.HTTP_SESSION, request.getSession());
}
if (!parameterMap.containsKey(KernelConstants.CONTEXT_URL)) {
parameterMap.put(KernelConstants.CONTEXT_URL, computeContextURL(request));
}
if (!parameterMap.containsKey(KernelConstants.SERVLET_CONTEXT)) {
parameterMap.put(KernelConstants.SERVLET_CONTEXT, servletContext);
}
if (!parameterMap.containsKey(KernelConstants.SKIN_PARAMETER)) {
parameterMap.put(KernelConstants.SKIN_PARAMETER, KernelConstants.SKIN_DEFAULT);
}
return parameterMap;
}
private String computeContextURL(HttpServletRequest request) {
return HttpBaseUtils.getLocalAddress(request);
}
}
你检查过日志文件了吗?您是否收到 Error executing action
之类的错误消息。
你得到 StringIndexOutOfBoundsException
可能是因为 NullPointerException
在下面的代码中将你的异常转换为 java-script-error
response.getWriter().write(KernelUtils.getInstance().createErrorJavaScript(e));
我得到的答案不是我的错,但我使用 tomcat 版本 8.0.32 并且有错误所以为了解决这个问题我有 将我的 tomcat 版本从 8.0.32 降级到 8.0.26 以解决我的问题。
以上错误是 tomcat 本身的错误。所以通过 link 来解决这个问题。
谢谢。
[http-apr-8080-exec-6] 错误 org.openbravo.client.kernel.KernelServlet - 字符串索引超出范围:3 java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:3 在 java.lang.String.charAt(来源不明) 在 org.apache.catalina.loader.WebappClassLoaderBase.filter(WebappClassLoaderBase.java:2780) 在 org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1253) 在 org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1142) 在 org.mozilla.javascript.Kit.classOrNull(Kit.java:92) 在 org.mozilla.javascript.NativeJavaPackage.getPkgProperty(NativeJavaPackage.java:159) 在 org.mozilla.javascript.NativeJavaPackage.get(NativeJavaPackage.java:114) 在 org.mozilla.javascript.NativeJavaTopPackage.init(NativeJavaTopPackage.java:128) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) 在 sun.reflect.NativeMethodAccessorImpl.invoke(未知来源) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(来源不明) 在 java.lang.reflect.Method.invoke(来源不明) 在 org.mozilla.javascript.ScriptableObject.buildClassCtor(ScriptableObject.java:1030) 在 org.mozilla.javascript.LazilyLoadedCtor.buildValue(LazilyLoadedCtor.java:110) 在 org.mozilla.javascript.LazilyLoadedCtor.init(LazilyLoadedCtor.java:89) 在 org.mozilla.javascript.ScriptableObject.sealObject(ScriptableObject.java:1567) 在 com.googlecode.jslint4java.JSLint.(JSLint.java:113) 在 com.googlecode.jslint4java.JSLintBuilder.fromReader(JSLintBuilder.java:121) 在 com.googlecode.jslint4java.JSLintBuilder.fromClasspathResource(JSLintBuilder.java:54) 在 com.googlecode.jslint4java.JSLintBuilder.fromClasspathResource(JSLintBuilder.java:37) 在 com.googlecode.jslint4java.JSLintBuilder.fromDefault(JSLintBuilder.java:66) 在 org.openbravo.client.kernel.JSLintChecker.check(JSLintChecker.java:55) 在 org.openbravo.client.kernel.ComponentGenerator.generate(ComponentGenerator.java:68) 在 org.openbravo.client.kernel.KernelServlet.processComponentRequest(KernelServlet.java:242) 在 org.openbravo.client.kernel.KernelServlet.doGet(KernelServlet.java:188) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:622) 在 org.openbravo.base.HttpBaseServlet.serviceInitialized(HttpBaseServlet.java:214) 在 org.openbravo.base.secureApp.HttpSecureAppServlet.service(HttpSecureAppServlet.java:428) 在 org.openbravo.client.kernel.BaseKernelServlet.callServiceInSuper(基础KernelServlet.java:88) 在 org.openbravo.client.kernel.BaseKernelServlet.service(基础KernelServlet.java:59) 在 org.openbravo.client.kernel.KernelServlet.service(KernelServlet.java:168) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) 在 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) 在 org.openbravo.utils.SessionExpirationFilter.doFilter(SessionExpirationFilter.java:66) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) 在 org.openbravo.utils.CharsetFilter.doFilter(CharsetFilter.java:35) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) 在 org.openbravo.client.kernel.KernelFilter$1.doAction(KernelFilter.java:62) 在 org.openbravo.dal.core.ThreadHandler.run(ThreadHandler.java:46) 在 org.openbravo.client.kernel.KernelFilter.doFilter(KernelFilter.java:71) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) 在 org.openbravo.dal.core.DalRequestFilter$1.doAction(DalRequestFilter.java:81) 在 org.openbravo.dal.core.ThreadHandler.run(ThreadHandler.java:46) 在 org.openbravo.dal.core.DalRequestFilter.doFilter(DalRequestFilter.java:103) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) 在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522) 在 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095) 在 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672) 在 org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2500) 在 org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2489) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(来源不明) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(未知来源) 在 org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 在 java.lang.Thread.run(来源不明) [http-apr-8080-exec-6] 错误 org.openbravo.client.kernel.KernelUtils - 字符串索引超出范围:3
java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:3
请帮助我任何人在 openbravo 中遇到以上错误? 我被那个错误困住了,我正在尽我最大的努力来解决这个错误,但我无法解决这个问题,所以请帮助我.. 我为此附上了我的错误日志。 谢谢你.. 我的 kernelservlet.java class
package org.openbravo.client.kernel;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.openbravo.base.ConfigParameters;
import org.openbravo.base.HttpBaseUtils;
import org.openbravo.base.exception.OBSecurityException;
import org.openbravo.base.util.OBClassLoader;
import org.openbravo.base.weld.WeldUtils;
import org.openbravo.dal.core.OBContext;
import org.openbravo.portal.PortalAccessible;
import org.openbravo.service.web.WebServiceUtil;
public class KernelServlet extends BaseKernelServlet {
// private static final Logger log = Logger.getLogger(DataSourceServlet.class);
private static final Logger log = Logger.getLogger(KernelServlet.class);
// this is needed to support logout deep in the code...
// TODO: make it easier to get to the authentication manager from
// the
public static final String KERNEL_SERVLET = "kernelServletInstance";
private static final String REQUEST_HEADER_IFMODIFIEDSINCE = "If-Modified-Since";
private static final String REQUEST_HEADER_IFNONEMATCH = "If-None-Match";
private static final long serialVersionUID = 1L;
private static String servletPathPart = "org.openbravo.client.kernel";
// are used to compute the relative path
private static ConfigParameters globalParameters;
private static ServletContext servletContext;
/**
* @return the parameters as they are defined in the servlet context.
*/
public static ConfigParameters getGlobalParameters() {
return globalParameters;
}
public static String getServletPathPart() {
return servletPathPart;
}
// the inc and dec by passauthentication count must be synchronized
// and static, there might be multiple kernelservlets and multiple threads
// may use the same kernelservlet
private static synchronized void incBypassAuthenticationCount(HttpServletRequest request) {
HttpSession session = request.getSession(true);
OBContext context = OBContext.getOBContext();
boolean sessionForThisRequest = context == null
|| session.getAttribute("#Authenticated_user") == null;
if (sessionForThisRequest) {
session.setAttribute("forceLogin", "Y");
}
if (session != null && "Y".equals(session.getAttribute("forceLogin"))) {
// session has been created to retrieve a non authenticated component, it might be several
// non authenticated components sharing the same session, count them to invalidate the
// session after all of them are done
Integer count = (Integer) session.getAttribute("forcedSessionsRequestCount");
if (count == null || count == 0) {
count = 1;
} else {
count += 1;
}
session.setAttribute("forcedSessionsRequestCount", count);
log.warn("The KernelServlet should not be used for unauthenticated access (this request url: "
+ request.getRequestURL()
+ " - "
+ request.getQueryString()
+ "). This functionality is deprecated, "
+ "use 'org.openbravo.mobile.core' instead of 'org.openbravo.client.kernel'; "
+ "see this issue https://issues.openbravo.com/view.php?id=27248 for more information");
}
}
private static synchronized void decBypassAuthenticationCount(HttpSession session,
HttpServletRequest request) {
if (session != null && "Y".equals(session.getAttribute("forceLogin"))) {
Integer count = (Integer) session.getAttribute("forcedSessionsRequestCount");
count = (count != null ? count : 0) - 1;
if (count <= 0) {
session.invalidate();
log.debug("Invalidating session created for bypass authentication elements");
} else {
session.setAttribute("forcedSessionsRequestCount", count);
}
log.warn("The KernelServlet should not be used for unauthenticated access (this request url: "
+ request.getRequestURL()
+ " - "
+ request.getQueryString()
+ "). This functionality is deprecated, "
+ "use 'org.openbravo.mobile.core' instead of 'org.openbravo.client.kernel'; "
+ "see this issue https://issues.openbravo.com/view.php?id=27248 for more information");
}
}
@Inject
@Any
private Instance<ComponentProvider> componentProviders;
@Inject
private WeldUtils weldUtils;
public void init(ServletConfig config) {
super.init(config);
globalParameters = ConfigParameters.retrieveFrom(config.getServletContext());
servletContext = config.getServletContext();
}
public void service(final HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
boolean bypassAuthentication = false;
final String action = request.getParameter(KernelConstants.ACTION_PARAMETER);
if (action == null) {
Component component = getComponent(request);
if (component instanceof BaseComponent && ((BaseComponent) component).bypassAuthentication()) {
bypassAuthentication = true;
incBypassAuthenticationCount(request);
}
}
super.service(request, response);
if (bypassAuthentication) {
HttpSession session = request.getSession(false);
decBypassAuthenticationCount(session, request);
}
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException {
if (!request.getRequestURI().contains("/" + servletPathPart)) {
throw new UnsupportedOperationException("Invalid url " + request.getRequestURI());
}
final String action = request.getParameter(KernelConstants.ACTION_PARAMETER);
if (action != null) {
processActionRequest(request, response);
} else {
processComponentRequest(request, response);
}
}
// NOTE: this exact same method is present in the MobileCoreComponentServlet in the mobile core
// module, if changed here, please also check the method in the MobileCoreComponentServlet class
private Component getComponent(HttpServletRequest request) {
final int nameIndex = request.getRequestURI().indexOf(servletPathPart);
final String servicePart = request.getRequestURI().substring(nameIndex);
final String[] pathParts = WebServiceUtil.getInstance().getSegments(servicePart);
if (pathParts.length < 2) {
throw new UnsupportedOperationException("No service name present in url "
+ request.getRequestURI());
}
final String componentProviderName = pathParts[1];
final ComponentProvider componentProvider = componentProviders.select(
new ComponentProvider.Selector(componentProviderName)).get();
final String componentId;
if (pathParts.length > 2) {
componentId = pathParts[2];
} else {
componentId = null;
}
final Map<String, Object> parameters = getParameterMap(request);
final Component component = componentProvider.getComponent(componentId, parameters);
return component;
}
// NOTE: this exact same method is present in the MobileCoreComponentServlet in the mobile core
// module, if changed here, please also check the method in the MobileCoreComponentServlet class
protected void processComponentRequest(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
Component component = getComponent(request);
OBContext.setAdminMode();
String eTag;
try {
eTag = component.getETag();
} finally {
OBContext.restorePreviousMode();
}
final String requestETag = request.getHeader(REQUEST_HEADER_IFNONEMATCH);
if (requestETag != null && eTag.equals(requestETag)) {
response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
response.setDateHeader(RESPONSE_HEADER_LASTMODIFIED,
request.getDateHeader(REQUEST_HEADER_IFMODIFIEDSINCE));
return;
}
try {
final String result = ComponentGenerator.getInstance().generate(component);
response.setHeader(RESPONSE_HEADER_ETAG, eTag);
response.setDateHeader(RESPONSE_HEADER_LASTMODIFIED, component.getLastModified().getTime());
response.setContentType(component.getContentType());
response.setHeader(RESPONSE_HEADER_CONTENTTYPE, component.getContentType());
response.setHeader(RESPONSE_HEADER_CACHE_CONTROL, RESPONSE_NO_CACHE);
final PrintWriter pw = response.getWriter();
pw.write(result);
pw.close();
} catch (Exception e) {
log.error(e.getMessage(), e);
if (!response.isCommitted()) {
response.setContentType(KernelConstants.JAVASCRIPT_CONTENTTYPE);
response.setHeader(RESPONSE_HEADER_CONTENTTYPE, KernelConstants.JAVASCRIPT_CONTENTTYPE);
response.setHeader(RESPONSE_HEADER_CACHE_CONTROL, RESPONSE_NO_CACHE);
response.getWriter().write(KernelUtils.getInstance().createErrorJavaScript(e));
}
}
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException {
doGet(request, response);
}
protected void processActionRequest(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
final String action = request.getParameter(KernelConstants.ACTION_PARAMETER);
response.setContentType(KernelConstants.JAVASCRIPT_CONTENTTYPE);
response.setHeader(RESPONSE_HEADER_CONTENTTYPE, KernelConstants.JAVASCRIPT_CONTENTTYPE);
response.setHeader(RESPONSE_HEADER_CACHE_CONTROL, RESPONSE_NO_CACHE);
try {
@SuppressWarnings("unchecked")
final Class<ActionHandler> actionHandlerClass = (Class<ActionHandler>) OBClassLoader
.getInstance().loadClass(action);
final ActionHandler actionHandler = weldUtils.getInstance(actionHandlerClass);
if (OBContext.getOBContext() != null && OBContext.getOBContext().isPortalRole()) {
if (!(actionHandler instanceof PortalAccessible)) {
log.error("Portal user " + OBContext.getOBContext().getUser() + " with role "
+ OBContext.getOBContext().getRole()
+ " is trying to access to non granted action handler " + request.getRequestURL()
+ "?" + request.getQueryString());
throw new OBSecurityException("Portal role has no access to this handler");
}
}
actionHandler.execute();
} catch (Exception e) {
log.error("Error executing action " + action + " error: " + e.getMessage(), e);
if (!response.isCommitted()) {
response.setContentType(KernelConstants.JAVASCRIPT_CONTENTTYPE);
response.setHeader(RESPONSE_HEADER_CONTENTTYPE, KernelConstants.JAVASCRIPT_CONTENTTYPE);
response.setHeader(RESPONSE_HEADER_CACHE_CONTROL, RESPONSE_NO_CACHE);
response.getWriter().write(KernelUtils.getInstance().createErrorJavaScript(e));
}
}
}
@Override
public void doDelete(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
throw new UnsupportedOperationException("Only GET/POST is supported");
}
@Override
public void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException {
throw new UnsupportedOperationException("Only GET/POST is supported");
}
@SuppressWarnings("rawtypes")
private Map<String, Object> getParameterMap(HttpServletRequest request) {
final Map<String, Object> parameterMap = new HashMap<String, Object>();
for (Enumeration keys = request.getParameterNames(); keys.hasMoreElements();) {
final String key = (String) keys.nextElement();
parameterMap.put(key, request.getParameter(key));
}
if (!parameterMap.containsKey(KernelConstants.HTTP_SESSION)) {
parameterMap.put(KernelConstants.HTTP_SESSION, request.getSession());
}
if (!parameterMap.containsKey(KernelConstants.CONTEXT_URL)) {
parameterMap.put(KernelConstants.CONTEXT_URL, computeContextURL(request));
}
if (!parameterMap.containsKey(KernelConstants.SERVLET_CONTEXT)) {
parameterMap.put(KernelConstants.SERVLET_CONTEXT, servletContext);
}
if (!parameterMap.containsKey(KernelConstants.SKIN_PARAMETER)) {
parameterMap.put(KernelConstants.SKIN_PARAMETER, KernelConstants.SKIN_DEFAULT);
}
return parameterMap;
}
private String computeContextURL(HttpServletRequest request) {
return HttpBaseUtils.getLocalAddress(request);
}
}
你检查过日志文件了吗?您是否收到 Error executing action
之类的错误消息。
你得到 StringIndexOutOfBoundsException
可能是因为 NullPointerException
在下面的代码中将你的异常转换为 java-script-error
response.getWriter().write(KernelUtils.getInstance().createErrorJavaScript(e));
我得到的答案不是我的错,但我使用 tomcat 版本 8.0.32 并且有错误所以为了解决这个问题我有 将我的 tomcat 版本从 8.0.32 降级到 8.0.26 以解决我的问题。
以上错误是 tomcat 本身的错误。所以通过 link 来解决这个问题。
谢谢。