Search in sources :

Example 46 with EndpointReference

use of org.apache.axis2.addressing.EndpointReference 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 47 with EndpointReference

use of org.apache.axis2.addressing.EndpointReference 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 48 with EndpointReference

use of org.apache.axis2.addressing.EndpointReference 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 49 with EndpointReference

use of org.apache.axis2.addressing.EndpointReference 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 50 with EndpointReference

use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.

the class HTTPTransportUtils method processHTTPGetRequest.

/**
 * @param msgContext           - The MessageContext of the Request Message
 * @param out                  - The output stream of the response
 * @param soapAction           - SoapAction of the request
 * @param requestURI           - The URL that the request came to
 * @param configurationContext - The Axis Configuration Context
 * @param requestParameters    - The parameters of the request message
 * @return - boolean indication whether the operation was succesfull
 * @throws AxisFault - Thrown in case a fault occurs
 * @deprecated use RESTUtil.processURLRequest(MessageContext msgContext, OutputStream out, String contentType) instead
 */
public static boolean processHTTPGetRequest(MessageContext msgContext, OutputStream out, String soapAction, String requestURI, ConfigurationContext configurationContext, Map requestParameters) throws AxisFault {
    if ((soapAction != null) && soapAction.startsWith("\"") && soapAction.endsWith("\"")) {
        soapAction = soapAction.substring(1, soapAction.length() - 1);
    }
    msgContext.setSoapAction(soapAction);
    msgContext.setTo(new EndpointReference(requestURI));
    msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
    msgContext.setServerSide(true);
    SOAPEnvelope envelope = HTTPTransportUtils.createEnvelopeFromGetRequest(requestURI, requestParameters, configurationContext);
    if (envelope == null) {
        return false;
    } else {
        msgContext.setDoingREST(true);
        msgContext.setEnvelope(envelope);
        AxisEngine.receive(msgContext);
        return true;
    }
}
Also used : SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Aggregations

EndpointReference (org.apache.axis2.addressing.EndpointReference)261 Options (org.apache.axis2.client.Options)99 OMElement (org.apache.axiom.om.OMElement)67 AxisFault (org.apache.axis2.AxisFault)66 MessageContext (org.apache.axis2.context.MessageContext)58 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)57 ServiceClient (org.apache.axis2.client.ServiceClient)54 QName (javax.xml.namespace.QName)40 ArrayList (java.util.ArrayList)37 AxisService (org.apache.axis2.description.AxisService)28 Map (java.util.Map)25 MessageContext (org.apache.synapse.MessageContext)25 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)25 Test (org.junit.Test)20 IOException (java.io.IOException)19 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)18 RelatesTo (org.apache.axis2.addressing.RelatesTo)18 URL (java.net.URL)17 SOAPFactory (org.apache.axiom.soap.SOAPFactory)17 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)17