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
美国特价云服务器 2核4G 19.9元杭州王小玉网络科技有限公司成立于2020是拥有IDC ISP资质的正规公司,这次推荐的美国云服务器也是商家主打产品,有点在于稳定 速度 数据安全。企业级数据安全保障,支持异地灾备,数据安全系数达到了100%安全级别,是国内唯一一家美国云服务器拥有这个安全级别的商家。E5 2696v2x2 2核 4G内存 20G系统盘 10G数据盘 20M带宽 100G流量 1...
justhost.ru官方来消息说已经对网络进行了比较全面的优化,针对中国电信、联通、移动来说,4个机房总有一个适合中国用户,让站长进行一下测试,这不就有了这篇有关justhost的VPS的第四次测评。本帖主要关注的是网络,对于其他的参数一概不管! 官方网站:https://justhost.ru 最低配VPS:8.3元/月,KVM,512M内存,5G硬盘,200M带宽,不限流量 购买链接:...
传统农历新年将至,国人主机商DogYun(狗云)发来了虎年春节优惠活动,1月31日-2月6日活动期间使用优惠码新开动态云7折,经典云8折,新开独立服务器可立减100元/月;使用优惠码新开香港独立服务器优惠100元,并次月免费;活动期间单笔充值每满100元赠送10元,还可以参与幸运大转盘每日抽取5折码,流量,余额等奖品;商家限量推出一款年付特价套餐,共100台,每个用户限1台,香港VPS年付199元...
myim为你推荐
吴晓波频道买粉《充电时间》的节目跟《吴晓波频道》哪个好听?中小企业信息化中小企业信息化途径有哪些godaddyGodaddy域名怎么接受神雕侠侣礼包大全神雕侠侣手游版四重大礼包怎么得到啊?保护气球什么气球可以骑?如何快速收录如何让百度快速收录声母是什么哪些是声母,哪些是韵母,网页打不开的原因为什么我的有些网页打不开呢?请客网请人吃饭邀请文言文的短信有哪些?熊猫直播频道哪里可以查询熊猫频道每一个直播镜头是哪一只熊猫
windows2003iso 湖南服务器托管 asp免费空间申请 网站卫士 服务器合租 河南移动梦网 美国凤凰城 工信部网站备案查询 申请免费空间 双11促销 汤博乐 葫芦机 移动王卡 xshell5注册码 SmartAXMT800 hosting24 空间排行榜 月付空间 studentmain 日本小学生 更多