Java - Problema con array en Servicio Web

 
Vista:

Problema con array en Servicio Web

Publicado por Rober (1 intervención) el 17/10/2007 18:53:16
Hola a todos, tengo un problema con un servicio web, que no consigo resolver. tengo un servicio web que a la vez es cliente de otro servicio web. El servicio Web principal recibe una lista de objetos del servicio web secundario. Y lo que quiero es coger los objetos de esta lista y meterlos en un array que va a ser la respuesta del servicio Web principal. El problema es que la llamada del servicio web secundario está dentro de un try, y aunque yo me creo un array (Hoteles) para utilizarlo en local, no me reconoce el array dentro del try y si me lo creo dentro del try, fuera de él no lo reconoce y no puedo obtener los datos para mandarlos al cliente.

Os agradecería mucho que me pudierais echar una mano.

Os paso el código:

*
* BuscadorAgencia4.java
*
* Created on 3 de septiembre de 2007, 20:31
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package ServicioAgencia4;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.WebServiceRef;
import java.util.*;
import java.io.*;
/**
*
* @author Rober
*/
@WebService()
public class BuscadorAgencia4
{
private ElementoReservahotel[] Hoteles= new ElementoReservahotel[25];

@WebServiceRef(wsdlLocation = "http://localhost:8080/ReservaHotel/BuscaHotelService?wsdl")
private ServicioAgencia4.BuscaHotelService service;
/**
* Web service operation
*/



@WebMethod
public ServicioAgencia4.ElementoViaje2[] BuscaViajes(@WebParam(name = "Transporte") String Transporte, @WebParam(name = "Destino") String Destino, @WebParam(name = "Fecha") String Fecha, @WebParam(name = "ClaseAsientos") String ClaseAsientos, @WebParam(name = "ClaseTren") String ClaseTren, @WebParam(name = "TipoTrayecto") String TipoTrayecto)
{
// TODO implement operation

ElementoViaje2[] ArrayViajes;
CompruebaDatos2 cd= new CompruebaDatos2();
ArrayViajes = cd.comprobar(Transporte, Destino, Fecha, ClaseAsientos, ClaseTren, TipoTrayecto);
System.out.println("Estos son, los datos");
System.out.println(ArrayViajes[0].getTransporte());
System.out.println(ArrayViajes[0].getDestino());
System.out.println(ArrayViajes[0].getFecha());
System.out.println(ArrayViajes[0].getHora());
System.out.println(ArrayViajes[0].getClaseAsientos());


boolean quiereHotel=true;
if (quiereHotel=true)
{
try
{ // Call Web Service Operation
ServicioAgencia4.BuscaHotel port = service.getBuscaHotelPort();
// TODO initialize WS operation arguments here
java.lang.String destino = ArrayViajes[0].getDestino();
java.lang.String fecha = ArrayViajes[0].getFecha();
// TODO process result here
java.util.List<ServicioAgencia4.ElementoReservahotel> result = port.extraeListaHotel(destino, fecha);
System.out.println("Estos son los datos obtenidos del Servicio Web Hotel");
System.out.println("Destino = "+result.get(0).getDestino());
System.out.println("Nombre = "+result.get(0).getNombre());
System.out.println("Fecha = "+result.get(0).getFecha());
System.out.println("Disponibilidad = "+result.get(0).getDisponibilidad());
System.out.println("Result = "+result);



int i=0;
System.out.println("Antes del while "+result.get(i).getDestino());
// Iterator it = result.iterator();
System.out.println("El tamano de la lista hotel es: "+result.size());
// while (it.hasNext())
ElementoReservahotel[] Hoteles=new ElementoReservahotel[25];
for (i=0;i<=result.size()-1;i++)
{
ElementoReservahotel hotel = new ElementoReservahotel();
hotel.setDestino(result.get(i).getDestino());
hotel.setNombre(result.get(i).getNombre());
hotel.setDisponibilidad(result.get(i).getDisponibilidad());
hotel.setFecha(result.get(i).getFecha());
Hoteles[i]= hotel;

}
}
catch (Exception ex)
{
// TODO handle custom exceptions here
System.out.println("Esta es la excepcion del Hotel dentro de BuscaViajes"+ ex.toString());
}

// System.out.println("Dentro del IF, este es el destino en el array Hoteles, a ver si funciona"+ Hoteles[0].getDestino());

}

// System.out.println("Este es el destino en el array Hoteles, a ver si funciona"+ Hoteles[0].getDestino());

return ArrayViajes;
}


}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder