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 "Mathias P.W Nilsson" <ma...@snyltarna.se> on 2007/09/06 09:44:11 UTC
RPCServiceClient and ArrayList
Hi!
I can't get my service to work with sending arraylist. It works fine sending
just one object but not the list
here is my client code
=============================================
package samples.demo;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class WeatherRPCClient {
public static void main(String[] args1) throws AxisFault {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new
EndpointReference("http://localhost:8080/axis2-book-1.1/services/WeatherService");
options.setTo(targetEPR);
// Setting the weather
QName opSetWeather = new QName("http://demo.samples", "setWeather");
Weather w = new Weather();
w.setTemperature((float)39.6);
w.setForecast("Cloudy with showers");
w.setRain(true);
w.setHowMuchRain((float)4.5);
Weather w1 = new Weather();
w1.setTemperature((float)4.6);
w1.setForecast("sunny day with showers");
w1.setRain(true);
w1.setHowMuchRain((float)2.5);
ArrayList<Weather> l = new ArrayList<Weather>();
l.add(w);
l.add( w1 );
Object[] opSetWeatherArgs = new Object[] { l };
//serviceClient.invokeBlocking(opSetWeather, opSetWeatherArgs);
serviceClient.invokeRobust(opSetWeather, opSetWeatherArgs);
// Getting the weather
QName opGetWeather = new QName("http://demo.samples", "getWeather");
Object[] opGetWeatherArgs = new Object[] { };
Class[] returnTypes = new Class[] { Weather.class };
Object[] response = serviceClient.invokeBlocking(opGetWeather,
opGetWeatherArgs, returnTypes);
Weather result = (Weather) response[0];
if (result == null) {
System.out.println("Weather didn't initialize!");
return;
}
// Displaying the result
System.out.println("Id : " +
result.getId());
System.out.println("Temperature : " +
result.getTemperature());
System.out.println("Forecast : " +
result.getForecast());
System.out.println("Rain : " +
result.getRain());
System.out.println("How much rain (in inches) : " +
result.getHowMuchRain());
result.setForecast( "hehehe" );
opSetWeatherArgs = new Object[] { result };
//serviceClient.invokeBlocking(opSetWeather, opSetWeatherArgs);
serviceClient.invokeRobust(opSetWeather, opSetWeatherArgs);
}
}
=============================================
And here is my service
=============================================
package samples.demo;
import java.util.ArrayList;
import org.hibernate.Session;
public class WeatherService{
public void setWeather(ArrayList<Weather> weathers){
Session session = HibernateUtil.getSession();
HibernateUtil.beginTransaction();
for( Weather weather : weathers ){
if( weather.getId() != null ){
session.update(weather);
}else{
session.persist(weather);
}
}
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
}
public Weather getWeather(){
Session session = HibernateUtil.getSession();
Weather w = ( Weather ) session.get(Weather.class, new Long( 1 ));
HibernateUtil.closeSession();
return w;
}
}
=============================================
When I'm calling setWeather I get this except
ijava.lang.ClassCastException: org.apache.axiom.om.impl.llom.OMElementImpl
cannot be cast to samples.demo.Weather
at samples.demo.WeatherService.setWeather(WeatherService.java:14)
seems like when I put Weather class In arraylist it gets cast?
--
View this message in context: http://www.nabble.com/RPCServiceClient-and-ArrayList-tf4390198.html#a12517244
Sent from the Axis - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
RE: RPCServiceClient and ArrayList
Posted by "Mathias P.W Nilsson" <ma...@snyltarna.se>.
Thanks but this I have done. It's still an array and not an ArrayList
--
View this message in context: http://www.nabble.com/RPCServiceClient-and-ArrayList-tf4390198.html#a12523540
Sent from the Axis - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
RE: RPCServiceClient and ArrayList
Posted by "Bhojraj, Santosh" <Sa...@ustrust.com>.
You can. You will need to set the object type of an array.
QName opFindAllEntries = new
QName("http://service.addressbook.sample/xsd", "findAllEntries");
Object[] opFindAllEntriesArgs = new Object[0] ;
Class[] returnTypesList = new Class[] { Entry[].class };
Object[] allEntriesResponse =
serviceClient.invokeBlocking(opFindAllEntries,
opFindAllEntriesArgs,
returnTypesList);
// System.out.println("Num RESPONSE Entries : " + (null !=
allEntriesResponse ? allEntriesResponse.length : 0 ) );
System.out.println("RESPONSE Entry class: " +
allEntriesResponse[0].getClass() );
Object[] allEntriesRsltArray = (Object[])
allEntriesResponse[0];
System.out.println("Num Entries in Result Array:" +
allEntriesRsltArray.length );
for(int i=0, n= allEntriesRsltArray.length; i < n;i++)
{
System.out.println("Entry # " + (i+1) + ": " +
(null != allEntriesRsltArray[i]
? ((Entry)allEntriesRsltArray[i]).getName() : "NULL") );
}
Or use JIBX.
-----Original Message-----
From: Mathias P.W Nilsson [mailto:mathias@snyltarna.se]
Sent: Thursday, September 06, 2007 3:57 AM
To: axis-user@ws.apache.org
Subject: Re: RPCServiceClient and ArrayList
I got it to work by sending an array an not a list.
Why can't I send ArrayList?
--
View this message in context:
http://www.nabble.com/RPCServiceClient-and-ArrayList-tf4390198.html#a125
17424
Sent from the Axis - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
Re: RPCServiceClient and ArrayList
Posted by "Mathias P.W Nilsson" <ma...@snyltarna.se>.
I got it to work by sending an array an not a list.
Why can't I send ArrayList?
--
View this message in context: http://www.nabble.com/RPCServiceClient-and-ArrayList-tf4390198.html#a12517424
Sent from the Axis - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org