Question

I have created a Web Service from a java class called PoliceDepartment.java. I did that by doing:

Ctrl-n -> web service -> Server Implementation -> browse to source -> finish.

I have created a tomcat server and its running and all.

Even under threat of death I could not create the client.

I have the client code ready (see below).

Ctrl-n -> web service -> pass it the wsdl document.

Eclipse actually tried to override the PoliceDepartment.java class.

In any case, it does not create the Web Client.

What i need is to simply send a signal with parameters: createClient("blabla").

I imagine that there must be some tools that will create a proxy to the PoliceDepartment server that i can simply call from my java client.

If you know how to, please help me to achieve that.

Thanks for you help in advance.

That's the "client" parsing argument from the command line (it needs a proxy to send the parsed argument to the Web Service):

package client;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Scanner;
import java.util.regex.Pattern;

import interfaces.Compute;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class Console {

    public void loop(){

        Scanner sc = new Scanner(System.in);
        while(true){
            System.err.println("Enter you badge id in digits");
            String id = sc.nextLine();
            System.err.println("Choose police station: SPVM, Brossard or Longueil");
            String station = sc.nextLine();
            if(station.equals("SPVM")||station.equals("Brossard")||station.equals("Longueil")){
                PoliceOfficer popo = new PoliceOfficer(station, id);
                Compute stub = (Compute) this.connect(popo.station);

                while (true){
                    System.err.println("Choose which record you want: Criminal, Missing, Edit, Get Count; type Show to see database, Transfer to transfer a record or Exit to exit:");
                    try{
                        String choice=sc.nextLine();
                        if(choice.equals("Criminal")){
                            System.out.println("Please enter: firstname, lastname, description, status");
                            String firstname=sc.nextLine();
                            String lastname=sc.nextLine();
                            String description=sc.nextLine();
                            String status=sc.nextLine();
                            this.write(stub.createCRecord(firstname, lastname, description, status, popo.badgeID), popo.badgeID);



                        }else if(choice.equals("Missing")){
                            System.err.println("Please enter: firstname, lastname,address,last location, last date seen, status");
                            String firstname=sc.nextLine();
                            String lastname=sc.nextLine();
                            String address=sc.nextLine();
                            String lastlocation=sc.nextLine();
                            String lastdate = sc.nextLine();
                            String date[] = lastdate.split("-");
                            Date cal = new Date(Integer.parseInt(date[0])-1901, 
                                    Integer.parseInt(date[1]), Integer.parseInt(date[2]));

                            String status=sc.nextLine();
                            this.write(stub.createMRecord(firstname, lastname, address, cal, lastlocation, status, popo.badgeID), popo.badgeID);

                        } else if(choice.equals("Edit")){
                            System.err.println("Please enter: lastname, recordid number (only the digits), status");
                            String lastname=sc.nextLine();
                            int recordid=0;
                            try{
                                recordid=Integer.parseInt(sc.nextLine());
                                String newstatus=sc.nextLine();
                                this.write(stub.editCRecord(lastname, recordid, newstatus, popo.badgeID), popo.badgeID);
                            }catch (NumberFormatException e){
                                System.err.println("NOT INTEGER. ABORTING. RECORDID MUST BE INTEGER e.g CR0 you must enter 0");
                            }


                        } else if(choice.equals("Get Count")){

                                  DatagramSocket clientSocket = new DatagramSocket();
                                  InetAddress IPAddress = InetAddress.getByName("localhost");
                                  byte[] sendData = new byte[1024];
                                  byte[] receiveData = new byte[1024];
                                  sendData="COUNT".getBytes();

                                  DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
                                  clientSocket.send(sendPacket);
                                  DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
                                  clientSocket.receive(receivePacket);
                                  String modifiedSentence = new String(receivePacket.getData());
                                  this.write("Get Count:" + modifiedSentence + "\n", popo.badgeID);

                        } else if(choice.equals("Show")){

                            this.write(stub.show(), popo.badgeID);


                        }else if(choice.equals("Transfer")){

                            System.err.println("Please enter the department and the id of the record");
                            String department=sc.nextLine();
                            String record_id=sc.nextLine();
                            System.err.println("Following record transfered to the "+department+" department:");

                            this.write(stub.transferRecord(department, record_id, popo.badgeID), popo.badgeID);

                        }
                        else if(choice.equals("Exit")){
                            break;
                        }
                        System.err.println("\n\n\n");

                    }catch(Exception e){
                        e.printStackTrace();
                    }
                }//end inner while
            }// end if the choice is SPVM, Longueil or Brossard
        }//end outer while (choose police station)
    }

    public Compute connect(String station){
        Compute stub=null;
        try{

            Registry registry = LocateRegistry.getRegistry();



                stub = (Compute) registry.lookup(station);





        }catch(Exception e){
            System.err.println("an error in the client has occured");
            e.printStackTrace();
        }
        return stub;

    }

    private void write(String s, String filename){
        PrintWriter file=null;
        try{
            file = new PrintWriter(new FileOutputStream(
                    new File(filename), 
                    true /* append = true */)); 
            file.println(s);
            System.err.println(s);
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            file.close();
        }

    }


}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top