I am trying to use location geodist function in my solrj query.
My solr query is :-
q=*:*&sfield=latlng_coordinate&pt=70.00,80.000&sort=geodist() asc&fl=_dist_:geodist()&fl=name,id&fl=name,id
this query works fine when I hit this from browser but as soon as I try to hit this query from my java code it throws below exception:-
SEVERE: org.apache.solr.common.SolrException: undefined field *
at org.apache.solr.schema.IndexSchema.getDynamicFieldType(IndexSchema.java:1241)
at org.apache.solr.schema.IndexSchema.getFieldType(IndexSchema.java:1193)
at org.apache.solr.parser.SolrQueryParserBase.getWildcardQuery(SolrQueryParserBase.java:774)
at org.apache.solr.parser.SolrQueryParserBase.handleBareTokenQuery(SolrQueryParserBase.java:521)
at org.apache.solr.parser.QueryParser.Term(QueryParser.java:299)
at org.apache.solr.parser.QueryParser.Clause(QueryParser.java:185)
at org.apache.solr.parser.QueryParser.Query(QueryParser.java:107)
at org.apache.solr.parser.QueryParser.TopLevelQuery(QueryParser.java:96)
at org.apache.solr.parser.SolrQueryParserBase.parse(SolrQueryParserBase.java:152)
at org.apache.solr.search.LuceneQParser.parse(LuceneQParser.java:50)
at org.apache.solr.search.QParser.getQuery(QParser.java:141)
at org.apache.solr.handler.component.QueryComponent.prepare(QueryComponent.java:145)
at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:196)
at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135)
at org.apache.solr.core.SolrCore.execute(SolrCore.java:1916)
at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:768)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:415)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:205)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
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)
Jul 10, 2016 8:22:30 PM org.apache.solr.core.SolrCore execute
INFO: [move2gathercollection] webapp=/solr path=/select params={q=*:*%26sfield%3Dlatlng_coordinate%26pt%3D70.00,80.000%26sort%3Dgeodist()+asc%26fl%3D_dist_:geodist()%26fl%3Dname,id&fl=name,id&wt=javabin&version=2} status=400 QTime=3
org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: undefined field *
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:495)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:199)
at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:91)
at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301)
at com.move2gather.search.SolrServerHelper.getSolrQueryResults(SolrServerHelper.java:172)
at com.move2gather.search.data.SolrSearcher.getSuggesionsByGeoPoints(SolrSearcher.java:59)
trying to debug from past 4-5 hours but couldn't find out the solution.
I suppose there is a problem in the request url.
Looking at move2gathercollection I see the query is not completely encoded. If all the query q=*:* was encoded, it should be q=*%3A*
So given that the q parameter, is correctly encoded, the problem is with the rest of the url which may be is encoded two times before the call.
Just to be clear, when I look at solr log, the request are already decoded, so you can read all the parameters. In your log:
INFO: [move2gathercollection] webapp=/solr path=/select params={q=*:*%26sfield%3Dlatlng_coordinate%26pt%3D70.00,80.000%26sort%3Dgeodist()+asc%26fl%3D_dist_:geodist()%26fl%3Dname,id&fl=name,id&wt=javabin&version=2} status=400 QTime=3
I see only the first part of the request is readable q=*:* and the rest of the url is encoded %26sfield%3Dlatlng_coordinate%26pt%3D70.00,80.000%26sort%3Dgeodist()+asc%26fl%3D_dist_:geodist()%26fl%3Dname, which is pretty strange to me.
I suppose the entire string after q: is read as the name of a field which starts with a *.
Related
We are upgrading from Tomcat 7.0.59 to 7.0.61 and getting following error.
This error occurs only when passing via Apache proxy (no SSL).
When calling the Tomcat context from the browser (without Apache proxy) it works without problems.
Has anyone experienced the same/similar problem ?
We did go through the changelog (https://tomcat.apache.org/tomcat-7.0-doc/changelog.html) but we could not find any change explaining this behavior in Tomcat 7.0.61
SEVERE: Servlet.service() for servlet [CaptchaServlet] in context with path [/cw] threw exception
java.lang.IllegalStateException: Cannot create a session after the response has been committed
at org.apache.catalina.connector.Request.doGetSession(Request.java:3008)
at org.apache.catalina.connector.Request.getSession(Request.java:2384)
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:897)
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:909)
at be.servlet.CaptchaServlet.doGet(CaptchaServlet.java:127)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.filters.ExpiresFilter.doFilter(ExpiresFilter.java:1175)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:190)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
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)
The code concerned is:
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
HttpSession session = req.getSession();
Captcha captcha = getNumberCaptcha(_width, _height, 5, Color.black);
session.setAttribute(NAME, captcha);
resp.setHeader("Cache-Control", "private,no-cache,no-store");
resp.setContentType("image/png");
// See https://wiki.apache.org/tomcat/FAQ/KnownIssues#ImageIOIssues
// Wrap insite MyImageIOOutputStream
ImageIO.write(captcha.getImage(), "png", new MyImageIOOutputStream(resp.getOutputStream()));
resp.getOutputStream().flush();
resp.getOutputStream().close();
}
Before you start saying it is the ImageIO we did use the MyImageIOOutputStream as specified on the https://wiki.apache.org/tomcat/FAQ/KnownIssues#ImageIOIssues.
We even tried with loading an image from File into a byte array and sending the byte array in the resonse (so no making use of ImageIO), but the problem remains the same.
It is surprising to find that this error occurs in Tomcat 7.0.61 but not in 7.0.59. The error basically says that you are creating a session after the header of the HTTP response has been sent. This is a problem because the session requires cookies and the cookies are transferred in the HTTP response headers. So it's too late to send the cookies.
Assuming that the CaptchaServlet is your code, the easiest solution is to create the session (getSession()) before your write any output in the servlet. Then you are on the safe side with any servlet container.
I confirm that I have the same issue than you (in my particular case, 7.0.62 vs 7.0.59). My app works fine behind the apache proxy if Tomcat version is 7.0.59 but I have the same trace than you if I use 7.0.62 behind the proxy.
In my opinion we should report it to Tomcat as soon as possible
I am using XenServer 6.5
In Java, I use SDK library
<dependency>
<groupId>net.java.dev.vcc.thirdparty</groupId>
<artifactId>xen-api</artifactId>
<version>6.2.0-3.1</version>
</dependency>
Then I create my instance with a template.
VM template = VM.getByNameLabel(connection, templateName).iterator()
.next();
VM vm = template.createClone(connection, instanceName);
vm.setIsATemplate(connection, false);
vm.removeFromOtherConfig(connection, "disks");
vm.setNameLabel(connection, instanceName);
vm.setMemoryStaticMin(connection, new Long(256));
vm.setMemoryDynamicMin(connection, new Long(256));
vm.setMemoryDynamicMax(connection, new Long(256));
vm.setMemoryStaticMax(connection, new Long(256));
vm.setVCPUsAtStartup(connection, new Long(1));
After I create an instance, I try to start it.
VM vm = VM.getByNameLabel(connection, name).iterator().next();
vm.start(connection, false, false);
System.out.println(vm.getPowerState(connection));
But it returns
The server failed to handle your request, due to an internal error. The given message may give details useful for debugging the problem.
at com.xensource.xenapi.Types.checkResponse(Types.java:1609)
at com.xensource.xenapi.Connection.dispatch(Connection.java:395)
at com.xensource.xenapi.VM.start(VM.java:3118)
at com.apo.region.vm.XenConnectionsManager.startVM(XenConnectionsManager.java:79)
at com.apo.region.controller.VMController.list(VMController.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
I searched on the Internet, and found that
the create function doesn't have two boolean parameters for:
vm.start(connection);
But I try different version of Maven with:
vm.start(connection, false, false);
And the error message doesn't have much information. Did I miss any steps?
I am really sorry to answer so late, but I just saw yesterday the question and I wished to test something before answer you.
About the memory issue, any setting of memory is in bytes, due this, the parameter is long (for allow huge memory configurations).You set your new VM to 512 bytes only in both memories, static and dynamic, less than Spectrum!!
With that though in mind, my supposition is your memory limits are too low because the GUEST OS has memory restriction (specially Windows). In this blog you can see the minimum/maximum memory for guest OS related to other hypervisor (however I think is equal in Xenserver).
Anyway, this snippet is working for me using the same maven dependency, and same xenserver - 6.5 - as you.
For more information about vm.start(con,false,false) you can download Xenserver 6.5 SDK and see the javadoc related to VM. The second parameter is to allow start in pause mode and the third one is to force the start operation.
try
{
Connection con = new Connection(new URL(url));
Session.loginWithPassword(con, user, pass);
String templateName = "template-test";
String instanceName = "testVM";
VM template = VM.getByNameLabel(con, templateName).iterator().next();
VM vm = template.createClone(con, instanceName);
vm.setNameLabel(con, instanceName);
//This numbers are upper than required minimum for Windows 7
//My Guest OS
vm.setMemoryStaticMin(connection, 1073741824L);
vm.setMemoryDynamicMin(connection, 4294967296L);
vm.setMemoryDynamicMax(connection, 1073741824L);
vm.setMemoryStaticMax(connection, 4294967296L);
vm.setVCPUsAtStartup(con, 1L);
vm.provision(con);
VM vm2 = VM.getByNameLabel(con, instanceName).iterator().next();
vm2.start(con, false, false);
System.out.println(vm2.getPowerState(con));
}
catch (Exception e)
{
e.printStackTrace();
}
I am trying to print reports using the Crystal Report API based on this example.
reportClientDoc.open(reportpath+reportName, 0);
//Create and set print options.
PrintReportOptions printOptions = new PrintReportOptions();
printOptions.setPrinterName(printerName); //Note: Printer 'printername' must already be configured at Operating system level.
printOptions.setJobTitle(reportName); // job title by the report file name
printOptions.setPrinterDuplex(PrinterDuplex.simplex);
printOptions.setPaperSource(PaperSource.auto);
printOptions.setPaperSize(PaperSize.paperA4);
printOptions.setNumberOfCopies(1);
printOptions.setCollated(false);
reportClientDoc.getPrintOutputController().printReport(printOptions);
But I can't get it working, I receive a java.util.concurrent.CancellationException:
java.util.concurrent.CancellationException
at com.businessobjects.crystalreports.printer.bean.Printer.X(Unknown Source)
at com.businessobjects.crystalreports.printer.bean.ReportPrinter.print(Unknown Source)
at com.businessobjects.crystalreports.printer.bean.ReportPrinter.print(Unknown Source)
at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.printReport(SourceFile:742)
at my.test.crystal.GenerateReport.doGet(GenerateReport.java:108)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.awt.print.PrinterAbortException
at com.businessobjects.crystalreports.viewer.core.ReportPagePrinter.print(Unknown Source)
at sun.print.RasterPrinterJob.printPage(RasterPrinterJob.java:1936)
at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1431)
at com.businessobjects.crystalreports.viewer.core.ReportPagePrinter.print(Unknown Source)
The very strange thing is that the example worked previously in another project, but no longer on my local environment! I probably changed something but I can't figure out what :(
I tried with several printers (local and network) but the scenario is always the same: I can see the job during a very short time in printer job list but after less than 1 second, it vanishes and I receive the exception.
I am using Tomcat 7 and I tried with JDK1.6 and 1.7 (thinking about a JDK issue?) but there's no change.
If someone can give me some leads because currently, I am totally stuck.
Thx
Make sure you add ReportViewer.jar to your libraries.
For code completion, this doesn't seem necessary, but it is for printing.
I have a JSF webpage and form. On submit i validate the model number that was entered in. When I run the bit of code in JUnit that throws the exception all my tests pass just fine. When I enter in a model number and am the only one logged in this form it works just fine. I'm thinking this is a race condition of sorts...
the code that fails is this
public static int getCountOfSameModelsInItemInventory(String[] models) {
int count = 0;
if (initialize()) {
try (Connection conn = DriverManager.getConnection(AOurl, userName, password)) {
count = TryWithConnection(models, conn);
} catch (SQLException ex) {
Logger.getLogger(SqlInformationHolder.class.getName()).log(Level.SEVERE, null, ex);
}
}
return count;
}
the line number indicates that it fails here try (Connection conn = DriverManager.getConnection(AOurl, userName, password)) {
I have a C# background so my first instinct is to use a lock around my Connection, but I don't think java has that. My research is saying that the error is thrown if the port is already in use.I'm not sure if this is enough information or not, but I will edit my post if need be.
So I guess in the end I have 2 questions.. the obvious one: "How do I fix this", and two is there a design pattern/ best practice that would help avoid this?
On average I have about 5 people using the webpage, and this is the only method that makes a call to this specific server . The other methods use a different SQL server.
EDIT
so I have 1 other method that makes a call to this server. I'm looking at it to see if all the resources are cleared.
EDIT
Oct 08, 2014 9:17:09 AM dli_qc_v2.SqlInformationHolder getCountOfSameModelsInItemInventory
SEVERE: null
com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host OURSERVER, named instance THEINSTNACE failed. Error: "java.net.BindException: Address already in use: Cannot bind". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434. For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.getInstancePort(SQLServerConnection.java:3589)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.primaryPermissionCheck(SQLServerConnection.java:1225)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:972)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at dli_qc_v2.SqlInformationHolder.getCountOfSameModelsInItemInventory(SqlInformationHolder.java:110)
at dli_qc_v2.DLIModelValidator.validate(DLIModelValidator.java:56)
at dli_qc_v2.NcpFormBean.verifyingModelValue(NcpFormBean.java:327)
at dli_qc_v2.NcpFormBean.fillForm(NcpFormBean.java:230)
at sun.reflect.GeneratedMethodAccessor447.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273)
at org.apache.myfaces.view.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:83)
at javax.faces.component._MethodExpressionToMethodBinding.invoke(_MethodExpressionToMethodBinding.java:88)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:100)
at javax.faces.component.UICommand.broadcast(UICommand.java:120)
at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:937)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:271)
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1249)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:675)
at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:34)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2442)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2431)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
I have the following code:
<#attempt>
<#include "brands/custom.ftl">
<#recover>
<#include "brands/default.ftl">
</#attempt>
The idea was to have a custom template when it's available, or default when it's not. As far as I understood, all errors generated inside an attempt/recover block would be logged as: freemarker.runtime.attempt as per this page, but it seems that it doesn't, or it doesn't appear to be the case.
Logs template exceptions thrown during template processing, but caught by attempt/recover directives. Enable DEBUG severity to see the exceptions.
For me it generates the following error:
freemarker.log.JDK14LoggerFactory$JDK14Logger error
SEVERE: Template processing error: "Error reading included file brands/custom.ftl"
Error reading included file brands/custom.ftl
The problematic instruction:
----------
==> include "brands/custom.ftl" [on line 5, column 9 in _header.ftl]
in include "_header.ftl" [on line 2, column 1 in index.ftl]
----------
Java backtrace for programmers:
----------
freemarker.template.TemplateException: Error reading included file brands/custom.ftl
at freemarker.core.Include.accept(Include.java:167)
at freemarker.core.Environment.visit(Environment.java:221)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:221)
at freemarker.core.Environment.visit(Environment.java:361)
at freemarker.core.AttemptBlock.accept(AttemptBlock.java:73)
at freemarker.core.Environment.visit(Environment.java:221)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:221)
at freemarker.core.Environment.include(Environment.java:1508)
at freemarker.core.Include.accept(Include.java:169)
at freemarker.core.Environment.visit(Environment.java:221)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:221)
at freemarker.core.Environment.process(Environment.java:199)
at freemarker.template.Template.process(Template.java:259)
at com.company.portal.http.Controller.processTemplate(Controller.java:586)
at com.company.portal.http.Controller.guardedService(Controller.java:354)
at com.company.portal.http.Controller.service(Controller.java:65)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at com.radiadesign.catalina.session.RedisSessionHandlerValve.invoke(RedisSessionHandlerValve.java:26)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1695)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.FileNotFoundException: Template brands/custom.ftl not found.
at freemarker.template.Configuration.getTemplate(Configuration.java:580)
at freemarker.core.Environment.getTemplateForInclusion(Environment.java:1490)
at freemarker.core.Include.accept(Include.java:157)
... 41 more
How do I make it so that it doesn't generate a SEVERE error?
The #attempt/#recover documentation says: "Errors occurring during template execution are always logged, even if they occur inside an attempt block." The exception captured by #recover are also logged under "[DEBUG] freemarker.runtime.attempt". That said, you can't use #attempt/#recover to do normal flow control. It's for disaster recovery, like when something goes down but you don't want to fail the whole page, just show some error indicator and go on. But you still want to alert the sysadmins or whoever gets the error logs.
As of what you want to achieve, there's no directive built in for this. However, in the 2.3.21 API (not yet out... GitHub 2.3 or 2.3-gae head), Environment has a Template getTemplateForInclusion(String name, String encoding, boolean parse, boolean ignoreMissing) method - note the last parameter. If this method returns with non-null, then you can proceed with include(Template), otherwise you can try to get another template. You can implement a custom directive with TemplateDirectiveModel that does this.
BTW, are you sure this logic is justified? Can't just the application tell the template what's the name of the template to include? (I don't like if a logic depends on a file to be missing. What's if it's missing by accident, like even, because of a typo? Now the template won't fail and tell you, just falls back and include something else silently.)