Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Java Webservice problem (Array)

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Webservice problem (Array)

    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) {
            }
        }
    }
    Last edited by Gadge; January 10th, 2010 at 10:09 AM.


Similar Threads

  1. array/string problem
    By RSYR in forum Collections and Generics
    Replies: 1
    Last Post: December 18th, 2009, 09:24 PM
  2. Problem with 2d array
    By Anyone in forum Collections and Generics
    Replies: 2
    Last Post: November 14th, 2009, 08:32 PM
  3. [SOLVED] Creation of objects of Array in Java
    By sadi_shihab in forum Collections and Generics
    Replies: 4
    Last Post: July 9th, 2009, 01:38 PM
  4. [SOLVED] Array loop problem which returns the difference between the value with fixed value
    By uplink600 in forum Loops & Control Statements
    Replies: 5
    Last Post: May 15th, 2009, 04:31 AM
  5. Java program for 2-D Array Maze
    By Peetah05 in forum Collections and Generics
    Replies: 11
    Last Post: May 8th, 2009, 04:30 AM