I can not catch errors - java

Hi I have made ​​an if query and this question goes to the server. However, the server will only accept 2 numbers and a decimal number (99.9) but I have to count up to 100, the server always gives me an error.
Do you know maybe how I can catch this error so that my software anyway Counts to 100. It must not be output to the server. The program should run only on. He shall not make it stop at 99 again and continue counting down So when he comes at 99 and then 100.
public static void main(String[] args)
{
boolean positive = true;
int counter = 0;
while (true)
{
if (counter >= 99)
{
positive = false;
}
if (counter <=-99)
{
positive = true;
}
if (positive == true)
{
counter ++;
}
else
{
counter --;
}
That's my "Software" And the Exception is:
Exception = Response was of unexpected text/html ContentType. Incoming portion of HTML stream: <html><head><title>Apache Tomcat/7.0.47 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - Request processing failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/QueryTimeoutException</h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u>Request processing failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/QueryTimeoutException</u></p><p><b>description</b> <u>The server encountered an internal error that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/QueryTimeoutException
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
</pre></p><p><b>root cause</b> <pre>java.lang.NoClassDefFoundError: org/springframework/dao/QueryTimeoutException
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.<init>(SQLErrorCodeSQLExceptionTranslator.java:86)
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.<init>(SQLErrorCodeSQLExceptionTranslator.java:102)
org.springframework.jdbc.support.JdbcAccessor.getExceptionTranslator(JdbcAccessor.java:99)
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605)
org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:849)
org.springframework.jdbc.core.simple.AbstractJdbcInsert.executeInsertAndReturnKeyHolderInternal(AbstractJdbcInsert.java:436)
org.springframework.jdbc.core.simple.AbstractJdbcInsert.executeInsertAndReturnKeyInternal(AbstractJdbcInsert.java:417)
org.springframework.jdbc.core.simple.AbstractJdbcInsert.doExecuteAndReturnKey(AbstractJdbcInsert.java:371)
org.springframework.jdbc.core.simple.SimpleJdbcInsert.executeAndReturnKey(SimpleJdbcInsert.java:122)
de.fraunhofer.iao.sharedefleet.energiemanagement.backend.ChargePointLogDAO.insertChargePointRequest(ChargePointLogDAO.java:65)
de.fraunhofer.iao.sharedefleet.energiemanagement.facade.PlugAndChargeFacade.handleHeartbeatRequest(PlugAndChargeFacade.java:55)
de.fraunhofer.iao.sharedefleet.energiemanagement.facade.PlugAndChargeFacade.requestChargingState(PlugAndChargeFacade.java:142)
de.fraunhofer.iao.sharedefleet.energiemanagement.services.EVSEHeartbeatEndpoint.requestChargingState(EVSEHeartbeatEndpoint.java:34)
sun.reflect.GeneratedMethodAccessor143.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.ws.server.endpoint.MethodEndpoint.invoke(MethodEndpoint.java:134)
org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter.invokeInternal(DefaultMethodEndpointAdapter.java:240)
org.springframework.ws.server.endpoint.adapter.AbstractMethodEndpointAdapter.invoke(AbstractMethodEndpointAdapter.java:53)
org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:233)
org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:173)
org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:88)
org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:59)
org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:239)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
</pre></p><p><b>root cause</b> <pre>java.lang.ClassNotFoundException: org.springframework.dao.QueryTimeoutException.
So I hope you can help me.
Thats my main
public class Main {
public static void main(String[] args)
{
boolean positive = true;
int counter = 0;
while (true)
{
if (counter >= 99)
{
positive = false;
}
if (counter <=-99)
{
positive = true;
}
if (positive == true)
{
counter ++;
}
else
{
counter --;
}
CloudCommunicator ccc = new CloudCommunicator("sh1");
EnergyManagerJob emj = ccc.SendRequest (true , true, 1 , 100 , "Nori2");
System.out.println("\nmax Current: " + emj.allowedMaximumCurrent);
System.out.println("charging status: " +emj.chargingPending);
System.out.println("power: " +emj.powerOn);
try
{
Thread.sleep(10000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
} // end of while
}// end of main

For the error you've posted, you'll need to find and add the spring-tx library to your classpath. You can add it to /WEB-INF/lib.
However, I don't see how the exception you've posted and the code you've posted relate to each other.

The server may be missing a dependency: spring-tx.
You can download the jar or add it to your project dependencies here: http://mvnrepository.com/artifact/org.springframework/spring-tx

Sotirios Delimanolis is right, please also avoid putting while(true) because it is an infinite loop, you can put for example while(positive), this will increment the counter until it gets to 99.

Related

jBCrypt String index out of range: 0 error on starting app in Netbeans

I'm receiving the following error in the Apache logs when starting my application
I've found BCrypt.checkpw() Invalid salt version exception
But this is not a match as the passwords stored in the DB for my users are hashed and this error appears on start up and I've no issues logging in 99.99% of the time.
29-Oct-2017 22:12:32.242 SEVERE [http-nio-8084-exec-1] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [UserController] in context with path [/medsched] threw exception
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:658)
at org.mindrot.jbcrypt.BCrypt.hashpw(BCrypt.java:658)
at org.mindrot.jbcrypt.BCrypt.checkpw(BCrypt.java:764)
at medsched.data.UserDB.loginUser(UserDB.java:216)
at medsched.controllers.UserController.logInToSite(UserController.java:165)
at medsched.controllers.UserController.doPost(UserController.java:41)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:213)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at medsched.filters.SecPageFilter.doFilter(SecPageFilter.java:61)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
It does not seem to affect the application as nearly most of the time as I can log in or if I present a password mismatch I am returned to a login error jsp defined in my application. I do some times, however receive a 500 error page with
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:658)
at org.mindrot.jbcrypt.BCrypt.hashpw(BCrypt.java:658)
at org.mindrot.jbcrypt.BCrypt.checkpw(BCrypt.java:764)
at medsched.data.UserDB.loginUser(UserDB.java:216)
at medsched.controllers.UserController.logInToSite(UserController.java:165)
at medsched.controllers.UserController.doPost(UserController.java:41)
Could it be the way I'm using BCrypt.checkpw ?? I'd understand the error appearing if I was attempting to log in, but not on starting the application in Netbeans.
public static User loginUser(String phnum,String passw) {
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = pool.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
String hpwd="";
//Get the key
String key=confUtil.encDeckey();
String query = "SELECT userid,fName,pwd FROM users "
+ "WHERE phone = AES_ENCRYPT(?,?) AND active=1";
try {
ps = connection.prepareStatement(query);
ps.setString(1, phnum);
ps.setString(2, key);
rs = ps.executeQuery();
User user = null;
if (rs.next()) {
user = new User();
user.setUserID(rs.getLong("userid"));
user.setFName(rs.getString("fName"));
user.setPwd(rs.getString("pwd"));
hpwd=user.getPwd();
}
if(hpwd!=null || !hpwd.isEmpty()){
if(!BCrypt.checkpw(passw,hpwd)){
user=null;
}
}
} catch (SQLException e) {
//System.err.println(e);
log.error("Exception when trying to log in",e);
return null;
} finally {
DBUtil.closeResultSet(rs);
DBUtil.closePreparedStatement(ps);
pool.freeConnection(connection);
}
}
Issue occurred again today, posting the 500 error that I'm getting
HTTP Status 500 - String index out of range: 0
type Exception report
message String index out of range: 0
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
java.lang.String.charAt(String.java:658)
org.mindrot.jbcrypt.BCrypt.hashpw(BCrypt.java:658)
org.mindrot.jbcrypt.BCrypt.checkpw(BCrypt.java:764)
medsched.data.UserDB.loginUser(UserDB.java:190)
medsched.controllers.UserController.logInToSite(UserController.java:169)
medsched.controllers.UserController.doPost(UserController.java:41)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:213)
medsched.filters.SecPageFilter.doFilter(SecPageFilter.java:61)
org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.27 logs.
I just ran into a similar issue:
Bcrypt throws java.lang.StringIndexOutOfBoundsException: String index out of range: 0.
In my case I found out that the hashed password was empty.
I can't tell why this error is appearing at app start without seeing more code.

HTTP Status 500 - An exception occurred processing JSP page /FinancialAssessment.jsp at line 440

Following is the exact error.
Type Exception report:
message An exception occurred processing JSP page /FinancialAssessment.jsp at line 440
Description:
The server encountered an internal error that prevented it from fulfilling this request.
Exception:
org.apache.jasper.JasperException: An exception occurred processing JSP page /FinancialAssessment.jsp at line 440
437:
438:
439:
440:
if(std.prev_treatment_start_date.equals("null"))
441: {
442: System.out.println("out by krishna------------");
443:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause:
java.lang.NullPointerException
org.apache.jsp.FinancialAssessment_jsp._jspService(FinancialAssessment_jsp.java:542)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
If your error line is that one on the if statement which is the most prabably, try this:
if( std == null || std.prev_treatment_start_date == null ) {
.....
This is because in java you have to test each object to avoid a NullPointerException which means that an object is null and cannot have methods or attributes.
Either std or std.prev_treatment_start_date is null. You should use:
if (std == null || std.prev_treatment_start_date == null) {
The way you wrote it means "std.prev_treatment_start_date is a string and has a value, and this value equals the string null".

java code wont run in JSP

I have a JSP page with two tabs and I am trying to run some Java code in the second tab but I keep getting a null pointer exception. I swear my Java Code is correct but the second tab wont show up either.
<%
String fn = request.getParameter("fn9");
String ln = request.getParameter("ln9");
String primaryEmail = request.getParameter("primaryemail9");
CreatingTheProviderFile ctpf = new CreatingTheProviderFile();
char[] c = fn.toCharArray();
if(fn != null){
System.out.println("it is blank");
}else{
System.out.println("it is something else");
}
if(fn != ''){
ctpf.FillNameArray(fn, ln, primaryEmail);
}
%>
JSP for some reason doesnt like the char statement nor does it like the if statement. This is my stacktrace
Dec 18, 2013 11:37:33 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/TwoWayPortal] threw exception [An exception occurred processing JSP page /patient_discharge.jsp at line 800
797:
798: // CreatingTheProviderFile ctpf = new CreatingTheProviderFile();
799:
800: char[] c = fn.toCharArray();
801:
802: System.out.println(c[0]);
803: // System.out.println(String.valueOf(fn.charAt(0)));
Stacktrace:] with root cause
java.lang.NullPointerException
at org.apache.jsp.patient_005fdischarge_jsp._jspService(patient_005fdischarge_jsp.java:999)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:205)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
I appreciate any help,
Thank You
The line that throws the NullPointerException is the line with fn.toCharArray(); This implies that fn is null.
Try
if(fn != null){
//do stuff here
}
Yes. fn is null.
// test for null, init to null if fn is null.
char[] c = (fn != null) ? fn.toCharArray() : null;
if (fn != null) {
System.out.println("it is not null");
if (fn.length() > 0) { // fn != '' is illegal, could have used !fn.equals("") -
// note double quotes (not single).
ctpf.FillNameArray(fn, ln, primaryEmail);
}
} else {
System.out.println("it is something else");
}
Before doing fn.toCharArray() check whether fn is null or not. You are checking it later. But if fn is null, you will get exception on fn.toCharArray() only and rest of the code wont execute.
When you change tabs, you may be losing data in request scope (just a guess). As an experiment, you can consider putting data in session scope instead. If it works, you may conider weather or not its of value to leave it as session scope.

Read Drools variable to Java code

I'm new to drools and what I'm trying to do is to get a value from the rules
I used the code from the project sample of drools which is:
Reading the DRL file:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "path.drl", getClass() ), ResourceType.DRL );
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if( errors.size() > 0 )
{
for( KnowledgeBuilderError error : errors )
{
System.err.println( error );
}
throw new IllegalArgumentException( "Could not parse knowledge." );
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
return kbase;
Inserting object and firing the rules
Bean bean = new Bean();
StatefulKnowledgeSession ksession = aKnowledgeBase.newStatefulKnowledgeSession();
// planning to insert a double
ksession.insert( bean );
ksession.fireAllRules();
What I want to do is to get a value from the rules, What I tried so far is using query which is I'm not sure if it is the proper way of doing it:
global String $test;
rule "Excellent"
when
// I'm planning to replace the bean with just a double is that possible?
$m: bean ( listeningScore > 85 )
$p: bean ( listeningScore < 101 )
then
$test = "Excellent";
System.out.println( $test );
end
query "Knowledge"
$result : $test
end
Also this produce an error which I really don't know how to fix. Here is the stacktrace:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[24,0]: [ERR 102] Line 24:0 mismatched input 'end' in query
[0,0]: Parser returned a null Package
java.lang.IllegalArgumentException: Could not parse knowledge.
at com.neu.als.thesis.units.InferenceEngine.readKnowledgeBase(InferenceEngine.java:61)
at com.neu.als.thesis.units.EvaluationUnit.evaluateConceptKnowledgeLevel(EvaluationUnit.java:187)
at com.neu.als.thesis.web.controllers.FLTController.evaluateFLT(FLTController.java:108)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:444)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:432)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:946)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:848)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:822)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Firstly, that exception means that the DRL code won't compile. I suspect this is because your query is referencing a bound variable from another rule, but it could be something else. Check out the docs on syntax for queries.
However, I tend to use one of two mechanisms for getting rule responses into the Java code.
In a stateless session have rules modify the inserted fact(s). After rules execution, just look at the fact that you inserted.
In a stateful session you can additionally use session.getObjects() or session.getObjects(ObjectFilter) to get references to the facts that are in the working memory after rules execution.
Here's an example of the first pattern, modifying the inserted fact:
rule "Reject a request"
when
$req: PaymentValidationRequest()
then
$req.setValid(false);
update($req);
end
PaymentValidationRequest request = new PaymentValidationRequest(payment);
request.setPayment(payment);
List<Object> facts = new ArrayList<Object>();
facts.add(request);
ksession.execute(facts);
...
boolean isValid = request.isValid()
List<ValidationAnnotation> annotations = request.getAnnotations();
Here's an example of the second pattern, when your rules have inserted or modified facts:
ObjectFilter filter = new ObjectFilter() {
#Override
public boolean accept(Object object) {
return object.getClass().getSimpleName().equals("MyFact");
}
};
for (FactHandle handle : session.getFactHandles(filter)) {
Object fact = session.getObject(handle);
// Do something with the fact you just found in working memory.
// ...
}

Error when trying to search similar images using JSP

I am building a web application for feature extraction and comparing the feature of images, using JSP, Java, and PostgreSQL.
My feature extraction is extracting some features from images, so that then I can compare them (some features are about color, some on the histogram of the image and so. I have special methods that extract them using specific libraries (jars that I add into lib) as you can see in the following example!
Those features are then successfully being added into my PostgreSQL database.
public void GetImageProperties(String targetPath, ImageProperties imagesProperties) throws Exception
{
// load image
FileInputStream imageStream;
imageStream = new FileInputStream(targetPath);
BufferedImage bimg = ImageIO.read(imageStream);
// get properties
imagesProperties.cl = new ColorLayoutImpl(bimg);
imagesProperties.eh = new EdgeHistogramImplementation(bimg);
imagesProperties.sc = new ScalableColorImpl(bimg);
}
Then I add them into a postgresql database(only the features, not the images)
String query = "CREATE TABLE Images (" +
" imageid SERIAL PRIMARY KEY," +
" fname VARCHAR(128)," +
" colorlayout VARCHAR(512), " +
" edgehist VARCHAR(512), " +
" scalablecolor VARCHAR(512) " +
")";
I get this error every time I had loaded an image and want to compare it with all the other images in a directory.
HTTP Status 500 -
type Exception report
message:
description The server encountered an internal error () that prevented it from fulfilling this request.
exception:
org.apache.jasper.JasperException: An exception occurred processing JSP page /query.jsp at line 124
121: if (bSearch) {
122: // get form params
123: query.setTopK(new Integer(request.getParameter("frm_topk")));
124: query.setColorHistogramWeight(new Integer(request.getParameter("frm_weight_c1")));
125: query.setColorDistributionWeight(new Integer(request.getParameter("frm_weight_c2")));
126: query.setTextureWeight(new Integer(request.getParameter("frm_weight_c3")));
127: }
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause:
java.lang.NumberFormatException: For input string: "1.0"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
java.lang.Integer.parseInt(Integer.java:492) java.lang.Integer.<init>
(Integer.java:677) org.apache.jsp.query_jsp._jspService(query_jsp.java:256)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.27 logs.
Your problem is here
query.setTopK(new Integer(request.getParameter("frm_topk")));
should be
String parFrm_topk = request.getParameter("frm_topk");
Integer frm_topk = null;
if (parFrm_topk != null && parFrm_topk.length() > 0 && !parFrm_topk.equals("null"))
try {
frm_topk = Integer.valueOf(parFrm_topk);
} catch (NumberFormatException nfe){
throw nfe;
}
if (frm_topk ! = null) {
query.setTopK(frm_topk);
this code is trying to check the parameter that could be empty, why it is empty depends on how flow the app and how parameters are passed through url.

Categories

Resources