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()
}
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());
// /////////////////////////////////////////////////////////////////////
}
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());
}
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());
}
}
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());
}
Aggregations