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
最近看到群里的不少网友在搭建大数据内容网站,内容量有百万篇幅,包括图片可能有超过50GB,如果一台服务器有需要多个站点的话,那肯定默认的服务器50GB存储空间是不够用的。如果单独在购买数据盘会成本提高不少。这里我们看到腾讯云促销活动中有2款带大数据盘的套餐还是比较实惠的,一台是400GB数据盘,一台是800GB数据盘,适合他们的大数据网站。 直达链接 - 腾讯云 大数据盘套餐服务器这里我们看到当前...
hosteons当前对美国洛杉矶、达拉斯、纽约数据中心的VPS进行特别的促销活动:(1)免费从1Gbps升级到10Gbps带宽,(2)Free Blesta License授权,(3)Windows server 2019授权,要求从2G内存起,而且是年付。 官方网站:https://www.hosteons.com 使用优惠码:zhujicepingEDDB10G,可以获得: 免费升级10...
国外主机测评昨天接到Hostigger(现Hostiger)商家邮件推送,称其又推出了一款特价大内存VPS,机房位于土耳其的亚欧交界城市伊斯坦布尔,核50G SSD硬盘200Mbps带宽不限月流量只要$59/年。 最近一次分享的促销信息还是5月底,当时商家推出的是同机房同配置的大内存VPS,价格是$59.99/年,不过内存只有10G,虽然同样是大内存,但想必这次商家给出16G,价格却是$59/年,...
myim为你推荐
回收站在哪vivo手机的回收站在哪主页改不了为什么我电脑的主页改不了了?bbsxpdvbbs bbsxp LeadBBS 对比无线路由器限速设置无线路由器限速怎么设置!照片转手绘有什么软件可以把相片变成手绘的,不是美图秀秀里面的开机滚动条开机滚动条要很长时间怎么解决?人人逛街包公免费逛街打一成语lockdownd[求教]在淘宝买了张激活卡,请问怎么取消激活宕机何谓宕机?cr2格式如何打开CR2格式的照片呢
最好的虚拟主机 域名邮箱 大庆服务器租用 美国主机评测 blackfriday suspended shopex空间 万网优惠券 主机合租 e蜗牛 工信部icp备案号 泉州移动 100m独享 php空间购买 hkt metalink 监控服务器 卡巴斯基官网下载 阿里云个人邮箱 美国十大啦 更多