parsedmyim

myim  时间:2021-02-23  阅读:()
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

.asia域名是否适合做个人网站及.asia域名注册和续费成本

今天看到群里的老秦同学在布局自己的网站项目,这个同学还是比较奇怪的,他就喜欢用这些奇怪的域名。比如前几天看到有用.in域名,个人网站他用的.me域名不奇怪,这个还是常见的。今天看到他在做的一个范文网站的域名,居然用的是 .asia 后缀。问到其理由,是有不错好记的前缀。这里简单的搜索到.ASIA域名的新注册价格是有促销的,大约35元首年左右,续费大约是80元左右,这个成本算的话,比COM域名还贵。...

个人网站备案流程及注意事项(内容方向和适用主机商)

如今我们还有在做个人网站吗?随着自媒体和短视频的发展和兴起,包括我们很多WEB2.0产品的延续,当然也包括个人建站市场的低迷和用户关注的不同,有些个人已经不在做网站。但是,由于我们有些朋友出于网站的爱好或者说是有些项目还是基于PC端网站的,还是有网友抱有信心的,比如我们看到有一些老牌个人网站依旧在运行,且还有新网站的出现。今天在这篇文章中谈谈有网友问关于个人网站备案的问题。这个也是前几天有他在选择...

香港云服务器最便宜价格是多少钱一个月、一年?

香港云服务器最便宜价格是多少钱一个月/一年?无论香港云服务器推出什么类型的配置和活动,价格都会一直吸引我们,那么就来说说香港最便宜的云服务器类型和香港最低的云服务器价格吧。香港云服务器最便宜最低价的价格是多少?香港云服务器只是服务器中最受欢迎的产品。香港云服务器有多种配置类型,如1核1G、2核2G、2核4G、8到16核32G等。这些配置可以满足大多数用户的需求,无论是电商站、视频还是游戏、小说等。...

myim为你推荐
刷网站权重适当的刷百度指数对网站权重有影响吗站长故事部队里什么是站长?最低是什么级别?都有哪些级别啊?博客外链怎么用博客发外链?拂晓雅阁有什么网站是学电脑技术的`?渗透测试软件测试与渗透测试那个工作有前途1433端口1433端口怎么打开淘宝店推广给淘宝店铺推广有什么好处?保护气球气球保护液可以用什么来代替?xp系统停止服务XP系统停止服务后电脑怎么办?lockdowndios8.1能用gpp3to2吗?型号A1429
100m虚拟主机 怎么注册域名 网通服务器租用 工信部域名备案查询 阿里云邮箱登陆首页 加勒比群岛 42u机柜尺寸 gitcafe 正版win8.1升级win10 idc资讯 工作站服务器 美国在线代理服务器 美国网站服务器 hkt 台湾谷歌 789电视剧 香港亚马逊 www789 789 万网空间 更多