Hey Guys
I'm fairly inexperienced with Java so please be patient with me.
I have a web service running which I have shown the code for below, I am using a basic array to extract data however if an incorrect data entry is made the web service will return "null" values which cause the web service to malfunction and stop working.
I'm looking to get help with either how to deal with the "null" values or ideas to upgrade my array into something more functional. I will be using a Java client to access the web service
Any help is appreciated.
Thanks
Web Service (BookFlightWS)
package org.me.travel; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; @WebService() public class BookFlightWS extends Protocol { @WebMethod(operationName = "bookflight") public String[] bookflight(@WebParam(name = "dest") String user_dest) { int Size = 12; //TODO write your implementation code here: String[] options = new String[Size]; double[] showprice = new double[Size]; //Convert Double fare to string to be read out to screen String aString = Double.toString(Fare[i]); for (int i = 0; i < Destination.length; i++) { options[j] = " - " + Origin[i] + " - to - " + Destination[i] + " - " + "£" + Fare[i] + "\n"; j++; if (Destination[i].equals(user_dest)) { options[j] = "Flight Reference: " + FlightRefNumber[i] + " || " + "Destination: " + Destination[i] + " || " + "Origin: " + Origin[i] + " || " + "\n"; j++; } } return options; } }
Array (Protocol.Java)
package org.me.travel; public class Protocol { String [] FlightRefNumber = { "Gat1", "Gat2", "Gat3", "Gat4", //Gatwick "Mid1", "Mid2", "Mid3", "Mid4", //East Middlands "Manc1", "Manc2", "Manc3", "Manc4" //Manchester }; int [] Available_Seats = { 300, 200, 100, 350, 200, 0, 20, 10, 0, 0, 10, 9 }; String [] Airline = { "British Airways", "British Airways", "British Airways", "British Airways", "Virgin Atlantic Airways", "Virgin Atlantic Airways", "Virgin Atlantic Airways", "Virgin Atlantic Airways", "Honk Hong Airways", "Honk Hong Airways", "Honk Hong Airways", "Honk Hong Airways" }; String [] Origin = { "London_Gatwick", "London_Gatwick", "London_Gatwick", "London_Gatwick", //Gatwick "East Middlands", "East Middlands", "East Middlands", "East Middlands", //East Middlands "Manchester Airport", "Manchester Airport", "Manchester Airport", "Manchester Airport" //Manchester Airport }; String [] Destination = { "Malaga Airport", "Hong Kong Airport", "Beijing International Airport", "Orlando International Airport", // London Gatwick "Hong Kong Airport", "Beijing International Airport", "Malaga Airport", "Orlando International Airport", //East Middlands "Hong Kong Airport", "Beijing International Airport", "Malaga Airport", "Dubai International Airport" //Manchester Aiport }; int [] Airport_Proximity = { 5, 10, 5 }; double Fare [] = { 200.00, 500.24, 323.99, 199.99, 156.00, 500.94, 123.99, 5879.39, 400.00, 250.24, 323.99, 989.23 }; int i = 0; int j = 0; int k = 0; double Currency_British_Pounds = 1; double Currency_US_Dollars = 0.62496094; double Currency_New_Zealand_dollar = 0.442347353; }
Java Client
package travel_client_app; import java.io.*; // for streams public class Main { static public void main(String[] argv) { BufferedReader kbd = null; // stream from the keyboard // TODO code application logic here kbd = new BufferedReader(new InputStreamReader(System.in)); try { System.out.println("Welcome to blah blah"); System.out.print("\n"); System.out.println("CHOOSE OPTION TO PROCEED 1-4 "); System.out.println("1. Flight Availability "); System.out.println("2. "); System.out.println("3. Hotel Room Availability "); System.out.println("4. "); System.out.println("Type 'exit' at anypoint to logout"); System.out.print("\n"); String choice = kbd.readLine().trim(); if (choice.equals("1")) { try { // Call Web Service Operation try { // Call Web Service Operation org.me.travel.BookFlightWSService service = new org.me.travel.BookFlightWSService(); org.me.travel.BookFlightWS port = service.getBookFlightWSPort(); // TODO initialize WS operation arguments here java.lang.String dest = ""; // TODO process result here java.util.List<java.lang.String> result = port.bookflight(dest); System.out.println("Available Flights: " + "\n" + result); } catch (Exception ex) { // TODO handle custom exceptions here } org.me.travel.BookFlightWSService service = new org.me.travel.BookFlightWSService(); org.me.travel.BookFlightWS port = service.getBookFlightWSPort(); // TODO initialize WS operation arguments here System.out.print("Enter Destination City: "); java.lang.String dest1 = kbd.readLine().trim(); java.lang.String dest = dest1; java.util.List<java.lang.String> result = port.bookflight(dest); System.out.println("Result = " + result); } catch (Exception ex) { // TODO handle custom exceptions here } } if (choice.equals("2")) { try { // Call Web Service Operation org.me.travel.BookFlightDisplayAllService service = new org.me.travel.BookFlightDisplayAllService(); org.me.travel.BookFlightDisplayAll port = service.getBookFlightDisplayAllPort(); // TODO initialize WS operation arguments here System.out.print("Enter Flight Number: "); java.lang.String flightno1 = kbd.readLine().trim(); java.lang.String flightNo = flightno1; // TODO process result here java.util.List<java.lang.String> result = port.showflight(flightNo); System.out.println("Result = " + result); } catch (Exception ex) { // TODO handle custom exceptions here } } if (choice.equals("3")) { } } catch (IOException e) { } } }