Xenserver Java API start VM - java

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();
}

Related

java client calls python server reports error org.apache.thrift.TApplicationException: Internal error

I use thrift make java server to call python client, the connection is ok
the server response uses 100ms~500ms, and but the error as follows happens about twice in three minutes, can anyone help me ?
python server:
transport = TSocket.TServerSocket("127.0.0.1", 8080)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
rpcServer = TServer.TThreadPoolServer(processor, transport, tfactory, pfactory)
Java client:
socket = new TSocket("127.0.0.1", 8080);
TProtocol protocol = new TBinaryProtocol(tTransport);
client = new ImDetect.Client(protocol);
This is the detail of my error:
org.apache.thrift.TApplicationException: Internal error at
org.apache.thrift.TApplicationException.read(TApplicationException.java:111)
at
org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:79)
at
business.thriftclient.ImDetect$Client.recv_doWatermarkDetect(ImDetect.java:75)
at
business.thriftclient.ImDetect$Client.doWatermarkDetect(ImDetect.java:62)
at
business.thriftclient.AsynCThriftClient.imageWatermarkDetection(AsynCThriftClient.java:95)
at
service.business.soa.ImageWatermarkDetectionServiceImpl.doWatermarkDetection(ImageWatermarkDetectionServiceImpl.java:123)
at
service.business.soa.ImageWatermarkDetectionServiceImpl.asynImageWatermarkDetection(ImageWatermarkDetectionServiceImpl.java:72)
at sun.reflect.GeneratedMethodAccessor107.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
com.ctriposs.baiji.rpc.server.OperationHandler.invoke(OperationHandler.java:430)
at
com.ctriposs.baiji.rpc.server.handler.ServiceRequestHandlerBase.executeService(ServiceRequestHandlerBase.java:417)
at
com.ctriposs.baiji.rpc.server.handler.ServiceRequestHandlerBase.handleInternal(ServiceRequestHandlerBase.java:168)
at
com.ctriposs.baiji.rpc.server.handler.ServiceRequestHandlerBase.handle(ServiceRequestHandlerBase.java:133)
at
com.ctriposs.baiji.rpc.server.BaijiServiceHost.processRequest(BaijiServiceHost.java:113)
at
com.ctriposs.baiji.rpc.server.BaijiServlet.service(BaijiServlet.java:66)
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
com.ctriposs.baiji.rpc.client.ribbon.HttpContextFilter.doFilter(HttpContextFilter.java:34)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

Upgrade tomcat 7.0.59 to 7.0.61 : Cannot create a session after the response has been committed

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

Printing SAP Crystal Reports using Java

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.

BindException: Address already in use: Cannot bind

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)

Spring post request parameter missing for long strings

I have a post method in my Spring controller that takes one request parameter called wkt. Here is my method signature:
#RequestMapping(value="/getNumberOfProperties", method=RequestMethod.POST)
public String getEstimateForNumberOfProperties(#RequestParam("wkt") String wkt) {
//code
}
In my jQuery, I am calling this method like this.
$.post(webroot + "/project/getNumberOfProperties", {wkt : wktGeomFromServer})
This works great. However, I was getting this error for wkt strings that are too long.
org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'wkt' is not present
at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:255) ~[spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:95) ~[spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:79) ~[spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:157) ~[spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:124) ~[spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) ~[spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749) ~[spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:690) ~[spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) ~[spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) [servlet-api.jar:?]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) [spring-webmvc-4.0.2.RELEASE.jar:4.0.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) [servlet-api.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) [catalina.jar:7.0.41]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.41]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
So how long is too long? After doing some testing, I have discovered that if the length of the string is 1,971,324 or less everything works. Otherwise, I get the above exception. I don't know if this is something with Spring, or tomcat, etc. Also, I have verified with Chrome that wkt parameter is getting sent in all cases, regardless of length. So the Spring error message when it is too long does not make much sense to me. Is 1,971,324 some magic number somewhere?
Any suggestions?
Could it be server configuration issue? For example Tomcat has 2MB maximum post request content size by default.

Categories