FileSizeLimitExceededException leads to error 500 instead of 413 - java

I got an exception like
2018-11-01 21:05:49.122 ERROR 31446 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1024 bytes.] with root cause
org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1024 bytes.
why 413 http error wasn't raised automatically?

You have to define maximum file size for a file upload.
Add below properties in application.properties
spring.http.multipart.max-file-size=128KB
spring.http.multipart.max-request-size=128KB
For spring boot 2.
spring.servlet.multipart.max-file-size=128MB
spring.servlet.multipart.max-request-size=128MB
spring.servlet.multipart.enabled=true
Refer this

Related

Spring boot mysql sonnection timeout during inserting new entry

I'm getting a timeout error during the insert query when I get 16 requests simultaneously.
I exceeded the timeout from 30 to 60 sec but without any success
2022-10-21 20:52:15.671 WARN 2375 --- [nio-8080-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: null
2022-10-21 20:52:15.672 ERROR 2375 --- [nio-8080-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : HikariPool-1 - Connection is not available, request timed out after 60000ms.
2022-10-21 20:52:15.681 ERROR 2375 --- [nio-8080-exec-6] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: unable to obtain isolated JDBC connection; nested exception is org.hibernate.exception.JDBCConnectionException: unable to obtain isolated JDBC connection] with root cause
java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 60000ms.

XML-22900: (Fatal Error) An internal error condition occurred after Adding spring-data-jpa-starter

Error after Adding spring-data-jpa-starter, It is working well without it.
XML-22900: (Fatal Error) An internal error condition occurred.
ERROR 1 --- [nio-8080-exec-1] c.sun.xml.internal.messaging.saaj.soap : SAAJ0511: Unable to create envelope from given source
org.springframework.ws.soap.SoapMessageCreationException: Could not create message from InputStream: Unable to create envelope from given source: ; nested exception is com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to create envelope from given source:
at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:218)
at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:62)
at org.springframework.ws.transport.AbstractWebServiceConnection.receive(AbstractWebServiceConnection.java:92)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:611)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)

Errors connecting to solrcloud using CloudSolrClient

I'm trying to connect to solrCloud using solrj CloudSolrClient, but am getting errors.
Used to directly call a single solr node, now switching to solrcloud. I have tried various different url formats as specified from documentation online.
SolrClient solrClient = new CloudSolrClient.Builder(zkUrl).build();
SolrQuery solrQuery = new SolrQuery();
solrQuery.setRequestHandler(FIELD_LIST_HANDLER);
QueryRequest req = new QueryRequest(solrQuery);
req.setBasicAuthCredentials(zkUser, zkPassword);
QueryResponse response = req.process(solrClient, core);
When using the following zkHost strings I get the various errors.
host:2181
2019-08-21 15:53:17 - ERROR o.a.c.c.C.[.[.[.[.a.d.n.s.JerseyConfiguration] [http-nio-8080-exec-1] Servlet.service() for servlet [com.att.dplr.nextgen.search.JerseyConfiguration] in context with path [] threw exception [java.lang.RuntimeException: Couldn't init
ialize a HttpClusterStateProvider (is/are the Solr server(s), [host:2181], down?)] with root cause
org.apache.http.client.ClientProtocolException: URI does not specify a valid host name: host:2181/admin/collections?action=CLUSTERSTATUS&wt=javabin&version=2
http://host:2181
2019-08-21 15:55:53 - ERROR o.a.c.c.C.[.[.[.[.a.d.n.s.JerseyConfiguration] [http-nio-8080-exec-1] Servlet.service() for servlet [com.att.dplr.nextgen.search.JerseyConfiguration] in context with path [] threw exception [java.lang.RuntimeException: Couldn't init
ialize a HttpClusterStateProvider (is/are the Solr server(s), [http://host:2181], down?)] with root cause
org.apache.http.NoHttpResponseException: host:2181 failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:141)
host:2181/solr
2019-08-21 16:00:11 - ERROR o.a.c.c.C.[.[.[.[.a.d.n.s.JerseyConfiguration] [http-nio-8080-exec-1] Servlet.service() for servlet [com.att.dplr.nextgen.search.JerseyConfiguration] in context with path [] threw exception [java.lang.RuntimeException: Couldn't init
ialize a HttpClusterStateProvider (is/are the Solr server(s), [host:2181/solr], down?)] with root cause
org.apache.http.client.ClientProtocolException: URI does not specify a valid host name: host:2181/solr/admin/collections?action=CLUSTERSTATUS&wt=javabin&version=2
at org.apache.http.impl.client.CloseableHttpClient.determineTarget(CloseableHttpClient.java:95)
http://host:2181/solr
2019-08-21 15:57:23 - ERROR o.a.c.c.C.[.[.[.[.a.d.n.s.JerseyConfiguration] [http-nio-8080-exec-1] Servlet.service() for servlet [com.att.dplr.nextgen.search.JerseyConfiguration] in context with path [] threw exception [java.lang.RuntimeException: Couldn't init
ialize a HttpClusterStateProvider (is/are the Solr server(s), [http://host:2181/solr], down?)] with root cause
org.apache.http.NoHttpResponseException: host:2181 failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:141)
What do I need to change to successfully query solr through zookeeper using solrj CloudSolrClient?
I have successfully communicated with the zookeeper instance from terminal.
$ echo stat | nc host 2181
Zookeeper version: 3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT
Clients:
/130.10.31.81:60381[0](queued=0,recved=1,sent=0)
/135.40.74.31:48984[1](queued=0,recved=817933,sent=817933)
Latency min/avg/max: 0/0/80
Received: 1893410
Sent: 1893706
Connections: 2
Outstanding: 0
Zxid: 0xa00000636
Mode: follower
Node count: 214
It turns out that both solrurls and zkurls can be provided to the CloudSolrClient.Builder. I was able to get past the previous issue by using the SolrClient solrClient = new CloudSolrClient.Builder(hosts, Optional.empty()).build();which accepts zkUrls whereas CloudSolrClient.Builder(hosts).build() accepts solr Urls
I also got this ClientProtocolException when the configuration itme clusterprops.json was not available in zookeeper /
Contents:
{"urlScheme":"https"}

Issue with generating excel sheets in a web application

While working in a web application I have some issues with generating the excel sheet based on the result. This excel sheet data should be independent for each request. As of now I have implemented in the following way:
Created a xml file for excel configuration
spring-excel-views.xml
<bean id="excelView" class="com.test.service.excelService"
I have configure this xml in the servlet configuration file
<bean class="xmlReolver> //Mentioned clearly in the code but not here
<property name="location>
<value>bin/spring-excel-views.xml</value>
</property>
</bean>
Now I have controller class as well as an Utility class
UtiilityClass: computes the results and send back to the Controller
Controller: model.addAttribute("result", result); //Assuming result is coming for Utility class
Now in excelService.java coded as follows:
class ExcelService implements AbstractExcelView{
#overridden
protected void buildExcelDocument(Map model,HttpServletRequest req, HTTPServletResponse res){
Map m = model.getResults("results"); // Picking this from Controller
for(Map.Entry<Integer,String> entry: m.entrySet()){ -->Exception is throwing
//excel sheet logiic
}
//iteration logic ----> Exception thrown here
}
}
Here sometimes excel sheet is generating successfully and sometimes it is throwing Nullpointerexception before starting the iteration. Also this excel data is overriding with some other requests data. Displayed result is good but I'm having the problem with the excel sheet data.
Help me out to resolve this issue.
Exception Stack trace
Exception Report:
type Exception report
message Request processing failed; nested exception is java.lang.NullPointerException
description: The server encountered an internal error that prevented it from fulfilling this request.
exception:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.
org. springframework. web. servlet. FrameworkServlet . processRequest (FrarneworkServlet. java: 932)
org.springframework.web.servlet.FrameworkServlet.doGet(Frameworkservlet.java:816)
javax.servlet.http.HttpServlet.service (HttpServlet.java: 620)
org.springframework.web.servlet.FrameworkServlet.service (FrameworkServlet.java:801)
javax.servlet.http.Httpservlet.service(Httpservlet.java:727)
root cause
java.lang.NullPointerException
com. hello. services.ExcelService.buildExcelDocument (Excelservice.java:34)
org. springframework.web.servlet.view.document.AbstractExcelView.renderMergedoutputModel (AbstractE
org.springfranework.web.servlet.view.AbstractView.render (AbstractView.java:264)
org.springframework.web.servlet.DispatcherServlet.render (Dispatcherservlet.java: 1208)
org. springframework . web . serviet . DispatcherServlet . processDispatchResult (DispatcherServlet . java: 1208
org. springframework. web. servlet . DispatcherServlet . doDispatch (DispatcherServlet . java: 939)
org. springframework.web.servlet.DispatcherServlet.doService (DispatcherServlet.java:856)
org. springframework.web.servlet.FrameworkServlet.processRequest (FrameworkServlet.java: 920)
org. springframework.web.servlet.FrameworkServlet.doGet (FrameeworkServlet.java:816)
javax.servlet.http.Httpservlet.service(Httpservlet.java: 620)
org.springframework.web.servlet.FrameworkServlet.service (FraneworkServlet.java:801)
javax.servlet.http.HttpServlet.service(Httpservlet.java:727)
As you pointed out that exception is throwing in the below line
for(Map.Entry entry: m.entrySet()){ -->Exception is throwing
You are getting this exception because model.getResults("results") is returning null.Thus your m is assigned null and doing m.entrySet() this on null reference is throwing null pointer exception.
So you'll have to figure out why model.getResults("results") is returning null and fix it. If there can occur situation where there will be no excel sheet generated and model.getResults("results") will return nulll. Then you'll have to provide appropriate checking in your code.Below is a checking but it may not be sufficient as you may to handle some more stuffs.
if(m!=null){
for(Map.Entry<Integer,String> entry: m.entrySet()){ -->Exception is throwing
//excel sheet logiic
}
//iteration logic ----> Exception thrown here
}
Regarding you question about Thread safe it completely depends how you have designed your class and using it which is very difficult to answer just by looking at the few lines. However this may not be an issue of Thread safe.

Log viewer in Glassfish 2 throws Exception

When I click certain records in the log viewer of a Glassfish 2 server running on 64-bit Ubuntu the error report opens a new popup but instead of the actual error I get a server exception:
HTTP Status 500 - type Exception reportmessagedescriptionThe server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: Expression '$property{list}' did not resolve to a List! Found: 'java.lang.String'root cause java.lang.IllegalArgumentException: Expression '$property{list}' did not resolve to a List! Found: 'java.lang.String'note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1_01 logs.Sun Java System Application Server 9.1_01
The stack trace in the server log is:
[#|2011-07-15T11:58:52.561+0000|INFO|sun-appserver9.1|com.sun.jsftemplating|_ThreadID=35;_ThreadName=httpWorkerThread-4848-1;|JSFT0003: VariableResolver was unable to find key (logEntryDetail) in ResourceBundle (help).|#]
[#|2011-07-15T11:58:52.586+0000|WARNING|sun-appserver9.1|javax.enterprise.resource.webcontainer.jsf.lifecycle|_ThreadID=35;_ThreadName=httpWorkerThread-4848-1;_RequestID=aa6c0f08-ce0f-4a10-bdc5-b835658db2bc;|executePhase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl#955e041) threw exception java.lang.IllegalArgumentException: Expression '$property{list}' did not resolve to a List! Found: 'java.lang.String'
at com.sun.jsftemplating.layout.descriptors.LayoutForEach.getList(LayoutForEach.java:119)
at com.sun.jsftemplating.layout.descriptors.LayoutForEach.encode(LayoutForEach.java:168)
at com.sun.jsftemplating.layout.descriptors.LayoutElementBase.encode(LayoutElementBase.java:271)
at com.sun.jsftemplating.layout.descriptors.LayoutDefinition.encode(LayoutDefinition.java:232)
at com.sun.jsftemplating.renderer.TemplateRenderer.encodeEnd(TemplateRenderer.java:139)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
at com.sun.webui.jsf.util.RenderingUtilities.renderComponent(RenderingUtilities.java:99)
at com.sun.webui.jsf.renderkit.html.PropertyRenderer.renderPropertyComponents(PropertyRenderer.java:200)
at com.sun.webui.jsf.renderkit.html.PropertyRenderer.encodeEnd(PropertyRenderer.java:161)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
at com.sun.webui.jsf.util.RenderingUtilities.renderComponent(RenderingUtilities.java:99)
at com.sun.webui.jsf.renderkit.html.PropertySheetSectionRenderer.renderProperties(PropertySheetSectionRenderer.java:192)
at com.sun.webui.jsf.renderkit.html.PropertySheetSectionRenderer.renderPropertySheetSection(PropertySheetSectionRenderer.java:152)
at com.sun.webui.jsf.renderkit.html.PropertySheetSectionRenderer.encodeEnd(PropertySheetSectionRenderer.java:95)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
at com.sun.webui.jsf.util.RenderingUtilities.renderComponent(RenderingUtilities.java:99)
at com.sun.webui.jsf.renderkit.html.PropertySheetRenderer.renderPropertySheetSections(PropertySheetRenderer.java:172)
at com.sun.webui.jsf.renderkit.html.PropertySheetRenderer.encodeEnd(PropertySheetRenderer.java:122)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
at com.sun.jsftemplating.layout.descriptors.LayoutElementBase.encodeChild(LayoutElementBase.java:480)
at com.sun.jsftemplating.layout.descriptors.LayoutElementBase.encodeChild(LayoutElementBase.java:477)
at com.sun.jsftemplating.layout.descriptors.LayoutElementBase.encodeChild(LayoutElementBase.java:477)
at com.sun.jsftemplating.layout.descriptors.LayoutElementBase.encodeChild(LayoutElementBase.java:477)
at com.sun.jsftemplating.layout.descriptors.LayoutElementBase.encodeChild(LayoutElementBase.java:477)
at com.sun.jsftemplating.layout.descriptors.LayoutComponent.encode(LayoutComponent.java:226)
at com.sun.jsftemplating.layout.descriptors.LayoutElementBase.encode(LayoutElementBase.java:271)
at com.sun.jsftemplating.layout.descriptors.LayoutDefinition.encode(LayoutDefinition.java:225)
at com.sun.jsftemplating.layout.LayoutViewHandler.renderView(LayoutViewHandler.java:484)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
at com.sun.faces.extensions.avatar.lifecycle.PartialTraversalLifecycle.render(PartialTraversalLifecycle.java:92)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
at com.sun.enterprise.tools.admingui.servlet.DelayedInitFacesServlet.service(DelayedInitFacesServlet.java:89)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
at com.sun.webui.jsf.util.UploadFilter.doFilter(UploadFilter.java:240)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
at com.sun.enterprise.web.connector.grizzly.WorkerThreadImpl.run(WorkerThreadImpl.java:116)|#]
Google came up with these two questions but with no real solution:
1. http://www.java.net/node/703568
2. http://www.java.net/node/682666
Does anybody have the same error or know the solution?

Categories