CopyrightIBMCorporation2009TrademarksDevelopinganXML-basedLotusSametimebotasastartupbeanonWebSphereApplicationServerV7.
0Page1of9DevelopinganXML-basedLotusSametimebotasastartupbeanonWebSphereApplicationServerV7.
0AhmedAlsumJune29,2009(FirstpublishedJune23,2009)Improvingtherepresentationforback-endcontentandsystemservicesusinganIBMLotusSametimebotisaneasywaytoattractuserswhoarealreadyfamiliarwiththetoolandwantquickresultswithoutgoingtoyetanotherWebsite.
Thisarticleprovidesastep-by-stepguidetodevelopinganXML-basedLotusSametimebotasastartupbeanonIBMWebSphereApplicationServerV7.
0.
Editor'snote:KnowalotaboutthistopicWanttoshareyourexpertiseParticipateintheIBMLotussoftwarewikiprogramtoday.
LotusSametimewikiIntroductionFirst,thisarticledescribeshowtoimplementaLotusSametimebotthatinteractswithdata-centricsystemsbasedonanXMLdataserviceprovidersuchasSOA,Webservices,orevenaservletthatmanipulatesXMLdata.
XSLTcontrolstherenderingoftheXMLresponse.
Next,theaccesstotheLotusSametimebotislimitedtoaspecificauthenticatedgroup.
Finally,thearticledelvesintohowtomanagetheLotusSametimebotloginandlogoutoperationsusingastart-upEnterpriseJavaBean(EJB)deployedonWebSphereApplicationServerV7.
0.
XML-basedLotusSametimebotXMLbecomesthemainstreamtechnologyfortransferringandmanipulatingdata.
TheLotusSametimeJavatoolkitallowsyoutoaccesscoreLotusSametimeservices,suchaspresenceawareness,instantmessaging,andscreensharingbymeansoftheJavaprogramminglanguage.
Inthisarticle,anextensionoftheLotusSametimebotisshowntoworkasanXMLdataconsumerthatfitsintheSOApicture.
Figure1showstherelationshipbetweentheXMLdataserviceproviderandtheXMLLotusSametimebotextension.
developerWorksibm.
com/developerWorks/DevelopinganXML-basedLotusSametimebotasastartupbeanonWebSphereApplicationServerV7.
0Page2of9Figure1.
LotusSametimebotandXMLdataserviceproviderarchitectureInthefollowingsections,wediscussthetwomainpartsofconnectingtheLotusSametimebotandtheXMLdataprovider:EstablishingaconnectionbetweenLotusSametimeJavaandtheexternaldatasourceusingaURL,includingwrappingtheresponseintoanXML-docobject.
TransformingtheXML-docobjectintoreadabletext.
TheLotusSametimebotconnectstotheXMLdataproviderTheXMLdataproviderusuallyisaccessibleusingthestringurl,whichcontainstheservername,therequiredservice,andthesupportedparameters.
IntheLotusSametimebotenvironment,youmightneedtocustomizethestringurlbasedontheusercommand(forexample,youmightneedtoaddparametersbasedonthecommand).
TheURLConnectionclasscanbeusedtoconnecttoanexternalWebserver.
Initially,theurltextfortheexternaldatasourceiswrappedintheURLobject,whichisusedtoopentheconnection.
Then,theURLConnectionclassisusedtoestablishtheconnection.
WhilemostsensitivedataprovidersexposetheirdatathroughtheSSLconnection,theURLConnectionclasscansupportpassingusernamesandpasswordstotheexternaldatasource.
NotethatiftheWebsiteusesanSSLcertificatethatisnottrusted,thecertificateshouldbeimportedintotheapplicationserverkeystorecertificate.
Lines2-8inlisting1showasampleofcodetoconnecttotheexternalsecuredatasourceusingstringurl.
TheLotusSametimebotreceivesaresponsefromtheXMLdataproviderTheLotusSametimebotreceivestheresponseasaninputStreamofdata;itshouldbewrappedintotheXMLdocumentobject.
Lines9-11inlisting1explainthestepsrequiredtotransformtheinputStreamintoanXMLdocumentobject.
AninstanceofDocumentBuilderFactoryisobtained,whichdefinesafactoryAPIthatenablesapplicationstoobtainaparserthatproducesDOMobjecttreesfromanXMLdocument.
ThisobjectisusedtocreateanewinstanceoftheDocumentBuilderclass.
Afteraninstanceofthisclassisobtained,XMLcanbeparsedfromavarietyofinputsources.
HereweparsedtheXMLfromtheinputStream.
Listing1.
TheLotusSametimebotconnectstotheXMLdataprovider1.
PublicDocumentconnect(StringurlStr){2.
URLurl;3.
try{4.
url=newURL(urlStr.
toString());5.
URLConnectionconn=url.
openConnection();6.
StringuserPassword="myUser:myPassword";7.
Stringencoding=newsun.
misc.
BASE64Encoder().
encode(userPassword.
getBytes());ibm.
com/developerWorks/developerWorksDevelopinganXML-basedLotusSametimebotasastartupbeanonWebSphereApplicationServerV7.
0Page3of98.
conn.
setRequestProperty("Authorization","Basic"+encoding);9.
conn.
connect();10.
DocumentBuilderFactorydbf=DocumentBuilderFactory.
newInstance();11.
DocumentBuilderdb=dbf.
newDocumentBuilder();12.
Documentdoc=db.
parse(conn.
getInputStream());13.
}catch(MalformedURLExceptione){14.
e.
printStackTrace();15.
}catch(IOExceptione){16.
e.
printStackTrace();17.
}catch(ParserConfigurationExceptione){18.
e.
printStackTrace();19.
}catch(SAXExceptione){20.
e.
printStackTrace();21.
}22.
returndoc;23.
}TheLotusSametimebottransformsaresponseusingXSLTAlthoughtheXMLdocumentobjectiseasytoparseandeasytounderstandonthecodinglevel,itfailsinuserreadability.
TheXMLresponsecannotbesentdirectlytotheuser;itneedstobeparsedinawaythattheusercanread.
AlotoftechniquessupportXMLparsingandpreparingofreadable,well-formattedtextfortheuser.
XSLTransformation(XSLT)isusedtotransformanXMLdocumentintoanotherXMLdocument,orintoanothertypeofdocumentthatisrecognizedbyabrowser,suchasHTMLandXHTMLorevenplaintext.
TheJavalibrarycontainsaformatterthatcombinesXMLdocumentswiththerelatedXSLTfilesandtransformsthemtotherequiredoutputformat.
Listing2showsthesamplecodeusedtotransferanXMLdocumenttoatext,basedontheXSLfilesavedonaspecificpath.
Listing2.
AsamplefunctiontotransformtheXML-docobjecttotextusinganXSLTfile1.
publicStringformat(Documentdom,StringxlsFilePath){2.
DOMSourcesrc=null;3.
StreamResultres=null;4.
StringWritersw=newStringWriter();5.
Filefile=newFile(xlsFilePath);6.
7.
if(file.
exists()){8.
try{9.
TransformerFactoryfactory=TransformerFactory.
newInstance();10.
Transformertransformer=factory.
newTransformer(newStreamSource(file));11.
src=newDOMSource(dom);12.
res=newStreamResult(sw);13.
transformer.
transform(src,res);14.
}catch(TransformerExceptione){15.
e.
printStackTrace();16.
}17.
}18.
returnsw.
toString();19.
}ImListener.
textReceivedcancombinebothfunctionstoprepareastringurlbasedonthecommand(forexample,thestringurlmightcontaindifferentparametersbasedontheusercommand).
Additionally,youcancreatedifferentXSLTresponsefilesforeachcommand.
Listing3containsasampleofcodeofImListener.
textReceivedthatcallsboththeconnectandformatmethods.
developerWorksibm.
com/developerWorks/DevelopinganXML-basedLotusSametimebotasastartupbeanonWebSphereApplicationServerV7.
0Page4of9Figures2and3showsamplesoftheXMLresponseandtherelatedXSLTfile,andfigure4showsthetextresponseasitappearstotheuser.
Listing3.
OverridenmethodImListener.
textReceived1.
publicclassMyImListenerimplementsImListener{2.
.
3.
4.
publicvoidtextReceived(ImEvente){5.
StringurlStr=prepareURLForCommand(e);6.
DocumentresponseDoc=connect(urlStr);7.
Stringanswer=format(responseDoc,"c://response.
xsl");8.
e.
getIm().
sendText(true,answer);9.
10.
.
11.
.
12.
}Figure2.
ReceivedXMLresponseFigure3.
XSLTfileibm.
com/developerWorks/developerWorksDevelopinganXML-basedLotusSametimebotasastartupbeanonWebSphereApplicationServerV7.
0Page5of9Figure4.
LotusSametimebotbehaviorThistechniqueissufficientlydynamictoreflecttoanyupdatesintheXMLdataproviderresponse;theonlyrequiredstepisuploadinganewXSLTfilewithoutanycodeupdate.
Also,thecodecanbeupdatedtolettheLotusSametimebotconnecttodifferentdatasources.
SecureLotusSametimebotTheLotusSametimeclientdoesnotlimitaddinguserIDstothecontactslist;thisfactmeansthattheLotusSametimebotisaccessibletoawiderangeofuserswhomightnothaveauthorizedaccesstothesystem.
ControllingaccesstoconfidentialinformationistheresponsibilityoftheLotusSametimebotitself.
Whenusersopenachatwindowwiththebot,ImServiceListener.
imReceived(ImEvente)isinvoked.
TheImEventobjectcontainstheessentialinformationabouttheuserIDImEvent.
getIm().
getPartner().
getId().
TheLotusSametimebotcanusethisvaluetochecktheuserIDinitsaccesslist.
Listing4showsanexampleofhowtosecuretheconfidentialinformationfromunauthorizedaccessusingbluegroups.
Youneedtoimplementtheauthenticate(StringuserID)methodtovalidatetheuserIDbasedontheaccessgroup.
Listing4.
ImServiceListener.
imReceivedauthenticatesuserID1.
publicvoidimReceived(ImEvente){2.
ImListenerimListener=null;3.
if(authenticate(e.
getIm().
getPartner().
getId())){4.
imListener=AuthorizedListener.
getListener(e);5.
e.
getIm().
sendText(true,WELCOME_TEXT);6.
}else{7.
imListener=UnAuthorizedListener.
getUnAuthorizedListener(e);8.
e.
getIm().
sendText(true,WELCOME_UNAUTHORIZED_TEXT);9.
}10.
e.
getIm().
addImListener(imListener);11.
}LotusSametimebotdeploymentTheLotusSametimebotrunsasastand-aloneapplication.
TotheLotusSametimeserver,aLotusSametimebotisusuallyconsideredjustanotherperson.
TheLotusSametimebotneedsonlytodeveloperWorksibm.
com/developerWorks/DevelopinganXML-basedLotusSametimebotasastartupbeanonWebSphereApplicationServerV7.
0Page6of9authenticateonthemessagingserverusingavalidusernameandpassword;itdoesn'trelyonhowtheLotusSametimebotwasdeployed.
Fromthecodingperspective,youcombinetherequiredstepsthathandletheloginandlogoutactivities;thesemethodsarethecontrollerofthestatusoftheLotusSametimebot.
Listings5and6showsamplecodesforbothmethods.
Inthissection,weprovidedifferentapproachestodeploytheLotusSametimebotonWebSphereApplicationServer.
Thetargetofthedifferentdeploymentapproachesistoprovideacontrolledmechanismtocallbothloginandlogoutmethods.
Listing5.
logIn()methodimplementation1.
publicvoidlogIn()2.
{3.
if(stsession==null){4.
try{5.
java.
util.
DateinitTime=newjava.
util.
Date();6.
stsession=newSTSession("MySametimeBot"+String.
valueOf(initTime.
getTime()));7.
8.
}catch(DuplicateObjectExceptione){9.
e.
printStackTrace();10.
return;11.
}12.
}13.
14.
if(!
stsession.
isActive()){15.
stsession.
loadSemanticComponents();16.
stsession.
start();17.
}18.
19.
commService=(CommunityService)stsession.
getCompApi(CommunityService.
COMP_NAME);20.
m_fileTransSvc=(FileTransferService)stsession.
getCompApi(FileTransferService.
COMP_NAME);21.
m_fileTransSvc.
addFileTransferServiceListener(this);22.
commService.
addLoginListener(this);23.
commService.
setLoginType(logInType);24.
commService.
enableAutomaticReconnect(100,5000);25.
commService.
loginByPassword(SERVER_NAME,USER_ID,PASSWORD);26.
}27.
Listing6.
logOut()methodimplementation1.
publicvoidlogOut()2.
{3.
commService=(CommunityService)stsession.
getCompApi(CommunityService.
COMP_NAME);4.
commService.
logout();5.
stsession.
stop();6.
stsession.
unloadSession();7.
}DifferentdeploymentapproachesThefirstdeploymentapproachthatdependsonJava2Platform,EnterpriseEdition(J2EE)technologiesisthedeploymentoftheLotusSametimebotasaservlet.
YouneedtocreateaservletandtomodifythedoGetmethodtoaccepttheuseractionsasURLparameters.
Theseactionsareabletoinvokeboththelogin()andlogout()methods.
Listing7showsasamplecodethatallowsyoutodeploytheLotusSametimebotasaservlet.
ibm.
com/developerWorks/developerWorksDevelopinganXML-basedLotusSametimebotasastartupbeanonWebSphereApplicationServerV7.
0Page7of9Listing7.
OverriddendoGetmethod1.
protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throws2.
ServletException,IOException{3.
4.
Stringaction=request.
getParameter("action");5.
PrintWriterout=response.
getWriter();6.
if("start".
equalsIgnoreCase(action)){7.
out.
println("RequesttostartSametimebot");8.
ebb=newMySametimeBot();9.
ebb.
logIn();10.
ebb.
start();11.
}elseif("stop".
equalsIgnoreCase(action)){12.
out.
println("RequesttostopSametimebot");13.
ebb.
logOut();14.
}else{15.
out.
println("Unknownaction:"+action);16.
}17.
}SupposetheservlethasaURLmappingassametimebotServlet.
TostarttheLotusSametimebot,enterthisURL:http://myserver/sametimebotServlet/action=startTostoptheLotusSametimebot,enterthisURL:http://myserver/sametimebotServlet/action=stopDeployasstartupbeansInsomecases,managingtheLotusSametimebotusingaservletorastand-aloneJavaapplicationisnotsecure.
Tobesecure,managementneedsmorecontroloftheLotusSametimebotstatus.
Inthissection,wedevelopanewapproachforusingtheEJBstartupbeanasacontainerforcontrollingtheLotusSametimebotstatus.
What'sastartupbeanAstartupbeanisauser-definedEJB2.
0sessionbean.
AmodulestartupbeanisasessionbeanthatisloadedwhenanEJBJARfilestarts.
ModulestartupbeansenableJ2EEapplicationstorunbusinesslogicautomatically,wheneveranEJBmodulestartsorstopsnormally.
TheEJBcanbeeitherstatefulorstateless.
Ifitisstateful,thesameinstanceisusedforstartandstop.
Otherwise,twoinstancesarecreated.
Youmustusethefollowinghomeandremoteinterfaces:TheEJBhomeinterfacemustbecom.
ibm.
websphere.
startupservice.
AppStartUpHome,todefinestart()andstop()methodsonthebean.
TheEJBremoteinterfacemustbecom.
ibm.
websphere.
startupservice.
AppStartUp,todefinestart()andstop()methodsonthebean.
Thestartupbeanstart()methodiscalledwhenthemoduleorapplicationstartsandcontainsbusinesslogictoberunatthemoduleorapplicationstarttime.
Thestartupbeanstop()methodiscalledwhenthemoduleorapplicationstopsandcontainsbusinesslogictoberunatthemoduledeveloperWorksibm.
com/developerWorks/DevelopinganXML-basedLotusSametimebotasastartupbeanonWebSphereApplicationServerV7.
0Page8of9orapplicationstoptime.
Anyexceptionthrownbyastop()methodisloggedonly;nootheractionistaken.
DeployingtheLotusSametimebotasastartupbeanCreatetheLotusSametimebotcodeinaseparateJavaprojectandincludeitintotheEJBstartupbeanproject.
Afterthat,theLotusSametimebotobjectinitializationandlogIn()methodareinvokedinthestart()method.
Also,thelogOut()methodisinvokedinthestop()method.
Seethecodeinlisting8.
Listing8.
ManagingLotusSametimebotstatususingstartandstopmethods1.
publicclassMySametimeBotStartupBeanimplementsjavax.
ejb.
SessionBean{2.
publicbooleanstart()3.
{4.
System.
out.
println("MySametimebotisstarting.
");5.
ebb=newMySametimeBot();6.
ebb.
logIn();7.
ebb.
start();8.
returntrue;//iffalseisreturnedanexceptionwillbethrownandtheapplicationisnotstarted9.
}10.
publicvoidstop()11.
{12.
System.
out.
println("MySametimebotisstopping.
");13.
ebb.
logOut();14.
}15.
}TheapplicationispackagedasanEnterpriseApplication(EAR)andisdeployedonWebSphereApplicationServer.
AftersuccessfuldeploymentoftheEARproject,youcanstartandstoptheLotusSametimebotinstance.
ConclusionInthisarticle,newaspectsoftheLotusSametimebot'sdevelopmentanddeploymentcyclesarediscussed.
First,theLotusSametimebotcouldconnecttotheXMLdatasourceusingJavaAPIs,supportedwiththeXSLTformattertoturntheXMLresponseintotextthattheusercanread.
DuetothesensitivityoftheXMLdatasource,anadditionalsecuritylevelisaddedtotheLotusSametimebotbasedontheuserIDtokeeptheXMLdatasourcesafe.
Finally,differentapproachesofdeployingtheLotusSametimebotarelistedwithdetaileddiscussionsofthedeploymentasastartupbean.
AcknowledgmentThisworkwasdoneasapartofIBM'sCorporateClientSupportPortal(CCSP)inNovember2008.
TheauthorwouldliketoexpressgratitudetotheCCSPteamfortheirvaluablecomments.
CopyrightIBMCorporation2009(www.
ibm.
com/legal/copytrade.
shtml)Trademarks(www.
ibm.
com/developerworks/ibm/trademarks/)ibm.
com/developerWorks/developerWorksDevelopinganXML-basedLotusSametimebotasastartupbeanonWebSphereApplicationServerV7.
0Page9of9
阿里云(aliyun)在这个月又推出了一个金秋上云季活动,到9月30日前,每天两场秒杀活动,包括轻量应用服务器、云服务器、云数据库、短信包、存储包、CDN流量包等等产品,其中Aliyun轻量云服务器最低60元/年起,还可以99元续费3次!活动针对新用户和没有购买过他们的产品的老用户均可参与,每人限购1件。关于阿里云不用多说了,国内首屈一指的云服务器商家,无论建站还是学习都是相当靠谱的。活动地址:h...
iWebFusion(iWFHosting)在部落分享过很多次了,这是成立于2001年的老牌国外主机商H4Y旗下站点,提供的产品包括虚拟主机、VPS和独立服务器租用等等,其中VPS主机基于KVM架构,数据中心可选美国洛杉矶、北卡、本德、蒙蒂塞洛等。商家独立服务器可选5个不同机房,最低每月57美元起,而大流量10Gbps带宽服务器也仅149美元起。首先我们分享几款常规服务器配置信息,以下机器可选择5...
百纵科技:美国高防服务器,洛杉矶C3机房 独家接入zenlayer清洗 带金盾硬防,CPU全系列E52670、E52680v3 DDR4内存 三星固态盘阵列!带宽接入了cn2/bgp线路,速度快,无需备案,非常适合国内外用户群体的外贸、搭建网站等用途。C3机房,双程CN2线路,默认200G高防,3+1(高防IP),不限流量,季付送带宽美国洛杉矶C3机房套餐处理器内存硬盘IP数带宽线路防御价格/月套...
myim为你推荐
ptrint(*ptr)*()怎么理解?文件夹删不掉为什么文件夹删除不了伪静态什么是伪静态网站?伪静态网站有什么优势网易公开课怎么下载网易公开课的视频该如何下载?mate8价格手机华为mat8售价多少安全漏洞如何发现系统安全漏洞系统分析员考系统分析员有什么好处?网站推广外链网站推广,免费的超级外链有用吗?seo还应该做什么手工杀毒怎样不用杀毒软件自己手动查毒?office2007简体中文版如何激活office2007 professional简体中文专业版啊?
服务器租赁 东莞服务器租用 高防服务器租用qy Dedicated cpanel主机 payoneer ixwebhosting 免费博客空间 京东商城双十一活动 工信部icp备案号 广州服务器 hkt 银盘服务是什么 cloudlink 万网空间管理 备案空间 上海电信测速 服务器论坛 网页加速 腾讯网盘 更多