Search code examples
javaxmlsoapwsdlapache-axis

stub file in client class not recocgnised using soap


I followed this guide "http://wso2.com/library/1719/", I didn't modified nothig except in the part of java to wsdl where i setted the taget namespace as

http ://ws

and in schema target namespace

http ://ws

I used for this tutorial a service and a client. I generate correctly (the tomcat server doesn't give error in axis page) the.aar file and the wsdl from it.

Service:

`

import java.time.*;

import java.time.format.DateTimeFormatter;

public class ATMachine {
//program begin

    public double deposita(double amount) {    
        Deposit.deposit = amount; //= read.nextDouble();
        BalanceInquiry.balance = Deposit.deposit + BalanceInquiry.getBalance();
        LocalDateTime date1= LocalDateTime.now();
        String md= "deposit";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy     HH:mm:ss");
    String date2= date1.format(formatter);
        BalanceInquiry.updateBalance(Deposit.deposit,BalanceInquiry.movement,md,date2);
        return Deposit.deposit;     
    }

    public double preleva(double amount) {        
        Withdraw.withdraw = amount;
        LocalDateTime date = LocalDateTime.now();
        String mw= "withdraw";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy  HH:mm:ss");
        String date3= date.format(formatter);
      BalanceInquiry.updateBalance(Withdraw.withdraw,BalanceInquiry.movement,mw,date3);
    int erwithdraw=BalanceInquiry.withdrawMoney(); // risposta di withdraw
    return erwithdraw;
    }

    public String[] bilancio(){
        double  checkb=BalanceInquiry.getBalance();
        String[] rbilancio= new String[12];
        rbilancio[0]= Double.toHexString(checkb);
        for(int i1=1;i1<=rbilancio.length;i1++){
            for(int i=0;i<= BalanceInquiry.movement.length-1; i++){
                if(BalanceInquiry.movement[i]==null){
                    rbilancio[i1]="";
                }
                else{rbilancio[i1]=BalanceInquiry.movement[i];
                }   
            }
        }
    return rbilancio;      
    }     
}

`

ATMClient `

package ws;

import java.util.Scanner;
import java.io.*;
import java.util.Properties;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.description.PolicyInclude;
import org.apache.neethi.Policy;
import org.apache.rampart.policy.model.CryptoConfig;
import org.apache.rampart.policy.model.RampartConfig;
import org.apache.axiom.om.OMElement;

public class ATMClient {

 public static void main(String[] args)
{
Scanner read = new Scanner(System.in);
double amount=0;
int select = 0;
int choice = 0;
//To be able to load the client configuration from axis2.xml

//ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("axis-repo",null);
    ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("axis-repo", "axis-repo\\conf\\axis2.xml");

    ATMachineStub stub = new ATMachineStub(ctx,"http://localhost:8888/axis2/services/ATMachine");

    ServiceClient sc = stub._getServiceClient();

    sc.engageModule("rampart");

System.out.println("====================================================");
System.out.println("\tWelcome to this simple ATM machine");
System.out.println("====================================================");
System.out.println();

do
{try
        {
    do {

            System.out.println("\tPlease select ATM Transactions");
            System.out.println("\tPress [1] Deposit");
            System.out.println("\tPress [2] Withdraw");
            System.out.println("\tPress [3] Balance Inquiry");
            System.out.println("\tPress [4] Exit");

            System.out.print("\n\tWhat would you like to do? ");
            select = read.nextInt();

                if(select>4)
                {
                    System.out.println("\n\tPlease select correct transaction.");
                }
                else
                {
                switch (select)
                {
                    case 1:
                        amount=0;
                        System.out.print("\n\tEnter the amount of money to deposit: ");
                        amount= read.nextDouble();
                        double result= stub.deposita(amount);
                        System.out.println("\tYou deposited the amount of " + amount);
                        break;

                    case 2:
                        amount=0;
                        System.out.print("\n\tTo withdraw, make sure that you have sufficient balance in your account.");
                        System.out.println();
                        System.out.print("\tEnter amount of money to withdraw: ");
                        amount= read.nextDouble();
                        double erpreleva=stub.preleva(amount);
                        if(erpreleva==1)
                        {
                            System.out.println("\tYour current balance is zero.");
                            System.out.println("\tYou cannot withdraw!");
                            System.out.println("\tYou need to deposit money first.");
                        }

                        else if(erpreleva==2)
                        {
                            System.out.println("\tThe amount you withdraw is greater than to your balance");
                            System.out.println("\tPlease check the amount you entered.");
                        }
                        else
                        {
                            System.out.println("\n\tYou withdraw the amount of Php " + amount);
                        }
                        break;

                    case 3:
                        String[] bilanciores= new String[12];
                        bilanciores=stub.bilancio();
                        System.out.println("\tYour current balance is:" + bilanciores[0]);
                        System.out.println();
                        System.out.println("\tThe last 10 operation are:\n ");
                        for(int i=1;i<bilanciores.length;i++){
                            System.out.println("\t"+ bilanciores[i] +"\n");
                            }
                        break;

                    default:
                        System.out.print("\n\tTransaction exited.");
                        break;

                }
            }               

    }while(select>4);

    do {
        try
        {
            System.out.println("\n\tWould you like to try another transaction?");
            System.out.println("\n\tPress [1] Yes \n\tPress [2] No");
            System.out.print("\tEnter choice: ");
            choice = read.nextInt();

                if(choice>2)
                {
                    System.out.print("\n\tPlease select correct choice.");
                }
            }

            catch(Exception e)
            {
                System.out.println("\tError Input! Please enter a number only.");
                read = new Scanner(System.in);
                System.out.println("\tEnter yout choice:");
                choice = read.nextInt();
            }
    } while(choice>2);
}
catch(Exception e)
        {
            System.out.println("\tError Input! Please enter a number only.");
            read = new Scanner(System.in);
            System.out.println("\tEnter yout choice:");
            select = read.nextInt();
        }

}while(choice<=1);

System.out.println("\n\tThank you for using this simple ATM Machine.");
} 
}

`

The classes BalanceInquiry, Deposit, Withdraw have get and response methods and works.

All the declared libraries are added to the project. But in ATMClient Eclipse says

ATMachineStub cannot be resolved to a type

I also tried to create an interface with the wizard using instead that ws and ws, ws and ws/xsd but cause error on the methods bilancio(), deposita(), and preleva() requiring to modify the parameters in the ATMchineStub file froma deposita(Deposita) to deposita(double), (the same for the other methods). I post also the xml file of the wsdl : <?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://ws.apache.org/axis2" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://ws.apache.org/axis2"> <wsdl:documentation>ATMachine</wsdl:documentation> <wsdl:types> <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://ws.apache.org/axis2"> <xs:element name="deposita"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="amount" type="xs:double"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="depositaResponse"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="return" type="xs:double"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="preleva"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="amount" type="xs:double"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="prelevaResponse"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="return" type="xs:double"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="bilancioResponse"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> </wsdl:types> <wsdl:message name="bilancioRequest"/> <wsdl:message name="bilancioResponse"> <wsdl:part name="parameters" element="ns:bilancioResponse"/> </wsdl:message> <wsdl:message name="prelevaRequest"> <wsdl:part name="parameters" element="ns:preleva"/> </wsdl:message> <wsdl:message name="prelevaResponse"> <wsdl:part name="parameters" element="ns:prelevaResponse"/> </wsdl:message> <wsdl:message name="depositaRequest"> <wsdl:part name="parameters" element="ns:deposita"/> </wsdl:message> <wsdl:message name="depositaResponse"> <wsdl:part name="parameters" element="ns:depositaResponse"/> </wsdl:message> <wsdl:portType name="ATMachinePortType"> <wsdl:operation name="bilancio"> <wsdl:input message="ns:bilancioRequest" wsaw:Action="urn:bilancio"/> <wsdl:output message="ns:bilancioResponse" wsaw:Action="urn:bilancioResponse"/> </wsdl:operation> <wsdl:operation name="preleva"> <wsdl:input message="ns:prelevaRequest" wsaw:Action="urn:preleva"/> <wsdl:output message="ns:prelevaResponse" wsaw:Action="urn:prelevaResponse"/> </wsdl:operation> <wsdl:operation name="deposita"> <wsdl:input message="ns:depositaRequest" wsaw:Action="urn:deposita"/> <wsdl:output message="ns:depositaResponse" wsaw:Action="urn:depositaResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="ATMachineSoap11Binding" type="ns:ATMachinePortType"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> <wsdl:operation name="bilancio"> <soap:operation soapAction="urn:bilancio" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="preleva"> <soap:operation soapAction="urn:preleva" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="deposita"> <soap:operation soapAction="urn:deposita" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name="ATMachineSoap12Binding" type="ns:ATMachinePortType"> <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> <wsdl:operation name="bilancio"> <soap12:operation soapAction="urn:bilancio" style="document"/> <wsdl:input> <soap12:body use="literal"/> </wsdl:input> <wsdl:output> <soap12:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="preleva"> <soap12:operation soapAction="urn:preleva" style="document"/> <wsdl:input> <soap12:body use="literal"/> </wsdl:input> <wsdl:output> <soap12:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="deposita"> <soap12:operation soapAction="urn:deposita" style="document"/> <wsdl:input> <soap12:body use="literal"/> </wsdl:input> <wsdl:output> <soap12:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name="ATMachineHttpBinding" type="ns:ATMachinePortType"> <http:binding verb="POST"/> <wsdl:operation name="bilancio"> <http:operation location="ATMachine/bilancio"/> <wsdl:input> <mime:content type="text/xml" part="bilancio"/> </wsdl:input> <wsdl:output> <mime:content type="text/xml" part="bilancio"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="preleva"> <http:operation location="ATMachine/preleva"/> <wsdl:input> <mime:content type="text/xml" part="preleva"/> </wsdl:input> <wsdl:output> <mime:content type="text/xml" part="preleva"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="deposita"> <http:operation location="ATMachine/deposita"/> <wsdl:input> <mime:content type="text/xml" part="deposita"/> </wsdl:input> <wsdl:output> <mime:content type="text/xml" part="deposita"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="ATMachine"> <wsdl:port name="ATMachineHttpSoap11Endpoint" binding="ns:ATMachineSoap11Binding"> <soap:address location="http://localhost:8080/axis2/services/ATMachine.ATMachineHttpSoap11Endpoint/"/> </wsdl:port> <wsdl:port name="ATMachineHttpSoap12Endpoint" binding="ns:ATMachineSoap12Binding"> <soap12:address location="http://localhost:8080/axis2/services/ATMachine.ATMachineHttpSoap12Endpoint/"/> </wsdl:port> <wsdl:port name="ATMachineHttpEndpoint" binding="ns:ATMachineHttpBinding"> <http:address location="http://localhost:8080/axis2/services/ATMachine.ATMachineHttpEndpoint/"/> </wsdl:port> </wsdl:service> </wsdl:definitions>

Can somebody suggest me how to solve it ?


Solution

  • I solved it using WSS4J by terminal. Instead of the eclipse service it has solved.