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)
Related
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 *.
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 class that I run on the Java SE that gets called through a thread every second. Everything works fine.
However when I transform this into a WebService and call it via AJAX every second, I get a SOAP server fault. However if I call it every 6 seconds, everything is fine.
The method I used to call cannot perform the work. It actually succeeds to read and parse XML, but when converted to a WebService the XML parsing crashes.
What could cause the fault, when calling the WebService more often?
Here is the exception thrown on the server side :
[Fatal Error] :1:7: A pseudo attribute name is expected.
Sep 25, 2014 3:22:46 PM com.sun.xml.internal.ws.server.sei.TieHandler createResponse
SEVERE: null
java.lang.NullPointerException
at Targets.XML.TESXMLStringToArrays(XML.java:209)
at Navires.Vessel.allVessels(Vessel.java:137)
at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.xml.internal.ws.api.server.MethodUtil.invoke(Unknown Source)
at com.sun.xml.internal.ws.api.server.InstanceResolver$1.invoke(Unknown Source)
at com.sun.xml.internal.ws.server.InvokerTube$2.invoke(Unknown Source)
at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Unknown Source)
at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(Unknown Source)
at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(Unknown Source)
at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(Unknown Source)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(Unknown Source)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(Unknown Source)
at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
at sun.net.httpserver.AuthFilter.doFilter(Unknown Source)
at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(Unknown Source)
at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
at sun.net.httpserver.ServerImpl$Exchange.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Here is the Exception thrown on the client side :
Sep 25, 2014 3:22:39 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/Map] threw exception [An exception occurred processing JSP page /targets.jsp at line 17
14:
15: Vessel M = V.getVesselPort() ;
16:
17: List<Vessel_Type> vessel =M.allVessels ();
18:
19: int j =0 ;
20: k="{"+'"'+"vessels"+'"'+":[" ;
Stacktrace:] with root cause
com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: java.lang.NullPointerException Please see the server log to find more detail regarding exact cause of the failure.
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(Unknown Source)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(Unknown Source)
at com.sun.xml.internal.ws.client.sei.StubHandler.readResponse(Unknown Source)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(Unknown Source)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
at com.sun.proxy.$Proxy35.allVessels(Unknown Source)
at org.apache.jsp.targets_jsp._jspService(targets_jsp.java:90)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:335)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
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.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
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:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:534)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
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)
It happens quite often when one client is calling the webservice . However when 2 clients are calling the web service it crashes immediately on the server and client sides . These exception are thrown when the Ajax call is performed .
EDIT: Added details.
The problem comes from the application architecture .
Here is how it works :
1) Server will open a socket connection to another server and get XML data close connection.
2) Server will format XML data as Array and make it available via webservice
3) Client calls the webservice to get the Array data.
So if i try to make Ajax call to the webservice less than 6 seconds i get errors i posted previously.
When i check the log in 1) i can see that the error is because the connection was closed so the 2) will automatically lead in error .
I can trigger the error by calling multiple times (Via eclipse many clicks to run java method calling the webservice ) or by using more than one client to call the webservice via JSP page having ajax, or simply by making ajax call very fast .
In 1) i can use many clients to open connection and get data very fastly witout any issue.
So the error i am getting can be solved if i declare the webmethod as synchronized , no errors will appear however it is very very slow as the multiple call will be hanging untill processed .
Where i am failing to understand is why in SE i can call 2 times a second and get data and even better i can do it within various machines at the same time without any log error and data are 100 clean meanwhile in webservice (EE) it fails ... Shall i reconfigure my webservice ? review the architecture ?
The problem comes from :
public class cnx {
static Socket socket ;
Now it is solved by removing socket from class attributes and putting it inside class as local variable.
But on the server side (where i pull data ) i can see many connections initiated meanwhile only one client is connected, this is due to multi calls (each Second and the data to be processed takes 2 seconds) .
if you have better alternative, please share .