Search in sources :

Example 1 with RPCServiceClient

use of org.apache.axis2.rpc.client.RPCServiceClient in project axis-axis2-java-core by apache.

the class LibraryServiceClient method runClient.

public void runClient() throws Exception {
    System.out.println("Enter service epr address :          ");
    String epr = getInput();
    RPCServiceClient rpcClient = new RPCServiceClient();
    Options opts = new Options();
    opts.setTo(new EndpointReference(epr));
    rpcClient.setOptions(opts);
    LibraryServiceClient client = new LibraryServiceClient();
    while (true) {
        showOptions();
        System.out.println("Type your command here : ");
        String commandsParms = getInput();
        if (commandsParms != null) {
            String[] args = commandsParms.split(" ");
            String firstarg = args[0];
            int command;
            try {
                command = Integer.parseInt(firstarg);
            } catch (NumberFormatException e) {
                System.out.println("Illegal argument entered.\n");
                continue;
            }
            switch(command) {
                case 1:
                    {
                        client.listAllBook(rpcClient);
                        break;
                    }
                case 2:
                    {
                        client.listAvailableBook(rpcClient);
                        break;
                    }
                case 3:
                    {
                        client.listLendBook(rpcClient);
                        break;
                    }
                case 4:
                    {
                        String usreName = null;
                        String passWord = null;
                        if (args.length < 5) {
                            throw new Exception("No enough number of arguments");
                        }
                        if (USER_NAME.equals(args[1])) {
                            usreName = args[2];
                        } else if (USER_NAME.equals(args[3])) {
                            usreName = args[4];
                        }
                        if (PASS_WORD.equals(args[1])) {
                            passWord = args[2];
                        } else if (PASS_WORD.equals(args[3])) {
                            passWord = args[4];
                        }
                        client.register(usreName, passWord, rpcClient);
                        break;
                    }
                case 5:
                    {
                        String usreName = null;
                        String passWord = null;
                        if (args.length < 5) {
                            throw new Exception("No enough number of arguments");
                        }
                        if (USER_NAME.equals(args[1])) {
                            usreName = args[2];
                        } else if (USER_NAME.equals(args[3])) {
                            usreName = args[4];
                        }
                        if (PASS_WORD.equals(args[1])) {
                            passWord = args[2];
                        } else if (PASS_WORD.equals(args[3])) {
                            passWord = args[4];
                        }
                        client.login(usreName, passWord, rpcClient);
                        break;
                    }
                case 6:
                    {
                        String isbn = null;
                        String userName = null;
                        if (args.length < 5) {
                            throw new Exception("No enough number of arguments");
                        }
                        if (USER_NAME.equals(args[1])) {
                            userName = args[2];
                        } else if (USER_NAME.equals(args[3])) {
                            userName = args[4];
                        }
                        if (ISBN.equals(args[1])) {
                            isbn = args[2];
                        } else if (ISBN.equals(args[3])) {
                            isbn = args[4];
                        }
                        client.lendBook(isbn, userName, rpcClient);
                        break;
                    }
                case 7:
                    {
                        String isbn = null;
                        if (args.length < 3) {
                            throw new Exception("No enough number of arguments");
                        }
                        if (ISBN.equals(args[1])) {
                            isbn = args[2];
                        }
                        client.returnBook(isbn, rpcClient);
                        break;
                    }
                case -1:
                    {
                        System.exit(0);
                    }
                default:
                    {
                        System.out.println("Wrong argument.\n");
                        break;
                    }
            }
        }
    }
// System.in.read()
}
Also used : Options(org.apache.axis2.client.Options) RPCServiceClient(org.apache.axis2.rpc.client.RPCServiceClient) IOException(java.io.IOException) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 2 with RPCServiceClient

use of org.apache.axis2.rpc.client.RPCServiceClient in project axis-axis2-java-core by apache.

the class AddressBookRPCClient method main.

public static void main(String[] args1) throws AxisFault {
    RPCServiceClient serviceClient = new RPCServiceClient();
    Options options = serviceClient.getOptions();
    EndpointReference targetEPR = new EndpointReference("http://127.0.0.1:8080/axis2/services/AddressBookService");
    options.setTo(targetEPR);
    // /////////////////////////////////////////////////////////////////////
    /*
         * Creates an Entry and stores it in the AddressBook.
         */
    // QName of the target method
    QName opAddEntry = new QName("http://service.addressbook.sample", "addEntry");
    /*
         * Constructing a new Entry
         */
    Entry entry = new Entry();
    entry.setName("Abby Cadabby");
    entry.setStreet("Sesame Street");
    entry.setCity("Sesame City");
    entry.setState("Sesame State");
    entry.setPostalCode("11111");
    // Constructing the arguments array for the method invocation
    Object[] opAddEntryArgs = new Object[] { entry };
    // Invoking the method
    serviceClient.invokeRobust(opAddEntry, opAddEntryArgs);
    // //////////////////////////////////////////////////////////////////////
    // /////////////////////////////////////////////////////////////////////
    /*
         * Fetching an Entry from the Address book
         */
    // QName of the method to invoke
    QName opFindEntry = new QName("http://service.addressbook.sample", "findEntry");
    // 
    String name = "Abby Cadabby";
    Object[] opFindEntryArgs = new Object[] { name };
    Class[] returnTypes = new Class[] { Entry.class };
    Object[] response = serviceClient.invokeBlocking(opFindEntry, opFindEntryArgs, returnTypes);
    Entry result = (Entry) response[0];
    if (result == null) {
        System.out.println("No entry found for " + name);
        return;
    }
    System.out.println("Name   :" + result.getName());
    System.out.println("Street :" + result.getStreet());
    System.out.println("City   :" + result.getCity());
    System.out.println("State  :" + result.getState());
    System.out.println("Postal Code :" + result.getPostalCode());
// /////////////////////////////////////////////////////////////////////
}
Also used : Options(org.apache.axis2.client.Options) Entry(sample.addressbook.entry.Entry) QName(javax.xml.namespace.QName) RPCServiceClient(org.apache.axis2.rpc.client.RPCServiceClient) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 3 with RPCServiceClient

use of org.apache.axis2.rpc.client.RPCServiceClient in project axis-axis2-java-core by apache.

the class WeatherRPCClient method main.

public static void main(String[] args1) throws AxisFault {
    RPCServiceClient serviceClient = new RPCServiceClient();
    Options options = serviceClient.getOptions();
    EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/WeatherService");
    options.setTo(targetEPR);
    // Setting the weather
    QName opSetWeather = new QName("http://service.pojo.sample", "setWeather");
    Weather w = new Weather();
    w.setTemperature((float) 39.3);
    w.setForecast("Cloudy with showers");
    w.setRain(true);
    w.setHowMuchRain((float) 4.5);
    Object[] opSetWeatherArgs = new Object[] { w };
    serviceClient.invokeRobust(opSetWeather, opSetWeatherArgs);
    // Getting the weather
    QName opGetWeather = new QName("http://service.pojo.sample", "getWeather");
    Object[] opGetWeatherArgs = new Object[] {};
    Class[] returnTypes = new Class[] { Weather.class };
    Object[] response = serviceClient.invokeBlocking(opGetWeather, opGetWeatherArgs, returnTypes);
    Weather result = (Weather) response[0];
    if (result == null) {
        System.out.println("Weather didn't initialize!");
        return;
    }
    // Displaying the result
    System.out.println("Temperature               : " + result.getTemperature());
    System.out.println("Forecast                  : " + result.getForecast());
    System.out.println("Rain                      : " + result.getRain());
    System.out.println("How much rain (in inches) : " + result.getHowMuchRain());
}
Also used : Weather(sample.pojo.data.Weather) Options(org.apache.axis2.client.Options) QName(javax.xml.namespace.QName) RPCServiceClient(org.apache.axis2.rpc.client.RPCServiceClient) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 4 with RPCServiceClient

use of org.apache.axis2.rpc.client.RPCServiceClient in project axis-axis2-java-core by apache.

the class WeatherSpringRPCClient method main.

public static void main(String[] args1) throws AxisFault {
    RPCServiceClient serviceClient = new RPCServiceClient();
    Options options = serviceClient.getOptions();
    EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/WeatherSpringService");
    options.setTo(targetEPR);
    // Get the weather (no setting, the Spring Framework has already initialized it for us)
    QName opGetWeather = new QName("http://service.spring.sample", "getWeather");
    Object[] opGetWeatherArgs = new Object[] {};
    Class[] returnTypes = new Class[] { Weather.class };
    Object[] response = serviceClient.invokeBlocking(opGetWeather, opGetWeatherArgs, returnTypes);
    Weather result = (Weather) response[0];
    // display results
    if (result == null) {
        System.out.println("Weather didn't initialize!");
    } else {
        System.out.println("Temperature               : " + result.getTemperature());
        System.out.println("Forecast                  : " + result.getForecast());
        System.out.println("Rain                      : " + result.getRain());
        System.out.println("How much rain (in inches) : " + result.getHowMuchRain());
    }
}
Also used : Weather(sample.spring.bean.Weather) Options(org.apache.axis2.client.Options) QName(javax.xml.namespace.QName) RPCServiceClient(org.apache.axis2.rpc.client.RPCServiceClient) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 5 with RPCServiceClient

use of org.apache.axis2.rpc.client.RPCServiceClient in project axis-axis2-java-core by apache.

the class EnumTest method testEnumPojo.

public void testEnumPojo() throws Exception {
    QName opEnumPojo = new QName("http://engine.axis2.apache.org", "enumPojo", "asix");
    Event event = new Event();
    event.setEventDesc("Event Description");
    event.setEventName("Event Name");
    event.setStartingDay(EnumService.Day.FRIDAY);
    // Constructing the arguments array for the method invocation
    Object[] opAddEventArgs = new Object[] { event };
    // Invoking the method
    RPCServiceClient serviceClient = getRPCClient();
    Options options = serviceClient.getOptions();
    EndpointReference targetEPR = new EndpointReference("local://services/EnumService");
    options.setTo(targetEPR);
    options.setAction("enumPojo");
    Class[] returnTypes = new Class[] { Event.class };
    Object[] ret = serviceClient.invokeBlocking(opEnumPojo, opAddEventArgs, returnTypes);
    // assertEquals(event, ret[0]);
    Event res = (Event) ret[0];
    assertEquals(event.getEventDesc(), res.getEventDesc());
    assertEquals(event.getEventName(), res.getEventName());
    assertEquals(event.getStartingDay(), res.getStartingDay());
}
Also used : Options(org.apache.axis2.client.Options) QName(javax.xml.namespace.QName) RPCServiceClient(org.apache.axis2.rpc.client.RPCServiceClient) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Aggregations

RPCServiceClient (org.apache.axis2.rpc.client.RPCServiceClient)47 QName (javax.xml.namespace.QName)33 OMElement (org.apache.axiom.om.OMElement)26 ArrayList (java.util.ArrayList)25 Options (org.apache.axis2.client.Options)13 EndpointReference (org.apache.axis2.addressing.EndpointReference)12 OMFactory (org.apache.axiom.om.OMFactory)9 OMNamespace (org.apache.axiom.om.OMNamespace)9 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)9 SOAPFactory (org.apache.axiom.soap.SOAPFactory)9 OperationClient (org.apache.axis2.client.OperationClient)9 MessageContext (org.apache.axis2.context.MessageContext)9 DefaultObjectSupplier (org.apache.axis2.engine.DefaultObjectSupplier)7 StringReader (java.io.StringReader)2 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)1 AxisFault (org.apache.axis2.AxisFault)1 AxisMessage (org.apache.axis2.description.AxisMessage)1 AxisOperation (org.apache.axis2.description.AxisOperation)1