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