Reputation: 667
I'm developing an application which uses some services where I have to use Date types. The WebService has this method:
public TRespuestaPedidosClientes consultarPedidosClientes(int id_cuenta_padre, int nivel_cuenta_padre, int id_cuenta, Date f_inicio, Date f_fin, int estado_pedido, String n_pedido)
{
// devuelve los pedidos asociados de una cuenta o de todas las cuentas hijas
// en un rango de fechas y con estado determinado
//
// id_cuenta == 0 -> buscar las cuentas hijas asociadas a la cuenta padre
// los pedidos los realizán las cuentas de nivel >= 3
// cuenta padre es de nivel 1 -> los pedidos son de sus cuentas hijas de nivel 2
// cuenta padre es de nivel 2 -> los pedidos son de sus cuentas hijas de nivel 3 y de las hijas de éstas
// id_cuenta != 0 -> solo los pedidos de ésta cuenta:
// - nivel_cuenta_padre = 1 => id_cuenta debe ser de nivel 2
// - nivel_cuenta_padre = 2 => id_cuenta debe ser de nivel 3
// - nivel_cuenta_padre = 3 => id_cuenta puede ser igual que id_cuenta_padre (ella misma) o puede ser de nivel 4 o 5
TRespuestaPedidosClientes resultado = new TRespuestaPedidosClientes();
try
{
System.out.println("F_inicio es:"+f_inicio.getTime());
System.out.println("Tengo la cuenta padre:"+id_cuenta_padre);
System.out.println("El nivel del padre es"+nivel_cuenta_padre);
// A-> nivel cuenta padre = 1
// - buscar cuentas hijas -> nivel 2
// - por cada cuenta hija de nivel 2: A y C
// B-> nivel cuenta padre = 2
// - buscar cuentas hijas -> nivel 3
// - buscar pedidos
// C-> nivel cuenta padre >= 3
// - buscar cuentas hijas -> nivel 4
// - pedidos de la cuenta actual y de sus hijas
TRespuestaCuentas result1 = new TRespuestaCuentas();
switch (nivel_cuenta_padre)
{
case 0:
{
result1 = buscar_Cuentas_Hijas(id_cuenta_padre);
if (result1.getError() == -1)
throw new Exception("Error al buscar las cuentas hija");
for (int i = 0; i < result1.getDatosCuentas().length; i++)
{
if ((id_cuenta == 0) || (id_cuenta != 0 && id_cuenta == result1.getDatosCuentas()[i].getId_cuenta()))
{
TRespuestaPedidosClientes resultP = buscar_Pedidos_Cuenta(id_cuenta_padre, result1.getDatosCuentas()[i], 0, estado_pedido, f_inicio, f_fin, n_pedido);
if (resultP.getError() == -1)
throw new Exception(resultP.getDescripcion_error());
if (resultP.getDatosPedidosClientes() != null)
{
for (int k = 0; k < resultP.getDatosPedidosClientes().length; k++)
{
resultP.getDatosPedidosClientes()[k].setCuenta(result1.getDatosCuentas()[i].getNombre());
}
// añadir pedidos a resultado
resultP.setDatosPedidosClientes(cargar_Datos_PedidosClientes_Array(resultP.getDatosPedidosClientes(), resultado.getDatosPedidosClientes()));
}
}
}
break;
}
case 1:
{
result1 = buscar_Cuentas_Hijas(id_cuenta_padre);
if (result1.error == -1)
throw new Exception("Error al buscar las cuentas hijas");
for (int i = 0; i < result1.getDatosCuentas().length; i++)
{
if ((id_cuenta == 0) || (id_cuenta != 0 && id_cuenta == result1.getDatosCuentas()[i].getId_cuenta()))
{
TRespuestaPedidosClientes resultP = buscar_Pedidos_Cuenta(id_cuenta_padre, result1.getDatosCuentas()[i], 0, estado_pedido, f_inicio, f_fin, n_pedido);
if (resultP.error == -1)
throw new Exception(resultP.getDescripcion_error());
if (resultP.getDatosPedidosClientes() != null)
{
for (int k = 0; k < resultP.getDatosPedidosClientes().length; k++)
{
resultP.getDatosPedidosClientes()[k].setCuenta(result1.getDatosCuentas()[i].getNombre());
}
// añadir pedidos a resultado
resultP.setDatosPedidosClientes(cargar_Datos_PedidosClientes_Array(resultP.getDatosPedidosClientes(), resultado.getDatosPedidosClientes()));
}
}
}
break;
}
case 2:
{
result1 = buscar_Cuentas_Hijas(id_cuenta_padre);
if (result1.error == -1)
throw new Exception("Error al buscar cuentas hijas");
System.out.println("Datos cuentas es:"+result1.getDatosCuentas().length);
for (int i = 0; i < result1.getDatosCuentas().length; i++)
{
if ((id_cuenta == 0) || (id_cuenta != 0 && id_cuenta == result1.getDatosCuentas()[i].getId_cuenta()))
{
TRespuestaPedidosClientes resultP = buscar_Pedidos_Cuenta(id_cuenta_padre, result1.getDatosCuentas()[i], 0, estado_pedido, f_inicio, f_fin, n_pedido);
System.out.println("ResultP"+resultP.getError());
if (resultP.getError() == -1)
throw new Exception(resultP.getDescripcion_error());
if (resultP.getError() != 4)
{
// añadir pedidos a resultado
resultP.setDatosPedidosClientes(cargar_Datos_PedidosClientes_Array(resultP.getDatosPedidosClientes(), resultado.getDatosPedidosClientes()));
}
}
}
break;
}
default:
{
result1 = buscar_Datos_Cuenta(id_cuenta_padre);
if (result1.getError() == -1)
throw new Exception("Error al buscar los datos de las cuentas");
TRespuestaPedidosClientes resultP = buscar_Pedidos_Cuenta(id_cuenta_padre, result1.getDatosCuentas()[0], id_cuenta, estado_pedido, f_inicio, f_fin, n_pedido);
if (resultP.getError() == -1)
throw new Exception(resultP.getDescripcion_error());
if (resultP.getDatosPedidosClientes() != null)
{
// añadir pedidos a resultado
resultP.setDatosPedidosClientes(cargar_Datos_PedidosClientes_Array(resultP.getDatosPedidosClientes(), resultado.getDatosPedidosClientes()));
}
break;
}
}
resultado.setError(0);
resultado.setDescripcion_error("");
return resultado;
}
catch (Exception ex)
{
resultado.setError(-1);
resultado.setDescripcion_error(ex.getMessage());
resultado.setDatosPedidosClientes(null);
return resultado;
}
}
When I invoke this service from the client I do this:
TRespuestaPedidosClientes pedidosClientes=bsStubcloud.consultarPedidosClientes(params[0].getId_cuenta_padre(), nivel, cuenta, cal, calF, 0, servletRequest.getParameter("edt_pedido").toString());
Where cal and calF are transformed into Calendar type and I don't know why. I use Axis, it's any way to keep these date types and as well when I pass these parameters they get the today day not, what I send. What can I do?.
Thanks so much
Upvotes: 0
Views: 200
Reputation: 71
When JAXB maps the java object to xml, the java data type are mapped to corresponding xml schema type. You can find more details on data type mapping here.
The java data type for xml schema type dateTime/date/time is javax.xml.datatype.XMLGregorianCalendar
In this case the java Date created by your server side is first marshaled to xml and in client the xml date is unmarshaled to java date type (XMLGregorianCalendar).Hence you get calendar object.
Hope this helps.
Upvotes: 1