object reference not set to instance of object+axis2

Reply

Join Date: Jul 2008
Posts: 1
Reputation: amitabhtripathi is an unknown quantity at this point 
Solved Threads: 0
amitabhtripathi amitabhtripathi is offline Offline
Newbie Poster

object reference not set to instance of object+axis2

 
0
  #1
Jul 26th, 2008
HI,

I’m getting the following messages when I run my java client which is invoking a WCF service.The service is converted to java stubs using axis2.
then when i run my client i get following messages.

Can anyone help me in finding the root of the problem.

log4j:WARN No appenders could be found for logger (org.apache.axis2.description.AxisService).

log4j:WARN Please initialize the log4j system properly.

org.apache.axis2.AxisFault: Object reference not set to an instance of an object.

at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)

at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)

at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)

at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228

at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)

at org.tempuri.CheckInServiceStub.CheckIn(CheckInServiceStub.java:183)

at stubInvoker.CheckInServiceClient.main(CheckInServiceClient.java:40)




The client is given below.

  1. package stubInvoker;
  2.  
  3.  
  4.  
  5. import java.rmi.RemoteException;
  6.  
  7.  
  8.  
  9. import org.apache.axis2.AxisFault;
  10.  
  11. import org.tempuri.CheckInServiceStub;
  12.  
  13.  
  14.  
  15.  
  16.  
  17. public class CheckInServiceClient {
  18.  
  19.  
  20.  
  21. public static void main(String []args){
  22.  
  23.  
  24.  
  25. try {
  26.  
  27.  
  28.  
  29. //Instantiate the stub
  30.  
  31. CheckInServiceStub checkin =new CheckInServiceStub();
  32.  
  33.  
  34.  
  35.  
  36.  
  37. CheckInServiceStub.CheckIn req=new CheckInServiceStub.CheckIn();
  38.  
  39. // set the "req" checkin object with the data
  40.  
  41. req.setSessionId("Here SessionId");
  42.  
  43.  
  44.  
  45. //create new entity obj
  46.  
  47. CheckInServiceStub.NewEntityObject newObj = new CheckInServiceStub.NewEntityObject();
  48.  
  49. //assign property
  50.  
  51. // newObj.setUUID(vctargs.elementAt(0).toString());
  52.  
  53. //newObj.setEntityType(vctargs.elementAt(1).toString());
  54.  
  55. //newObj.setMessage(vctargs.elementAt(2).toString());
  56.  
  57. //newObj.setEntityName(vctargs.elementAt(3).toString());
  58.  
  59. //assign props
  60.  
  61. newObj.setUUID("e1");
  62.  
  63. newObj.setEntityType("activity");
  64.  
  65. newObj.setMessage("entity type is activity");
  66.  
  67. newObj.setEntityName("Entity");
  68.  
  69. req.setNewEntityObject(newObj);
  70.  
  71.  
  72.  
  73. CheckInServiceStub.CheckInResponse resp=new CheckInServiceStub.CheckInResponse();
  74.  
  75. //using the response object to retrieve the output
  76.  
  77.  
  78.  
  79. resp=checkin.CheckIn(req);
  80.  
  81. String[] result=resp.getCheckInResult().getString();
  82.  
  83. //for(int i=0;i<result.length ;i++)
  84.  
  85. // {
  86.  
  87. // vctReturn.add(result[i]);
  88.  
  89. //}
  90.  
  91.  
  92.  
  93. } catch (AxisFault e) {
  94.  
  95. // TODO Auto-generated catch block
  96.  
  97. e.printStackTrace();
  98.  
  99. } catch (RemoteException e) {
  100.  
  101. // TODO Auto-generated catch block
  102.  
  103. e.printStackTrace();
  104.  
  105. }
  106.  
  107. //return
  108.  
  109.  
  110.  
  111. }
  112.  
  113. }
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. The stub is given as follows .
  122.  
  123.  
  124.  
  125.  
  126.  
  127. /**
  128.  
  129.  * CheckInServiceStub.java
  130.  
  131.  *
  132.  
  133.  * This file was auto-generated from WSDL
  134.  
  135.  * by the Apache Axis2 version: 1.4 Built on : Apr 26, 2008 (06:24:30 EDT)
  136.  
  137.  */
  138.  
  139. package org.tempuri;
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147. /*
  148.  
  149.   * CheckInServiceStub java implementation
  150.  
  151.   */
  152.  
  153.  
  154.  
  155.  
  156.  
  157. public class CheckInServiceStub extends org.apache.axis2.client.Stub
  158.  
  159. {
  160.  
  161. protected org.apache.axis2.description.AxisOperation[] _operations;
  162.  
  163.  
  164.  
  165. //hashmaps to keep the fault mapping
  166.  
  167. private java.util.HashMap faultExceptionNameMap = new java.util.HashMap();
  168.  
  169. private java.util.HashMap faultExceptionClassNameMap = new java.util.HashMap();
  170.  
  171. private java.util.HashMap faultMessageMap = new java.util.HashMap();
  172.  
  173.  
  174.  
  175. private static int counter = 0;
  176.  
  177.  
  178.  
  179. private static synchronized Object getUniqueSuffix(){
  180.  
  181. // reset the counter if it is greater than 99999
  182.  
  183. if (counter > 99999){
  184.  
  185. counter = 0;
  186.  
  187. }
  188.  
  189. counter = counter + 1;
  190.  
  191. return Long.toString(System.currentTimeMillis()) + "_" + counter;
  192.  
  193. }
  194.  
  195.  
  196.  
  197.  
  198.  
  199. private void populateAxisService() throws org.apache.axis2.AxisFault {
  200.  
  201.  
  202.  
  203. //creating the Service with a unique name
  204.  
  205. _service = new org.apache.axis2.description.AxisService("CheckInService" + getUniqueSuffix());
  206.  
  207. addAnonymousOperations();
  208.  
  209.  
  210.  
  211. //creating the operations
  212.  
  213. org.apache.axis2.description.AxisOperation __operation;
  214.  
  215.  
  216.  
  217. _operations = new org.apache.axis2.description.AxisOperation[1];
  218.  
  219.  
  220.  
  221. __operation = new org.apache.axis2.description.OutInAxisOperation();
  222.  
  223.  
  224.  
  225.  
  226.  
  227. __operation.setName(new javax.xml.namespace.QName("http://tempuri.org/", "CheckIn"));
  228.  
  229. _service.addOperation(__operation);
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239. _operations[0]=__operation;
  240.  
  241.  
  242.  
  243.  
  244.  
  245. }
  246.  
  247.  
  248.  
  249. //populates the faults
  250.  
  251. private void populateFaults(){
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259. }
  260.  
  261.  
  262.  
  263. /**
  264.  
  265.   *Constructor that takes in a configContext
  266.  
  267.   */
  268.  
  269.  
  270.  
  271. public CheckInServiceStub(org.apache.axis2.context.ConfigurationContext configurationContext,
  272.  
  273. java.lang.String targetEndpoint)
  274.  
  275. throws org.apache.axis2.AxisFault {
  276.  
  277. this(configurationContext,targetEndpoint,false);
  278.  
  279. }
  280.  
  281.  
  282.  
  283.  
  284.  
  285. /**
  286.  
  287.   * Constructor that takes in a configContext and useseperate listner
  288.  
  289.   */
  290.  
  291. public CheckInServiceStub(org.apache.axis2.context.ConfigurationContext configurationContext,
  292.  
  293. java.lang.String targetEndpoint, boolean useSeparateListener)
  294.  
  295. throws org.apache.axis2.AxisFault {
  296.  
  297. //To populate AxisService
  298.  
  299. populateAxisService();
  300.  
  301. populateFaults();
  302.  
  303.  
  304. serviceClient = new org.apache.axis2.client.ServiceClient(configurationContext,_service);
  305.  
  306.  
  307.  
  308.  
  309.  
  310. configurationContext = _serviceClient.getServiceContext().getConfigurationContext();
  311.  
  312.  
  313.  
  314. _serviceClient.getOptions().setTo(new org.apache.axis2.addressing.EndpointReference(
  315.  
  316. targetEndpoint));
  317.  
  318. _serviceClient.getOptions().setUseSeparateListener(useSeparateListener);
  319.  
  320.  
  321.  
  322.  
  323.  
  324. }
  325.  
  326.  
  327.  
  328. /**
  329.  
  330.   * Default Constructor
  331.  
  332.   */
  333.  
  334. public CheckInServiceStub(org.apache.axis2.context.ConfigurationContext configurationContext) throws org.apache.axis2.AxisFault {
  335.  
  336.  
  337.  
  338. this(configurationContext,"http://hydhtc33007.ad.infosys.com/InfluxServices/InfluxCheckInService.svc" );
  339.  
  340.  
  341.  
  342. }
  343.  
  344.  
  345.  
  346. /**
  347.  
  348.   * Default Constructor
  349.  
  350.   */
  351.  
  352. public CheckInServiceStub() throws org.apache.axis2.AxisFault {
  353.  
  354.  
  355.  
  356. this("http://hydhtc33007.ad.infosys.com/InfluxServices/InfluxCheckInService.svc" );
  357.  
  358.  
  359.  
  360. }
  361.  
  362.  
  363.  
  364. /**
  365.  
  366.   * Constructor taking the target endpoint
  367.  
  368.   */
  369.  
  370. public CheckInServiceStub(java.lang.String targetEndpoint) throws org.apache.axis2.AxisFault {
  371.  
  372. this(null,targetEndpoint);
  373.  
  374. }
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384. /**
  385.  
  386.   * Auto generated method signature
  387.  
  388.   *
  389.  
  390.   * @see org.tempuri.CheckInService#CheckIn
  391.  
  392.   * @param checkIn0
  393.  
  394.  
  395.  
  396.   */
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404. public org.tempuri.CheckInServiceStub.CheckInResponse CheckIn(
  405.  
  406.  
  407.  
  408. org.tempuri.CheckInServiceStub.CheckIn checkIn0)
  409.  
  410.  
  411.  
  412.  
  413.  
  414. throws java.rmi.RemoteException
  415.  
  416.  
  417.  
  418. {
  419.  
  420. org.apache.axis2.context.MessageContext _messageContext = null;
  421.  
  422. try{
  423.  
  424. org.apache.axis2.client.OperationClient _operationClient = _serviceClient.createClient(_operations[0].getName());
  425.  
  426. _operationClient.getOptions().setAction("http://tempuri.org/ICheckInService/CheckIn");
  427.  
  428. _operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436. addPropertyToOperationClient(_operationClient,org.apache.axis2.description.WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR,"&");
  437.  
  438.  
  439.  
  440.  
  441.  
  442. // create a message context
  443.  
  444. _messageContext = new org.apache.axis2.context.MessageContext();
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452. // create SOAP envelope with that payload
  453.  
  454. org.apache.axiom.soap.SOAPEnvelope env = null;
  455.  
  456.  
  457.  
  458.  
  459.  
  460. env = toEnvelope(getFactory(_operationClient.getOptions().getSoapVersionURI()),
  461.  
  462. checkIn0,
  463.  
  464. optimizeContent(new javax.xml.namespace.QName("http://tempuri.org/",
  465.  
  466. "CheckIn")));
  467.  
  468.  
  469.  
  470. //adding SOAP soap_headers
  471.  
  472. _serviceClient.addHeadersToEnvelope(env);
  473.  
  474. // set the message context with that soap envelope
  475.  
  476. _messageContext.setEnvelope(env);
  477.  
  478.  
  479.  
  480. // add the message contxt to the operation client
  481.  
  482. _operationClient.addMessageContext(_messageContext);
  483.  
  484.  
  485.  
  486. //execute the operation client
  487.  
  488. _operationClient.execute(true);
  489.  
  490.  
  491.  
  492.  
  493.  
  494. org.apache.axis2.context.MessageContext _returnMessageContext = _operationClient.getMessageContext(
  495.  
  496. org.apache.axis2.wsdl.WSDLConstants.MESSAGE_LABEL_IN_VALUE);
  497.  
  498. org.apache.axiom.soap.SOAPEnvelope _returnEnv = _returnMessageContext.getEnvelope();
  499.  
  500.  
  501.  
  502.  
  503.  
  504. java.lang.Object object = fromOM(
  505.  
  506. _returnEnv.getBody().getFirstElement() ,
  507.  
  508. org.tempuri.CheckInServiceStub.CheckInResponse.class,
  509.  
  510. getEnvelopeNamespaces(_returnEnv));
  511.  
  512.  
  513.  
  514.  
  515.  
  516. return (org.tempuri.CheckInServiceStub.CheckInResponse)object;
  517.  
  518.  
  519.  
  520. }catch(org.apache.axis2.AxisFault f){
  521.  
  522.  
  523.  
  524. org.apache.axiom.om.OMElement faultElt = f.getDetail();
  525.  
  526. if (faultElt!=null){
  527.  
  528. if (faultExceptionNameMap.containsKey(faultElt.getQName())){
  529.  
  530. //make the fault by reflection
  531.  
  532. try{
  533.  
  534. java.lang.String exceptionClassName = (java.lang.String)faultExceptionClassNameMap.get(faultElt.getQName());
  535.  
  536. java.lang.Class exceptionClass = java.lang.Class.forName(exceptionClassName);
  537.  
  538. java.lang.Exception ex=
  539.  
  540. (java.lang.Exception) exceptionClass.newInstance();
  541.  
  542. //message class
  543.  
  544. java.lang.String messageClassName = (java.lang.String)faultMessageMap.get(faultElt.getQName());
  545.  
  546. java.lang.Class messageClass = java.lang.Class.forName(messageClassName);
  547.  
  548. java.lang.Object messageObject = fromOM(faultElt,messageClass,null);
  549.  
  550. java.lang.reflect.Method m = exceptionClass.getMethod("setFaultMessage",
  551.  
  552. new java.lang.Class[]{messageClass});
  553.  
  554. m.invoke(ex,new java.lang.Object[]{messageObject});
  555.  
  556.  
  557.  
  558.  
  559.  
  560. throw new java.rmi.RemoteException(ex.getMessage(), ex);
  561.  
  562. }catch(java.lang.ClassCastException e){
  563.  
  564. // we cannot intantiate the class - throw the original Axis fault
  565.  
  566. throw f;
  567.  
  568. } catch (java.lang.ClassNotFoundException e) {
  569.  
  570. // we cannot intantiate the class - throw the original Axis fault
  571.  
  572. throw f;
  573.  
  574. }catch (java.lang.NoSuchMethodException e) {
  575.  
  576. // we cannot intantiate the class - throw the original Axis fault
  577.  
  578. throw f;
  579.  
  580. } catch (java.lang.reflect.InvocationTargetException e) {
  581.  
  582. // we cannot intantiate the class - throw the original Axis fault
  583.  
  584. throw f;
  585.  
  586. } catch (java.lang.IllegalAccessException e) {
  587.  
  588. // we cannot intantiate the class - throw the original Axis fault
  589.  
  590. throw f;
  591.  
  592. } catch (java.lang.InstantiationException e) {
  593.  
  594. // we cannot intantiate the class - throw the original Axis fault
  595.  
  596. throw f;
  597.  
  598. }
  599.  
  600. }else{
  601.  
  602. throw f;
  603.  
  604. }
  605.  
  606. }else{
  607.  
  608. throw f;
  609.  
  610. }
  611.  
  612. } finally {
  613.  
  614. _messageContext.getTransportOut().getSender().cleanup(_messageContext);
  615.  
  616. }
  617.  
  618. }
  619.  
  620.  
  621.  
  622. /**
  623.  
  624.   * Auto generated method signature for Asynchronous Invocations
  625.  
  626.   *
  627.  
  628.   * @see org.tempuri.CheckInService#startCheckIn
  629.  
  630.   * @param checkIn0
  631.  
  632.  
  633.  
  634.   */
  635.  
  636. public void startCheckIn(
  637.  
  638.  
  639.  
  640. org.tempuri.CheckInServiceStub.CheckIn checkIn0,
  641.  
  642.  
  643.  
  644. final org.tempuri.CheckInServiceCallbackHandler callback)
  645.  
  646.  
  647.  
  648. throws java.rmi.RemoteException{
  649.  
  650.  
  651.  
  652. org.apache.axis2.client.OperationClient _operationClient = _serviceClient.createClient(_operations[0].getName());
  653.  
  654. _operationClient.getOptions().setAction("http://tempuri.org/ICheckInService/CheckIn");
  655.  
  656. _operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664. addPropertyToOperationClient(_operationClient,org.apache.axis2.description.WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR,"&");
  665.  
  666.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672. // create SOAP envelope with that payload
  673.  
  674. org.apache.axiom.soap.SOAPEnvelope env=null;
  675.  
  676. final org.apache.axis2.context.MessageContext _messageContext = new org.apache.axis2.context.MessageContext();
  677.  
  678.  
  679.  
  680.  
  681.  
  682. //Style is Doc.
  683.  
  684.  
  685.  
  686.  
  687.  
  688. env = toEnvelope(getFactory(_operationClient.getOptions().getSoapVersionURI()),
  689.  
  690. checkIn0,
  691.  
  692. optimizeContent(new javax.xml.namespace.QName("http://tempuri.org/",
  693.  
  694. "CheckIn")));
  695.  
  696.  
  697.  
  698. // adding SOAP soap_headers
  699.  
  700. _serviceClient.addHeadersToEnvelope(env);
  701.  
  702. // create message context with that soap envelope
  703.  
  704. _messageContext.setEnvelope(env);
  705.  
  706.  
  707.  
  708. // add the message context to the operation client
  709.  
  710. _operationClient.addMessageContext(_messageContext);
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718. _operationClient.setCallback(new org.apache.axis2.client.async.AxisCallback() {
  719.  
  720. public void onMessage(org.apache.axis2.context.MessageContext resultContext) {
  721.  
  722. try {
  723.  
  724. org.apache.axiom.soap.SOAPEnvelope resultEnv = resultContext.getEnvelope();
  725.  
  726.  
  727.  
  728. java.lang.Object object = fromOM(resultEnv.getBody().getFirstElement(),
  729.  
  730. org.tempuri.CheckInServiceStub.CheckInResponse.class,
  731.  
  732. getEnvelopeNamespaces(resultEnv));
  733.  
  734. callback.receiveResultCheckIn(
  735.  
  736. (org.tempuri.CheckInServiceStub.CheckInResponse)object);
  737.  
  738.  
  739.  
  740. } catch (org.apache.axis2.AxisFault e) {
  741.  
  742. callback.receiveErrorCheckIn(e);
  743.  
  744. }
  745.  
  746. }
  747.  
  748.  
  749.  
  750. public void onError(java.lang.Exception error) {
  751.  
  752. if (error instanceof org.apache.axis2.AxisFault) {
  753.  
  754. org.apache.axis2.AxisFault f = (org.apache.axis2.AxisFault) error;
  755.  
  756. org.apache.axiom.om.OMElement faultElt = f.getDetail();
  757.  
  758. if (faultElt!=null){
  759.  
  760. if (faultExceptionNameMap.containsKey(faultElt.getQName())){
  761.  
  762. //make the fault by reflection
  763.  
  764. try{
  765.  
  766. java.lang.String exceptionClassName = (java.lang.String)faultExceptionClassNameMap.get(faultElt.getQName());
  767.  
  768. java.lang.Class exceptionClass = java.lang.Class.forName(exceptionClassName);
  769.  
  770. java.lang.Exception ex=
  771.  
  772. (java.lang.Exception) exceptionClass.newInstance();
  773.  
  774. //message class
  775.  
  776. java.lang.String messageClassName = (java.lang.String)faultMessageMap.get(faultElt.getQName());
  777.  
  778. java.lang.Class messageClass = java.lang.Class.forName(messageClassName);
  779.  
  780. java.lang.Object messageObject = fromOM(faultElt,messageClass,null);
  781.  
  782. java.lang.reflect.Method m = exceptionClass.getMethod("setFaultMessage",
Last edited by Tekmaven; Jul 26th, 2008 at 2:15 pm. Reason: Code tags
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC