-2

I am trying to call my servlet GetAttributeValueServlet from apache tomcat and this error has been shown. The Servlet is in CloudWebServerClient.

Severe: Servlet.service() for servlet [servlet.GetAttributeValueServlet] in context with path [/CloudWebServiceClient] threw exception
AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode: 
 faultString: java.lang.NullPointerException
 faultActor: 
 faultNode: 
 faultDetail: 
    {http://xml.apache.org/axis/}hostname

java.lang.NullPointerException
    at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
    at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
    at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
    at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
    at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
    at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:796)
    at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at com.client.service.WebServiceProxySoapBindingStub.getAttributeValue(WebServiceProxySoapBindingStub.java:297)
    at com.client.service.WebServiceProxyProxy.getAttributeValue(WebServiceProxyProxy.java:50)
    at servlet.GetAttributeValueServlet.doGet(GetAttributeValueServlet.java:48)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
    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)

Web.xml:

   <?xml version="1.0" encoding="UTF-8"?>
   <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
   <display-name>CloudWebServiceServer</display-name>
   <welcome-file-list>
   <welcome-file>index.html</welcome-file>
   <welcome-file>index.htm</welcome-file>
   <welcome-file>index.jsp</welcome-file>
   <welcome-file>default.html</welcome-file>
   <welcome-file>default.htm</welcome-file>
   <welcome-file>default.jsp</welcome-file>
   </welcome-file-list>

   <servlet>
   <display-name>GetAttributeValueServlet</display-name>
   <servlet-name>GetAttributeValueServlet</servlet-name>
   <servlet-class>com.src.servlet.GetAttributeValueServlet</servlet-class>
   </servlet>

   <servlet>
   <display-name>Apache-Axis Servlet</display-name>
   <servlet-name>AxisServlet</servlet-name>
   <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
   </servlet>

   <servlet-mapping>
   <servlet-name>GetAttributeValueServlet</servlet-name>
   <url-pattern>/CloudWebServiceClient/WebContent/GetAttributeValueServlet</url-pattern>
   </servlet-mapping>

   <servlet-mapping>
   <servlet-name>AxisServlet</servlet-name>
   <url-pattern>/servlet/AxisServlet</url-pattern>
   </servlet-mapping>

   <servlet-mapping>
   <servlet-name>AxisServlet</servlet-name>
   <url-pattern>*.jws</url-pattern>
   </servlet-mapping>

   <servlet-mapping>
   <servlet-name>AxisServlet</servlet-name>
   <url-pattern>/services/*</url-pattern>
   </servlet-mapping>

   <servlet>
   <display-name>Axis Admin Servlet</display-name>
   <servlet-name>AdminServlet</servlet-name>
   <servlet-class>org.apache.axis.transport.http.AdminServlet</servlet-class>
   <load-on-startup>100</load-on-startup>
   </servlet>

   <servlet-mapping>
   <servlet-name>AdminServlet</servlet-name>
   <url-pattern>/servlet/AdminServlet</url-pattern>
   </servlet-mapping>
   </web-app>

GetAttributeValueServlet:

   package servlet;

   import java.io.IOException;
   import java.io.PrintWriter;

   import javax.servlet.ServletException;
   import javax.servlet.annotation.WebServlet;
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;

   import com.client.service.WebServiceProxy;
   import com.client.service.WebServiceProxyProxy;


   /**
   * Servlet implementation class GetAttributeValueServlet
   */
   @WebServlet("/GetAttributeValueServlet")
   public class GetAttributeValueServlet extends HttpServlet {
   private static final long serialVersionUID = 1L;

   /**
   * @see HttpServlet#HttpServlet()
   */
   public GetAttributeValueServlet() {
   super();
   // TODO Auto-generated constructor stub
   }

   /**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub

    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setContentType("text/xml;charset=utf-8");  
    String EntityID=request.getParameter("entity_id"); 
    String AttrName=request.getParameter("attrName"); 


    //String Value=request.getParameter("value"); 
    System.out.println(EntityID+AttrName);

    WebServiceProxy wsp = new WebServiceProxyProxy();
    System.out.println("Huuu");  //just to see if it is coming to this point and yes it comes to this point and after that throws exception!
    String isGet = wsp.getAttributeValue(EntityID, AttrName);
    System.out.println("Hagfgfg");  //it doesn't shows this value!
    PrintWriter pw = response.getWriter();

        pw.print(isGet);    

    return;
}


/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
}

}

BollyBoy
  • 17
  • 1
  • 1
  • 7
  • The error is in the code of the servlet, not the mapping in web.xml – developerwjk Feb 20 '14 at 19:08
  • can you have a look at it please!?...its really urgent... I am done with my project if you will help me to solve this problem... I have copied the Servlet code – BollyBoy Feb 20 '14 at 19:49

2 Answers2

1

Before using values you pull from request.getParameter() you should check them to see if they are null and do something if they are.

 String entityID = request.getParameter("entity_id"); 
 if(entityID==null)
 {
     entityID = ""; 
    //or maybe print a message to user "Entity ID is required field" and return;
 }

Or you can make sure they're not null like this:

 String entityID  =  "" + request.getParameter("entity_id"); 

This would mean if what comes out of request.getParameter() was null, now it will be the String value "null" rather than null.

developerwjk
  • 8,619
  • 2
  • 17
  • 33
  • thanx for the reply but entity_id ist not null.... The Attribute I am calling has an ID and that is not null... – BollyBoy Feb 20 '14 at 20:12
  • You assume this. But that won't be the case always which is why you shouldn't assume it. If someone goes to your servlet without actually going through your html form, the parameter WILL BE null. – developerwjk Feb 20 '14 at 20:15
  • When I call the servlet with apache Tomcat, it gives entity_id and attributename but after that throws an exception ... with isGet=null ..... – BollyBoy Feb 20 '14 at 20:18
  • Try `String isGet = "" + wsp.getAttributeValue(EntityID, AttrName);` – developerwjk Feb 20 '14 at 20:20
  • doesnt works :( actually the program is not coming to this point...it gives out this line : `System.out.println(EntityID+AttrName);` and then throws exception – BollyBoy Feb 20 '14 at 20:25
  • Check wsp for null before calling wsp.getAttributeValue. Probably wsp is null – developerwjk Feb 20 '14 at 20:31
  • no wsp ist not null... it is giving out `com.client.service.WebServiceProxyProxy@132be3f` com.client.service is a package name where die java class is saved – BollyBoy Feb 20 '14 at 20:36
  • You're contradicting yourself on whether or not its getting to System.out.println("Huuu"); – developerwjk Feb 20 '14 at 20:40
  • no i am not contradicting... i have two `System.out.println` commands. one is `System.out.println("Huuu")` and its getting till there and after that it gives exception that means its not getting to the other command `System.out.println(Hagfgfg)` and i tried with this one `System.out.println("Huuu" +wsp)` and the output is: `Huuucom.client.service.WebServiceProxyProxy@13b732a` – BollyBoy Feb 20 '14 at 20:43
  • Try `if(wsp==null) { System.out.println("wsp is null"); }` If wsp isn't null, either the parameters you are feeding to wsp.getAttributeValue are null, or the null exception is being thrown from within the function wsp.getAttributeValue, in which case you'll have to find a different library to use unless you have the code for that. – developerwjk Feb 20 '14 at 21:00
0

I resolved it.... The problem was in parameter attrName which was Null and it was because of wrong function call ;) thanx anyways

BollyBoy
  • 17
  • 1
  • 1
  • 7