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
易探云服务器怎么样?易探云是国内一家云计算服务商家,致力香港云服务器、美国云服务器、国内外服务器租用及托管等互联网业务,目前主要地区为运作香港BGP、香港CN2、广东、北京、深圳等地区。目前,易探云推出的国内云服务器优惠活动,国内云服务器2核2G5M云服务器低至330元/年起;成都4核8G/200G硬盘/15M带宽,仅1888元/3年起!易探云便宜vps服务器配置推荐:易探云vps云主机,入门型云...
这不端午节和大家一样回家休息几天,也没有照顾网站的更新。今天又出去忙一天没有时间更新,这里简单搜集看看是不是有一些商家促销活动,因为我看到电商平台各种推送活动今天又开始一波,所以说现在的各种促销让人真的很累。比如在前面我们也有看到PacificRack 商家发布过年中活动,这不在端午节(昨天)又发布一款闪购活动,有些朋友姑且较多是端午节活动,刚才有看到活动还在的,如果有需要的朋友可以看看。第一、端...
零途云是一家香港公司,主要产品香港cn2 gia线路、美国Cera线路云主机,美国CERA高防服务器,日本CN2直连服务器;同时提供香港多ip站群云服务器。即日起,购买香港/美国/日本云服务器享受9折优惠,新用户有优惠码:LINGTUYUN,使用即可打折。目前,零途云还推出性价比非常高香港多ip站群云服务器,有需要的,可以关注一下。零途云优惠码:优惠码:LINGTUYUN (新用户优惠,享受9折优...
myim为你推荐
qq讨论组手机上QQ怎么创建讨论组?推广方法如何做推广?郭吉军郭吉军和管鹏这两个站长怎么样?群里有人骂伪装微信地理位置如何用伪装微信地理位置?怎么样免费装扮qq空间要怎么免费装扮QQ空间!吴晓波频道买粉《吴晓波频道》《罗辑思维》《专栏精粹》怎么评价?吴晓波频道买粉看吴晓波频道的心得网站联盟网盟跟b2b平台有什么区别安卓应用平台安卓系统支持的软件并不是那么多,为什么这么多人推崇?如何建立一个网站如何建立一个网站
免费注册网站域名 hawkhost优惠码 国外私服 permitrootlogin 天猫双十一秒杀 好看的桌面背景图 服务器架设 申请个人网页 商务主机 免费全能空间 个人域名 泉州电信 美国免费空间 t云 vip域名 免费外链相册 便宜空间 免费ftp 英雄联盟台服官网 谷歌台湾 更多