Servlet doGet() returns HTTP Status 500 - java

while i was learning servlet i used the method doGet() and i was using Get request method ,the HTTP Status 500 error showed up ,but while using doPost() and post request was working perfectly fine.why am i not able to work with the doGet().
HTTP Status 500 – Internal Server Error
Type Exception Report
Message null
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)
com.kiran.AddServlet.doGet(AddServlet.java:12)
javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.
Apache Tomcat/9.0.27

It seems like i was trying to parse a number that is null.

From your snippet stack trace it looks like you’re trying to parse a null number.

Related

Web service call returns "Fault string, and possibly fault code, not set"

I have a java application (A) that calls the webservice.
1)Then I have another app (B) that uses the A jar.
The call is successful and needed data are returned.
2)Then I have web application that also uses the A jar.
In this case when the web service method is called from A app, an exception is thrown.
Since the class that executes the webservice call is the same in both cases, I'm not sure where the problem is.
The webservice is on https server. But I authenticate using credentials.
I think maybe something should be set in the web application, but I don't know what..
The exception is:
09:21:48.009 [http-nio-8084-exec-33] WARN o.a.cxf.phase.PhaseInterceptorChain - Interceptor for {http://www.myserver.com/ci}ci2#{http://www.myserver.com/ci}GetCertPath has thrown exception, unwinding now
java.lang.UnsupportedOperationException: null
at java.util.AbstractMap.put(AbstractMap.java:209) ~[na:1.8.0_92]
at org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor.setSoapAction(SoapPreProtocolOutInterceptor.java:122) ~[cxf-rt-bindings-soap-2.7.16.jar:2.7.16]
javax.xml.ws.soap.SOAPFaultException: Fault string, and possibly fault code, not set
at org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor.handleMessage(SoapPreProtocolOutInterceptor.java:63) ~[cxf-rt-bindings-soap-2.7.16.jar:2.7.16]
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:158)
at org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor.handleMessage(SoapPreProtocolOutInterceptor.java:47) ~[cxf-rt-bindings-soap-2.7.16.jar:2.7.16]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) ~[cxf-api-2.7.16.jar:2.7.16]
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:572) [cxf-api-2.7.16.jar:2.7.16]
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:481) [cxf-api-2.7.16.jar:2.7.16]
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:382) [cxf-api-2.7.16.jar:2.7.16]
at com.sun.proxy.$Proxy318.getCertPath(Unknown Source)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:335) [cxf-api-2.7.16.jar:2.7.16]
..... more lines here :) .....
at java.util.AbstractMap.put(AbstractMap.java:209)
at org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor.setSoapAction(SoapPreProtocolOutInterceptor.java:122)
at org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor.handleMessage(SoapPreProtocolOutInterceptor.java:63)
Fault string, and possibly fault code, not set
at org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor.handleMessage(SoapPreProtocolOutInterceptor.java:47)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:572)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:481)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:382)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:335)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:136)
... 59 more
Any ideas?
Thank you.
EDIT:
Does it have to have any headers set? When connecting in case 1, there is nothing specific set and it's working.
Ok, so I have found the issue. The request should have included the content-type. Which is strange that it didn't threw an exception in the first case...
I have added Content-Type: application/soap+xml; charset=utf-8 and the web application is working too.
As I found out the javax.xml.ws.soap.SOAPFaultException: Fault string, and possibly fault code, not set is mostly connected to missing content-type..
In my case, this was due to a simple badly formatted URL in a placeholder. http:/xxx.yyu (note the single /)
CXF wasn't very clear running in JDK6 but running in JDK8 was more explicit

How to diagnose "org.restlet.data.Parameter cannot be cast to org.restlet.data.Header" error in Restlet 2.3.5?

I'm using Restlet 2.3.5 in my application. When the GET request handler of a certain server resource is invoked, I get the following error:
[10:26:04] [Restlet-860541310/WARN]: Nov 29, 2015 10:26:04 AM org.restlet.engine.adapter.ServerAdapter addResponseHeaders
WARNING: Exception intercepted while adding the response headers
java.lang.ClassCastException: org.restlet.data.Parameter cannot be cast to org.restlet.data.Header
at org.restlet.engine.header.HeaderUtils.addExtensionHeaders(HeaderUtils.java:226)
at org.restlet.engine.header.HeaderUtils.addResponseHeaders(HeaderUtils.java:653)
at org.restlet.engine.adapter.ServerAdapter.addResponseHeaders(ServerAdapter.java:83)
at org.restlet.engine.adapter.ServerAdapter.commit(ServerAdapter.java:184)
at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:144)
at org.restlet.engine.connector.HttpServerHelper$1.handle(HttpServerHelper.java:64)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:80)
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:677)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:649)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
The problem is that this exception is thrown outside of the code that I wrote (I added logging statements in my server resource and according to them, the exception is thrown somewhere else).
As a result, I get 500 response (internal server error), even though my server resource sends correct data back to the client.
How can I find out, what exactly is causing this error?
This could be caused when trying to add custom headers in Restlet. When initializing the corresponding map, you would use a map (Series in Restlet) of Parameter instead of Header...
You can use something like that:
Series<Header> responseHeaders = (Series<Header>)
response.getAttributes().get(HeaderConstants.ATTRIBUTE_HEADERS);
if (responseHeaders == null) {
responseHeaders = new Series(Header.class);
response.getAttributes().put(
HeaderConstants.ATTRIBUTE_HEADERS, responseHeaders);
}
responseHeaders.add(new Header("X-MyHeader", "value"));
Hope it helps you,
Thierry

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.

Tomcat EOFException: Unexpected EOF read on the socket

I want to better understand how Tomcat handles requests and why my specific issue may be happening.
I am trying to enhance my existing Spring MVC web application with the Netflix Hystrix framework. This involves adding a hystrix-specific servlet to handle requests ending with /hystrix.stream.
Based on the logs (below), this mapping works and the request is being forwarded to the correct servlet. However, the exception that is thrown does not occure in the servlet. I have also tried extending the servlet to add additional logging - but it appears that no methods in the servlet are called. The exception seems to be happening because of some inner working on Tomcat that I am not aware of.
Here is a snippet from my web.xml (note that the rest of my application works fine - this is just concerning requests for /hystrix.stream):
<servlet>
<display-name>HystrixMetricsStreamServlet</display-name>
<servlet-name>HystrixMetricsStreamServlet</servlet-name>
<servlet-class>com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HystrixMetricsStreamServlet</servlet-name>
<url-pattern>/hystrix.stream</url-pattern>
</servlet-mapping>
When I navigate to loalhost:8080/web-app/hystrix.stream I am forwarded to the Tomcat 404 Error. The following exception appears in tomcat's log file:
2014-04-16 15:53:22 DEBUG AuthenticatorBase:419 - Security checking request GET /web-app/hystrix.stream
2014-04-16 15:53:22 DEBUG WebappClassLoader:1582 - loadClass(com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet, false)
2014-04-16 15:53:22 DEBUG WebappClassLoader:1598 - Returning class from cache
2014-04-16 15:53:22 DEBUG RealmBase:617 - No applicable constraints defined
2014-04-16 15:53:22 DEBUG AuthenticatorBase:501 - Not subject to any constraint
2014-04-16 15:53:22 DEBUG [localhost]:449 - Processing ErrorPage[errorCode=404, location=/404.htm]
2014-04-16 15:53:22 DEBUG Http11Processor:986 - Error parsing HTTP request header
java.io.EOFException: Unexpected EOF read on the socket
at org.apache.coyote.http11.InternalInputBuffer.parseRequestLine(InternalInputBuffer.java:99)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:952)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
2014-04-16 15:53:22 DEBUG Http11Protocol:645 - Socket: [org.apache.tomcat.util.net.SocketWrapper#56a7cbf2:129bf96a[TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: Socket[addr=/0:0:0:0:0:0:0:1,port=53783,localport=8443]]], Status in: [OPEN_READ], State out: [CLOSED]
2014-04-16 15:53:22 DEBUG LimitLatch:126 - Counting down[http-bio-8443-exec-1] latch=4
2014-04-16 15:53:22 DEBUG Http11Processor:986 - Error parsing HTTP request header
java.io.EOFException: Unexpected EOF read on the socket
at org.apache.coyote.http11.InternalInputBuffer.parseRequestLine(InternalInputBuffer.java:99)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:952)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Has anyone encountered something like this before? As I mentioned, my application works fine - this only occures for /hystrix.stream. I've used the Chrome Postman plugin to add the Accept and Content-Type = application/json headers to the request - both without success. As far as I know, requests to this servlet do not have any header requirements
Thanks for the help.
issue message is very clear, your request head is not corrent.
byte chr = 0;
do {
// Read new bytes if needed
if (pos >= lastValid) {
if (!fill())//read request content
throw new EOFException(sm.getString("iib.eof.error"));
}
// Set the start time once we start reading data (even if it is
// just skipping blank lines)
if (request.getStartTime() < 0) {
request.setStartTime(System.currentTimeMillis());
}
chr = buf[pos++];
} while ((chr == Constants.CR) || (chr == Constants.LF));
above is the source code of tomcat in InternalInputBuffer.parseRequestLine
- *. first time in the while function will be read content (8*1024).
[usually your header won't be so long]
*. after you read request content, the code will be check the first charactor of '\r\n'
*. so if your request content won't be contains this charactors, will be throw EOF exception
*. then the header paser is faill, so the web container don't know the Servlet method, so your servlet won't be called.
i think the server is ok, the problem is appeared in Chrome Postman plugin, please check the header

Does CXF with SOAP 1.1 have a maximum content length for text sent in a request?

Is there a maximum content length for text sent over CXF with SOAP 1.1? I'm running into an issue where one SOAP request is failing while the other succeeds. The only difference I have pinpointed between these request so far has been the bytes of text I am sending.
I see an error like the following:
checkException (UnexpectedServiceExceptionCheckImpl.java:35) - An unexpected exception was found from source=[DesignService.generate] type=[class javax.xml.ws.soap.SOAPFaultException] message=[Unmarshalling Error: [was class java.io.IOException] Strange I/O stream, returned 0 bytes on read ]:
javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error: [was class java.io.IOException] Strange I/O stream, returned 0 bytes on read
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:145)
at $Proxy146.generate(Unknown Source)
I don't believe there are any maximums except for memory usage. Are you seeing any errors? Can you trace the transaction using wireshark or something?

Categories