Home Help Center

Any issues using Spring with ICE

galbelligalbelli Member Gary AlbelliOrganization: GAA ConsultingProject: Multiple projects for a financial companies SOA
Are there any known issues or things to be careful of when using ICE in the Spring container?

Comments

  • JiangyubaoJiangyubao Member Yubao JiangOrganization: www.gliet.edu.cnProject: integrate OSGi & Ice to provice service for PHP ✭✭
    galbelli wrote: »
    Are there any known issues or things to be careful of when using ICE in the Spring container?

    Hi:

    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?
  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi,

    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.

    Cheers,
    Benoit.
  • JiangyubaoJiangyubao Member Yubao JiangOrganization: www.gliet.edu.cnProject: integrate OSGi & Ice to provice service for PHP ✭✭
    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);
    
    	@Override
    	public boolean sendMail(String fromAddress, String[] toAddress,
    			String subject, String html, Current __current) {
    	//	CommonServer.commonServer.stop();
    		logger.info("sendMail");
    		return mailService.send(fromAddress, toAddress, subject, html);
    	}
    
    	@Override
    	public boolean sendJmsToQueue(String queueName, String msg,
    			Current __current) {
    		logger.info("sendJmsToQueue");
    		return jmsService.sendToQueue(queueName, msg);
    	}
    
    	@Override
    	public boolean sendJmsToTopic(String topicName, String msg,
    			Current __current) {
    		logger.info("sendJmsToTopic");
    		return jmsService.sendToTopic(topicName, msg);
    	}
    
    	@Override
    	public boolean sendSms(String[] phones, String msg, Current __current) {
    		logger.info("sendSms");
    		return smsService.send(phones, msg);
    	}
    
    	@Override
    	public boolean sendImMsg(String toAddress, String msg, Current __current) {
    		logger.info("sendImMsg");
    		return xmppService.sendImMessage(toAddress, msg);
    	}
    
    	@Override
    	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 grid.registry.com -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() {
    			@Override
    			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();
    					id.properties = props;
    					main("CommonServer", new String[] {}, id);
    				} catch (Exception e) {
    					logger.error("", e);
    				}
    			}
    		}).start();
    	}
    
    	public int run(String[] args) {
    		logger.info("trying to start commonServer...");
    		commonAdapter = communicator().createObjectAdapter("CommonAdapter");
    		Ice.Identity commonObjectId = communicator().stringToIdentity(objectId);
    		commonAdapter.add(commonI, commonObjectId);
    		commonAdapter.activate();
    		logger.info("commonServer start OK.");
    		communicator().waitForShutdown();
    		return 0;
    	}
    
    	public void stop() {
    		logger.info("trying to stop common server...");
    		communicator().shutdown();
    		logger.info("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:
     <HTML>
    <HEAD>
    <TITLE>Email Client</TITLE>
    </HEAD>
    <?php
    Ice_loadProfile("common");
    try {
    	$p = $ICE->stringToProxy("[email protected]");
    	$common = $p->ice_checkedCast("::osgi::Common");
    	$success=$common->sendMail("[email protected]",array("[email protected]"),"hello","hello,");
    	if($success){
    		echo "send email ok<br>";
    	}else{
    		echo "send email error<br>";
    	}
    	echo " s <br>";
    } catch(Ice_LocalException $ex) {
    	//process the Exception
    	echo "<pre>\n";
    	print_r($ex);
    	echo "</pre>\n";
    }
    ?>
    </HTML>
    

    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.
  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    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.

    Cheers,
    Benoit.
Sign In or Register to comment.