package org.jboss.test.jbossnet.external.server;
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import org.jboss.test.util.ejb.SessionSupport;
import org.jboss.test.jbossnet.external.google.GoogleSearchPort;
import org.jboss.test.jbossnet.external.google.GoogleSearchService;
import org.jboss.test.jbossnet.external.google.GoogleSearchResult;
import org.jboss.test.jbossnet.external.babelfish.BabelFishPortType;
import org.jboss.test.jbossnet.external.babelfish.BabelFishService;
import org.jboss.logging.Logger;
import javax.naming.InitialContext;
public class FederatedServiceBean extends SessionSupport implements SessionBean
{
private static Logger log = Logger.getLogger(FederatedServiceBean.class);
public String findAndTranslate(String searchTerm) throws Exception
{
InitialContext initContext = new InitialContext();
GoogleSearchService googleService =
(GoogleSearchService) initContext.lookup("Google");
GoogleSearchPort google = googleService.getGoogleSearchPort();
String licenseKey =
System.getProperty(
"google.license",
"Wr5iTf5QFHJKmmnJn+61lt9jaMuWMKCj");
GoogleSearchResult searchResult =
google.doGoogleSearch(
licenseKey,
searchTerm,
0,
10,
true,
"",
false,
"",
"latin1",
"latin1");
log.debug("Query for: '" + searchTerm + "' returned: " + searchResult);
BabelFishService babelFishService =
(BabelFishService) initContext.lookup("BabelFish");
BabelFishPortType babelFish = babelFishService.getBabelFishPort();
try
{
String translationResult = babelFish.babelFish("en_de", searchTerm);
log.debug(
"Translation of: '"
+ searchTerm
+ "' returned: "
+ translationResult);
return translationResult;
} catch (RemoteException e)
{
return "This service is currently disabled.";
}
}
}