This forum has been archived. Please start a new discussion on GitHub.

Any issues using Spring with ICE

Are there any known issues or things to be careful of when using ICE in the Spring container?


  • galbelli wrote: »
    Are there any known issues or things to be careful of when using ICE in the Spring container?


    Now I was asked to try to integrate the Spring OSGi(or Spring DM) and IceGrid. It seems that Ice is not suitable for enterprise application, for it's hard to integrate with mordern framework, such as spring, OSGi, AOP and so on.

    So if you need a cross-language communication protocol or tools for enterprise application, I thinks the SOAP or RPC is suitable, and if you need a cluster solution( or the Grid), why not try glassfish or jboss?
  • benoit
    benoit Rennes, France

    Can you be more specific? I don't see why it wouldn't be possible to use Ice from applications deployed with the Spring framework. And surely, using Ice is much better than using SOAP :)

    As to how to integrate IceGrid with the Spring framework, it's a different subject. It's actually not clear to me why you would want to do this. To me, like the Spring framework, IceGrid is a container (for Ice applications) and provides a deployment mechanism to deploy and manage these applications... So I'd think that you should either use one or the other.

    In any case, this doesn't mean that you can't use Ice within Spring applications, Ice is independant from IceGrid and it can be used from any Java application (that supports Java5 or Java6) regardless of how it's deployed.

  • Hi,

    thanks for your reply. I know that I am not more specific( or professional), But I have pay a lot time to the Ice specification document...

    yes, I use ice within spring container, and try to registry adapter or servant to the ice grid.

    here is my code:
    public class CommonI extends _CommonDisp {
    	private IMailService mailService;
    	private IJmsService jmsService;
    	private ISmsService smsService;
    	private IXmppService xmppService;
    	private Log logger = LogFactory.getLog(CommonI.class);
    	public boolean sendMail(String fromAddress, String[] toAddress,
    			String subject, String html, Current __current) {
    	//	CommonServer.commonServer.stop();"sendMail");
    		return mailService.send(fromAddress, toAddress, subject, html);
    	public boolean sendJmsToQueue(String queueName, String msg,
    			Current __current) {"sendJmsToQueue");
    		return jmsService.sendToQueue(queueName, msg);
    	public boolean sendJmsToTopic(String topicName, String msg,
    			Current __current) {"sendJmsToTopic");
    		return jmsService.sendToTopic(topicName, msg);
    	public boolean sendSms(String[] phones, String msg, Current __current) {"sendSms");
    		return smsService.send(phones, msg);
    	public boolean sendImMsg(String toAddress, String msg, Current __current) {"sendImMsg");
    		return xmppService.sendImMessage(toAddress, msg);
    	public User[] getList(Map<String, String> param, Current __current) {
    		return null;
    	public IMailService getMailService() {
    		return mailService;
    	public void setMailService(IMailService mailService) {
    		this.mailService = mailService;
    	public IJmsService getJmsService() {
    		return jmsService;
    	public void setJmsService(IJmsService jmsService) {
    		this.jmsService = jmsService;
    	public ISmsService getSmsService() {
    		return smsService;
    	public void setSmsService(ISmsService smsService) {
    		this.smsService = smsService;
    	public IXmppService getXmppService() {
    		return xmppService;
    	public void setXmppService(IXmppService xmppService) {
    		this.xmppService = xmppService;
    public class CommonServer extends Ice.Application {
    	private CommonI commonI;
    	protected Log logger = LogFactory.getLog(CommonServer.class);
    	private String defaultLocator = "xxxGrid/Locator:default -h -p 4061";
    	private String adapterId = "CommonAdapter";
    	private String endPoints = "tcp";
    	private String objectId = "CommonObject";
    	private Ice.ObjectAdapter commonAdapter;
            /**This m*/
    	public void start() {
    		new Thread(new Runnable() {
    			public void run() {
    				try {
    					Properties props = Ice.Util.createProperties();
    					props.setProperty("Ice.Default.Locator", defaultLocator);
    					props.setProperty("CommonAdapter.AdapterId", adapterId);
    					props.setProperty("CommonAdapter.Endpoints", endPoints);
    					InitializationData id = new InitializationData(); = props;
    					main("CommonServer", new String[] {}, id);
    				} catch (Exception e) {
    					logger.error("", e);
    	public int run(String[] args) {"trying to start commonServer...");
    		commonAdapter = communicator().createObjectAdapter("CommonAdapter");
    		Ice.Identity commonObjectId = communicator().stringToIdentity(objectId);
    		commonAdapter.add(commonI, commonObjectId);
    		commonAdapter.activate();"commonServer start OK.");
    		return 0;
    	public void stop() {"trying to stop common server...");
    		communicator().shutdown();"shutdown ok");
    	public CommonI getCommonI() {
    		return commonI;
    	public void setCommonI(CommonI commonI) {
    		this.commonI = commonI;
    	public String getDefaultLocator() {
    		return defaultLocator;
    	public void setDefaultLocator(String defaultLocator) {
    		this.defaultLocator = defaultLocator;
    	public String getAdapterId() {
    		return adapterId;
    	public void setAdapterId(String adapterId) {
    		this.adapterId = adapterId;
    	public String getEndPoints() {
    		return endPoints;
    	public void setEndPoints(String endPoints) {
    		this.endPoints = endPoints;
    	public String getObjectId() {
    		return objectId;
    	public void setObjectId(String objectId) {
    		this.objectId = objectId;

    These two class instance( or java bean) are managed by spring container. When spring container startup, it will auto invoke CommonServer.start, and then start the ice servant, and will register an adapter named CommonAdapter to IceRegistry.

    I package this spring application as an OSGi bundle, and deploy to two server, and start up it.

    I use the following PHP code to invoke the servant:
    <TITLE>Email Client</TITLE>
    try {
    	$p = $ICE->stringToProxy("CommonObject@CommonAdapter");
    	$common = $p->ice_checkedCast("::osgi::Common");
    		echo "send email ok<br>";
    		echo "send email error<br>";
    	echo " s <br>";
    } catch(Ice_LocalException $ex) {
    	//process the Exception
    	echo "<pre>\n";
    	echo "</pre>\n";

    The invocation is OK.
    But there is a problem:
    ICE for PHP always select one server(or machine) to connect to. So when I stop that server, PHP invocation is fail, and the exception is ObjectNotFound. Why PHP extendtion not try to use another server.
  • benoit
    benoit Rennes, France
    Before we can help you with this matter, could you specify which Ice version and operating system you're using? Please also update your company name and project field in your user profile. We require this information to provide free support on the forums.