Webservice client fails if invoked from server : Gets called successfully if invoked from Junit(locally)

12,722

Solution 1

Adding dependency on cxf-rt-transports-http-jetty solved it for me, as suggested here.

Solution 2

Probably, JUnit uses Eclipse's embedded JRE, while your application may use a specific JRE installed in your system. Check that you use the same JRE both for executing your application and JUnit test cases. Then, I had the same exception in my project, in my case the problem was that I wrote the web service url within "..." in my configuration file. Hope it helps, Roberto

Share:
12,722
Kshitij Jain
Author by

Kshitij Jain

I am a person who is crazy about learning new Web technologies . I believe in personal development in terms of genuine interests . I personally feel that being materialistic leads to disaster and working for your love and passion leads to happiness and gives pleasure in life .

Updated on June 04, 2022

Comments

  • Kshitij Jain
    Kshitij Jain almost 2 years

    I am working in jboss 7 and using CXF framework to build webservice client.

    I have written a particular webservice client to call a webservice deployed in remote server.

    If this webservice client is invoked from a Junit test case, then webservice call is successful and we get the valid xml response from the server.

    But if the same webservice client is invoked from the server(webservice client itself is deployed as webapp) then, it throws below exception :

    Caused by: javax.xml.ws.soap.SOAPFaultException: Could not find conduit initiator for address: 
                                    http://10.100.20.101/metavante1/ConnectwareWS/DPAcctTxnInqWSV1
                             and transport: http://schemas.xmlsoap.org/soap/http
            at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:156)
            at sun.proxy.$Proxy137.dpAcctTxnInq(Unknown Source)
            at webservice.client.hsa.MetavanteHSAPort.getAccountDetails(MetavanteHSAPort.java:1785) [webserviceclient.jar:]
            ... 34 more
    Caused by: java.lang.RuntimeException: Could not find conduit initiator for address: 
                                    http://10.100.20.101/metavante1/ConnectwareWS/DPAcctTxnInqWSV1
                             and transport: http://schemas.xmlsoap.org/soap/http
            at org.apache.cxf.binding.soap.SoapTransportFactory.getConduit(SoapTransportFactory.java:225)
            at org.apache.cxf.endpoint.AbstractConduitSelector.getSelectedConduit(AbstractConduitSelector.java:110)
            at org.apache.cxf.endpoint.UpfrontConduitSelector.prepare(UpfrontConduitSelector.java:63)
            at org.apache.cxf.endpoint.ClientImpl.prepareConduitSelector(ClientImpl.java:850)
            at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:525)
            at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
            at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
            at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
            at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
            at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
            ... 36 more
    

    In this case the URL http://10.100.20.101/metavante1/ConnectwareWS/DPAcctTxnInqWSV1 is picked up from a spring bean which is set in an XML file.

    Below is the code for webservice client :

    public HSAAccountDetailsBn getAccountDetails(String bankAccNum)
                throws ServiceException
        {
            HSAAccountDetailsBn detailsBn = new HSAAccountDetailsBn();
    
            try{
              URL wsdl = WebServiceClientUtil.getResourceAsURL("wsdl/clients/Metavante/DPAcctTxnInqWSV1.wsdl");
              MtvnCWDPAcctTxnInqWSV1 service = new MtvnCWDPAcctTxnInqWSV1(wsdl);
              MtvnCWDPAcctTxnInqWSV1Interface port = service
                        .getMtvnCWDPAcctTxnInqWSV1Port();
    
              BindingProvider provider = (BindingProvider) port;
              provider.getRequestContext().put(
              BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
              this.getServiceEndpointAcctTxnInq()
              );
    
              System.out.println("Invoking dpAcctTxnInq...");
    
              webservice.client.metavante.deposit.acctTrxnEnquiry.ObjectFactory obj = new webservice.client.metavante.deposit.acctTrxnEnquiry.ObjectFactory();
    
              DPAcctTxnInqMtvnSvcReq dpAcctTxnInqReq = obj
                        .createDPAcctTxnInqMtvnSvcReq();
              dpAcctTxnInqReq.setMtvnSvcVer("1.0");
              dpAcctTxnInqReq.setMsgUUID("11111111-1111-1111-1111-111111111114");
    
              DPAcctTxnInqMtvnSvcReq.PrcsParms prcsParms = obj
                        .createDPAcctTxnInqMtvnSvcReqPrcsParms();
    
              prcsParms.setSrcID("GJL747");
              prcsParms.setTestInd("Y");          
              dpAcctTxnInqReq.setPrcsParms(prcsParms);
    
              DPAcctTxnInqMtvnSvcReq.Svc svc = obj
                        .createDPAcctTxnInqMtvnSvcReqSvc();
    
              DPAcctTxnInqMtvnSvcReq.Svc.SvcParms svcParms = obj
                        .createDPAcctTxnInqMtvnSvcReqSvcSvcParms();
    
              svcParms.setApplID("DP");
              svcParms.setRoutingID(getRoutingId());
              svcParms.setRqstUUID("11111111-1111-1111-1111-111111111114");
              svcParms.setSvcID("DPAcctTxnInq");
              svcParms.setSvcVer("1.0");
              svc.setSvcParms(svcParms);
    
              DPAcctTxnInqMtvnSvcReq.Svc.Security security = obj
                        .createDPAcctTxnInqMtvnSvcReqSvcSecurity();
    
              DPAcctTxnInqMtvnSvcReq.Svc.Security.BasicAuth basicAuth = obj
                        .createDPAcctTxnInqMtvnSvcReqSvcSecurityBasicAuth();
    
              basicAuth.setUsrID(this.getUsernameDeposit());
              basicAuth.setPwd(this.getPasswordDeposit());
              security.setBasicAuth(basicAuth);
              svc.setSecurity(security);
    
              DPAcctTxnInqMtvnSvcReq.Svc.MsgData msgData = obj
                        .createDPAcctTxnInqMtvnSvcReqSvcMsgData();
              DPAcctTxnInqReqData dpAcctInqReqData = obj
                        .createDPAcctTxnInqReqData();
    
              if (!CommonSupportUtil.isNull(bankAccNum))
              {
                  dpAcctInqReqData.setE20007(bankAccNum); // account number
              }
    
              dpAcctInqReqData.setE310129("N");
              dpAcctInqReqData.setE310130("N");
              dpAcctInqReqData.setE310128("Y");
    
              msgData.setDPAcctTxnInqReqData(dpAcctInqReqData);
              svc.setMsgData(msgData);
    
              dpAcctTxnInqReq.getSvc().add(svc);
    
              DPAcctTxnInqMtvnSvcRes dpAcctTxnInqRes = port
                        .dpAcctTxnInq(dpAcctTxnInqReq);
    
              List<DPAcctTxnInqMtvnSvcRes.Svc> resSvclist = dpAcctTxnInqRes.getSvc();
              DPAcctTxnInqMtvnSvcRes.Svc resSvc = resSvclist.get(0);
              DPAcctTxnInqResData resData = resSvc.getMsgData()
                        .getDPAcctTxnInqResData();
    
              String returnStatus = dpAcctTxnInqRes.getErrCde();
    
              if (returnStatus.equalsIgnoreCase("0"))
                {
                    detailsBn.setAccruedInterest(new Double(resData.getE20638()));
                    detailsBn.setAvailableBalance(new Double(resData.getE21667()));
                    detailsBn.setClosingBalance(new Double(resData.getE20167()));
                    detailsBn.setCurrentBalance(new Double(resData.getE21661()));
                    detailsBn.setLedgerBalance(new Double(resData.getE21632()));
    
                    String openIndicator = resData.getE20276();
                    detailsBn.setOpenIndicator(openIndicator);
                    String dormantIndicator = resData.getE20277();
                    detailsBn.setDormantIndicator(dormantIndicator);
    
                }
                else
                {
                    throw new ServiceException("Could not access Metavante Deposit system ");
                }
    
            }
            catch (SOAPFaultException e) {
                throw new ServiceException(
                        "Vendor is intercepting the request but it is not returning the data. "
                                + "This can mean that either they are not servicing request at this moment "
                                + "at all or they are unable to service this request.",
                        e);
    
            } 
    
            return detailsBn;
    
        }//Method ends
    

    I looked some previous post on these type of issues, but none of them properly address my problem.

    I am not able to figure out the difference between the webservice client invocation from Junit vs jboss application server.