title: Calling my WebService via AJAX more often causes a server fault
body: <p>I have a class that I run on the Java SE that gets called through a thread every second. Everything works fine.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>What could cause the fault, when calling the WebService more often?</p>
  
  <p>Here is the exception thrown on the server side :</p>
  
  <pre><code>[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)
  </code></pre>
  
  <p>Here is the Exception thrown on the client side :</p>
  
  <pre><code>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&lt;Vessel_Type&gt; 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)
  </code></pre>
  
  <p>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 .</p>
  
  <p>EDIT: Added details.</p>
  
  <p>The problem comes from the application architecture .</p>
  
  <p>Here is how it works :</p>
  
  <p>1) Server will open a socket connection to another server and get XML data close connection.</p>
  
  <p>2) Server will format XML data as Array and make it available via webservice</p>
  
  <p>3) Client calls the webservice to get the Array data.</p>
  
  <p>So if i try to make Ajax call to the webservice less than 6 seconds i get errors i posted previously.</p>
  
  <p>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 .</p>
  
  <p>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 .</p>
  
  <p>In 1) i can use many clients to open connection and get data very fastly witout any issue.</p>
  
  <p>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 .</p>
  
  <p>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 ?</p>