You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Golam Chowdhury <Go...@fieldworker.com> on 2007/10/04 16:58:13 UTC

Session Not Working For Cleint App

 

My client is not working: Problem not keeping the session.

 

If I try with browser the session works but it does not work if I use the
java client application. Please give me some pointer on what do I have to do
in order to make the client work.

 

Thanks for all your help with you all I could have come this far. 

Golam

 

 

 

Client code:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

package com.fw.ws;

 

import java.rmi.RemoteException;

 

import org.apache.axis2.AxisFault;

import org.apache.axis2.client.Options;

import org.apache.axis2.client.ServiceClient;

 

import com.fw.ws.FieldTrackerWSStub.Customer;

import com.fw.ws.FieldTrackerWSStub.Fleet;

import com.fw.ws.FieldTrackerWSStub.Vehicle;

import com.fw.ws.FieldTrackerWSStub.Data;

 

import com.fw.ws.FieldTrackerWSStub.GetHistoryData;

import com.fw.ws.FieldTrackerWSStub.GetHistoryDataResponse;

 

import com.fw.ws.FieldTrackerWSStub.GetVehicleIds;

import com.fw.ws.FieldTrackerWSStub.GetVehicleIdsResponse;

 

 

import com.fw.ws.FieldTrackerWSStub.CustomerHasAccess;

import com.fw.ws.FieldTrackerWSStub.CustomerHasAccessResponse;

 

import com.fw.ws.FieldTrackerWSStub.IsValid;

import com.fw.ws.FieldTrackerWSStub.IsValidResponse;

 

 

 

public class WebServiceClient {

 

        public static void main(String[] args) {

                try {

                        String vehicleId = "3";

                        String fleetId = "1";

                        String startTime = "2006-07-28";

                        String endTime = "2006-07-28";

                        

                       //Options options = new Options();

                        

                       // options.setManageSession(true);

                       // ServiceClient sender = new ServiceClient();

                       // sender.setOptions(options);

                        

                        ServiceClient client = new ServiceClient();

                        client.getOptions().setManageSession(true);

                        

                        

                        

                        FieldTrackerWSStub stub = new
FieldTrackerWSStub("http://localhost:8081/FWWS/services/FieldTrackerWS");

                       // stub._setServiceClient(client);

                        

                       

                        

                        //first login

                        IsValid login = new IsValid();

                        login.setUsername("aa");

                        login.setPassword("aaaaa");

                        

                        //get the response for the login

                        IsValidResponse loginResp =  stub.isValid(login);

                        System.out.println("Login: "+loginResp.getLogin());

                        

                     

                       

                        //once login is valid then get data

                           if(loginResp.getLogin()){

                                                

                                    

                                    

                                    GetVehicleIds vehicleIds = new
GetVehicleIds();

                                    vehicleIds.setFleetId(fleetId);

                                    //sender.

                                    GetVehicleIdsResponse vehicleIdsResponse
= stub.getVehicleIds(vehicleIds);

                                    

                                    String [] ids =
vehicleIdsResponse.getVehicleId();

                                    System.out.println("vehicle
id:"+ids[0]);

                                    

                                    

                                    

                        }

                        else{

                                    System.out.println("Login in Invalid");

                        }

                        

                        

                

                } catch (AxisFault e) {

                        e.printStackTrace();

                } catch (RemoteException e) {

                        e.printStackTrace();

                }

                         catch(SQLExceptionException0 e) {

                                                e.printStackTrace();

                        }

 

        }

}

 

 

Service skeleton  code:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  /**

     * Auto generated method signature

     * @param getVehicleIds

     */

    public com.fw.ws.GetVehicleIdsResponse getVehicleIds(

        com.fw.ws.GetVehicleIds getVehicleIds) throws SQLExceptionException0
{

      com.fw.ws.GetVehicleIdsResponse response = new
com.fw.ws.GetVehicleIdsResponse();

      try{

            

            Statement st = null;

             ResultSet rs = null;

                  

                                    

            //connect to database

            Connection con = DatabaseConnection.getConnection();

        

              //query the user table

            String query = null;

            String [] vehicleIds = null;

            int counter = 0;

            int size = 0;

                   

            

            //session code

            MessageContext incomingContext =
MessageContext.getCurrentMessageContext();

            ServiceContext sc = incomingContext.getServiceContext();

            String username = (String)sc.getProperty("username");

            String password = (String)sc.getProperty("password");

            String key  = (String)sc.getProperty("key");

            

            

            

            if(key.equals("valid")){

                               query = "SELECT count(distinct v.vehicle_id,
vf.fleet_id) as size FROM  vehicle_fleets vf, vehicles v where  vf.fleet_id
= "+getVehicleIds.getFleetId()+" and  v.vehicle_id = vf.vehicle_id ";

                               st = con.createStatement();

                                   rs = st.executeQuery(query);

                                   

                                   while(rs.next()){

                                     size = rs.getInt("size");

                                   }      

                        

                                  vehicleIds =  new String[size]; 

                                   

                                    

                               query = "SELECT distinct v.vehicle_id,
vf.fleet_id FROM  vehicle_fleets vf, vehicles v where  vf.fleet_id =
"+getVehicleIds.getFleetId()+" and  v.vehicle_id = vf.vehicle_id";

                                   st = con.createStatement();

                                   rs = st.executeQuery(query);


                                  

                                 while(rs.next()){

                                    vehicleIds[counter] =
(String)rs.getString("vehicle_id"); 

                                    counter++;

                                 }


                                

                                 response.setVehicleId(vehicleIds);     

                                 return response;

                  

            }else{

                  return null;

            }

            

      }catch(SQLException ex){

            System.out.println("getVehicleIds Web Services:");

            ex.printStackTrace();

      }

      

      return null;

    }

 

 

Service.xml

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

<?xml version="1.0" encoding="UTF-8"?>

<!-- This file was auto-generated from WSDL -->

<!-- by the Apache Axis2 version: 1.3  Built on : Aug 10, 2007 (04:45:47
LKT) -->

<serviceGroup>

    <service name="FieldTrackerWS" scope="transportsession">

             <schema elementFormDefaultQualified="false"
attributeFormDefaultQualified="false"/>

     <messageReceivers>

            <messageReceiver mep="http://www.w3.org/ns/wsdl/in-only"
class="com.fw.ws.FieldTrackerWSMessageReceiverInOnly"/>

            <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out"
class="com.fw.ws.FieldTrackerWSMessageReceiverInOut"/>

        </messageReceivers>

        <parameter
name="ServiceClass">com.fw.ws.FieldTrackerWSSkeleton</parameter>

        <parameter name="useOriginalwsdl">true</parameter>

        <parameter name="modifyUserWSDLPortAddress">true</parameter> 

        <operation name="getHistoryData"
mep="http://www.w3.org/ns/wsdl/in-out">

            <actionMapping>urn:getHistoryData</actionMapping>

 
<outputActionMapping>urn:getHistoryDataResponse</outputActionMapping>

            <faultActionMapping
faultName="SQLException">urn:getHistoryDataSQLException</faultActionMapping>

        </operation>

        <operation name="getVehicleIds"
mep="http://www.w3.org/ns/wsdl/in-out">

            <actionMapping>urn:getVehicleIds</actionMapping>

 
<outputActionMapping>urn:getVehicleIdsResponse</outputActionMapping>

            <faultActionMapping
faultName="SQLException">urn:getVehicleIdsSQLException</faultActionMapping>

        </operation>

        <operation name="isValid" mep="http://www.w3.org/ns/wsdl/in-out">

            <actionMapping>urn:isValid</actionMapping>

            <outputActionMapping>urn:isValidResponse</outputActionMapping>

            <faultActionMapping
faultName="SQLException">urn:isValidSQLException</faultActionMapping>

        </operation>

        <operation name="logout" mep="http://www.w3.org/ns/wsdl/in-only">

            <actionMapping>urn:logout</actionMapping>

        </operation>

        <operation name="customerHasAccess"
mep="http://www.w3.org/ns/wsdl/in-out">

            <actionMapping>urn:customerHasAccess</actionMapping>

 
<outputActionMapping>urn:customerHasAccessResponse</outputActionMapping>

        </operation>

    </service>

</serviceGroup>

 

 

 

Run Time Error

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 

Login: true

org.apache.axis2.AxisFault: unknown

      at
org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:486
)

      at
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAx
isOperation.java:343)

      at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperatio
n.java:389)

      at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisO
peration.java:211)

      at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)

      at
com.fw.ws.FieldTrackerWSStub.getVehicleIds(FieldTrackerWSStub.java:449)

      at com.fw.ws.WebServiceClient.main(WebServiceClient.java:80)

 

 

 

 

Golam Chowdhury

 

 


Re: Session Not Working For Cleint App

Posted by Deepal Jayasinghe <de...@opensource.lk>.
Hi Golam
Seems like your code is bit error prone.
See my fixed inline
>
>  
>
> My client is not working: Problem not keeping the session.
>
>  
>
> If I try with browser the session works but it does not work if I use
> the java client application. Please give me some pointer on what do I
> have to do in order to make the client work.
>
>  
>
> Thanks for all your help with you all I could have come this far.
>
> Golam
>
>  
>
>  
>
> * *
>
> *Client code:*
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> package com.fw.ws;
>
>  
>
> import java.rmi.RemoteException;
>
>  
>
> import org.apache.axis2.AxisFault;
>
> import org.apache.axis2.client.Options;
>
> import org.apache.axis2.client.ServiceClient;
>
>  
>
> import com.fw.ws.FieldTrackerWSStub.Customer;
>
> import com.fw.ws.FieldTrackerWSStub.Fleet;
>
> import com.fw.ws.FieldTrackerWSStub.Vehicle;
>
> import com.fw.ws.FieldTrackerWSStub.Data;
>
>  
>
> import com.fw.ws.FieldTrackerWSStub.GetHistoryData;
>
> import com.fw.ws.FieldTrackerWSStub.GetHistoryDataResponse;
>
>  
>
> import com.fw.ws.FieldTrackerWSStub.GetVehicleIds;
>
> import com.fw.ws.FieldTrackerWSStub.GetVehicleIdsResponse;
>
>  
>
>  
>
> import com.fw.ws.FieldTrackerWSStub.CustomerHasAccess;
>
> import com.fw.ws.FieldTrackerWSStub.CustomerHasAccessResponse;
>
>  
>
> import com.fw.ws.FieldTrackerWSStub.IsValid;
>
> import com.fw.ws.FieldTrackerWSStub.IsValidResponse;
>
>  
>
>  
>
>  
>
> public class WebServiceClient {
>
>  
>
>         public static void main(String[] args) {
>
>                 try {
>
>                         String vehicleId = "3";
>
>                         String fleetId = "1";
>
>                         String startTime = "2006-07-28";
>
>                         String endTime = "2006-07-28";
>
>                        
>
>                        //Options options = new Options();
>
>                         
>
>                        // options.setManageSession(true);
>
>                        // ServiceClient sender = new ServiceClient();
>
>                        // sender.setOptions(options);
>
>                        
>
>                         ServiceClient client = new ServiceClient();
>
>                         client.getOptions().setManageSession(true);
>
>                        
>
>                        
>
>                        
>
>                         FieldTrackerWSStub stub = new
> FieldTrackerWSStub("http://localhost:8081/FWWS/services/FieldTrackerWS");
>
stub._getServiceClinet().getOptions().setManageSession(true);
>
>                        
>
>                       
>
>                        
>
>                         //first login
>
>                         IsValid login = new IsValid();
>
>                         login.setUsername("aa");
>
>                         login.setPassword("aaaaa");
>
>                        
>
>                         //get the response for the login
>
>                         IsValidResponse loginResp =  stub.isValid(login);
>
>                         System.out.println("Login:
> "+loginResp.getLogin());
>
>                        
>
>                     
>
>                       
>
>                         //once login is valid then get data
>
>                            if(loginResp.getLogin()){
>
>                                                
>
>                                    
>
>                                    
>
>                                     GetVehicleIds vehicleIds = new
> GetVehicleIds();
>
>                                     vehicleIds.setFleetId(fleetId);
>
>                                     //sender.
>
>                                     GetVehicleIdsResponse
> vehicleIdsResponse = stub.getVehicleIds(vehicleIds);
>
>                                    
>
>                                     String [] ids =
> vehicleIdsResponse.getVehicleId();
>
>                                     System.out.println("vehicle
> id:"+ids[0]);
>
>                                    
>
>                                    
>
>                                    
>
>                         }
>
>                         else{
>
>                                     System.out.println("Login in
> Invalid");
>
>                         }
>
>                         
>
>                        
>
>                
>
>                 } catch (AxisFault e) {
>
>                         e.printStackTrace();
>
>                 } catch (RemoteException e) {
>
>                         e.printStackTrace();
>
>                 }
>
>                          catch(SQLExceptionException0 e) {
>
>                                                 e.printStackTrace();
>
>                         }
>
>  
>
>         }
>
> }
>
>  
>
>  
>
*Thanks
Deepal
*



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org


RE: Session Not Working For Cleint App

Posted by Golam Chowdhury <Go...@fieldworker.com>.
OK the solution:

 

stub._getServiceClient().getOptions().setManageSession(true);

 

 

Thanks for all your help, without you all I couldn't have come this far.

 

Golam 

 

  _____  

From: Golam Chowdhury [mailto:Golam.Chowdhury@fieldworker.com] 
Sent: Thursday, October 04, 2007 10:58 AM
To: axis-user@ws.apache.org; axis-dev@ws.apache.org
Subject: Session Not Working For Cleint App

 

 

My client is not working: Problem not keeping the session.

 

If I try with browser the session works but it does not work if I use the
java client application. Please give me some pointer on what do I have to do
in order to make the client work.

 

Thanks for all your help with you all I could have come this far. 

Golam

 

 

 

Client code:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

package com.fw.ws;

 

import java.rmi.RemoteException;

 

import org.apache.axis2.AxisFault;

import org.apache.axis2.client.Options;

import org.apache.axis2.client.ServiceClient;

 

import com.fw.ws.FieldTrackerWSStub.Customer;

import com.fw.ws.FieldTrackerWSStub.Fleet;

import com.fw.ws.FieldTrackerWSStub.Vehicle;

import com.fw.ws.FieldTrackerWSStub.Data;

 

import com.fw.ws.FieldTrackerWSStub.GetHistoryData;

import com.fw.ws.FieldTrackerWSStub.GetHistoryDataResponse;

 

import com.fw.ws.FieldTrackerWSStub.GetVehicleIds;

import com.fw.ws.FieldTrackerWSStub.GetVehicleIdsResponse;

 

 

import com.fw.ws.FieldTrackerWSStub.CustomerHasAccess;

import com.fw.ws.FieldTrackerWSStub.CustomerHasAccessResponse;

 

import com.fw.ws.FieldTrackerWSStub.IsValid;

import com.fw.ws.FieldTrackerWSStub.IsValidResponse;

 

 

 

public class WebServiceClient {

 

        public static void main(String[] args) {

                try {

                        String vehicleId = "3";

                        String fleetId = "1";

                        String startTime = "2006-07-28";

                        String endTime = "2006-07-28";

                        

                       //Options options = new Options();

                        

                       // options.setManageSession(true);

                       // ServiceClient sender = new ServiceClient();

                       // sender.setOptions(options);

                        

                        ServiceClient client = new ServiceClient();

                        client.getOptions().setManageSession(true);

                        

                        

                        

                        FieldTrackerWSStub stub = new
FieldTrackerWSStub("http://localhost:8081/FWWS/services/FieldTrackerWS");

                       // stub._setServiceClient(client);

                        

                       

                        

                        //first login

                        IsValid login = new IsValid();

                        login.setUsername("aa");

                        login.setPassword("aaaaa");

                        

                        //get the response for the login

                        IsValidResponse loginResp =  stub.isValid(login);

                        System.out.println("Login: "+loginResp.getLogin());

                        

                     

                       

                        //once login is valid then get data

                           if(loginResp.getLogin()){

                                                

                                    

                                    

                                    GetVehicleIds vehicleIds = new
GetVehicleIds();

                                    vehicleIds.setFleetId(fleetId);

                                    //sender.

                                    GetVehicleIdsResponse vehicleIdsResponse
= stub.getVehicleIds(vehicleIds);

                                    

                                    String [] ids =
vehicleIdsResponse.getVehicleId();

                                    System.out.println("vehicle
id:"+ids[0]);

                                    

                                    

                                    

                        }

                        else{

                                    System.out.println("Login in Invalid");

                        }

                        

                        

                

                } catch (AxisFault e) {

                        e.printStackTrace();

                } catch (RemoteException e) {

                        e.printStackTrace();

                }

                         catch(SQLExceptionException0 e) {

                                                e.printStackTrace();

                        }

 

        }

}

 

 

Service skeleton  code:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  /**

     * Auto generated method signature

     * @param getVehicleIds

     */

    public com.fw.ws.GetVehicleIdsResponse getVehicleIds(

        com.fw.ws.GetVehicleIds getVehicleIds) throws SQLExceptionException0
{

      com.fw.ws.GetVehicleIdsResponse response = new
com.fw.ws.GetVehicleIdsResponse();

      try{

            

            Statement st = null;

             ResultSet rs = null;

                  

                                    

            //connect to database

            Connection con = DatabaseConnection.getConnection();

        

              //query the user table

            String query = null;

            String [] vehicleIds = null;

            int counter = 0;

            int size = 0;

                   

            

            //session code

            MessageContext incomingContext =
MessageContext.getCurrentMessageContext();

            ServiceContext sc = incomingContext.getServiceContext();

            String username = (String)sc.getProperty("username");

            String password = (String)sc.getProperty("password");

            String key  = (String)sc.getProperty("key");

            

            

            

            if(key.equals("valid")){

                               query = "SELECT count(distinct v.vehicle_id,
vf.fleet_id) as size FROM  vehicle_fleets vf, vehicles v where  vf.fleet_id
= "+getVehicleIds.getFleetId()+" and  v.vehicle_id = vf.vehicle_id ";

                               st = con.createStatement();

                                   rs = st.executeQuery(query);

                                   

                                   while(rs.next()){

                                     size = rs.getInt("size");

                                   }      

                        

                                  vehicleIds =  new String[size]; 

                                   

                                    

                               query = "SELECT distinct v.vehicle_id,
vf.fleet_id FROM  vehicle_fleets vf, vehicles v where  vf.fleet_id =
"+getVehicleIds.getFleetId()+" and  v.vehicle_id = vf.vehicle_id";

                                   st = con.createStatement();

                                   rs = st.executeQuery(query);


                                  

                                 while(rs.next()){

                                    vehicleIds[counter] =
(String)rs.getString("vehicle_id"); 

                                    counter++;

                                 }


                                

                                 response.setVehicleId(vehicleIds);     

                                 return response;

                  

            }else{

                  return null;

            }

            

      }catch(SQLException ex){

            System.out.println("getVehicleIds Web Services:");

            ex.printStackTrace();

      }

      

      return null;

    }

 

 

Service.xml

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

<?xml version="1.0" encoding="UTF-8"?>

<!-- This file was auto-generated from WSDL -->

<!-- by the Apache Axis2 version: 1.3  Built on : Aug 10, 2007 (04:45:47
LKT) -->

<serviceGroup>

    <service name="FieldTrackerWS" scope="transportsession">

             <schema elementFormDefaultQualified="false"
attributeFormDefaultQualified="false"/>

     <messageReceivers>

            <messageReceiver mep="http://www.w3.org/ns/wsdl/in-only"
class="com.fw.ws.FieldTrackerWSMessageReceiverInOnly"/>

            <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out"
class="com.fw.ws.FieldTrackerWSMessageReceiverInOut"/>

        </messageReceivers>

        <parameter
name="ServiceClass">com.fw.ws.FieldTrackerWSSkeleton</parameter>

        <parameter name="useOriginalwsdl">true</parameter>

        <parameter name="modifyUserWSDLPortAddress">true</parameter> 

        <operation name="getHistoryData"
mep="http://www.w3.org/ns/wsdl/in-out">

            <actionMapping>urn:getHistoryData</actionMapping>

 
<outputActionMapping>urn:getHistoryDataResponse</outputActionMapping>

            <faultActionMapping
faultName="SQLException">urn:getHistoryDataSQLException</faultActionMapping>

        </operation>

        <operation name="getVehicleIds"
mep="http://www.w3.org/ns/wsdl/in-out">

            <actionMapping>urn:getVehicleIds</actionMapping>

 
<outputActionMapping>urn:getVehicleIdsResponse</outputActionMapping>

            <faultActionMapping
faultName="SQLException">urn:getVehicleIdsSQLException</faultActionMapping>

        </operation>

        <operation name="isValid" mep="http://www.w3.org/ns/wsdl/in-out">

            <actionMapping>urn:isValid</actionMapping>

            <outputActionMapping>urn:isValidResponse</outputActionMapping>

            <faultActionMapping
faultName="SQLException">urn:isValidSQLException</faultActionMapping>

        </operation>

        <operation name="logout" mep="http://www.w3.org/ns/wsdl/in-only">

            <actionMapping>urn:logout</actionMapping>

        </operation>

        <operation name="customerHasAccess"
mep="http://www.w3.org/ns/wsdl/in-out">

            <actionMapping>urn:customerHasAccess</actionMapping>

 
<outputActionMapping>urn:customerHasAccessResponse</outputActionMapping>

        </operation>

    </service>

</serviceGroup>

 

 

 

Run Time Error

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 

Login: true

org.apache.axis2.AxisFault: unknown

      at
org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:486
)

      at
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAx
isOperation.java:343)

      at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperatio
n.java:389)

      at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisO
peration.java:211)

      at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)

      at
com.fw.ws.FieldTrackerWSStub.getVehicleIds(FieldTrackerWSStub.java:449)

      at com.fw.ws.WebServiceClient.main(WebServiceClient.java:80)

 

 

 

 

Golam Chowdhury