axis使用和配置1.docx

上传人:b****5 文档编号:6946157 上传时间:2023-01-13 格式:DOCX 页数:17 大小:137.58KB
下载 相关 举报
axis使用和配置1.docx_第1页
第1页 / 共17页
axis使用和配置1.docx_第2页
第2页 / 共17页
axis使用和配置1.docx_第3页
第3页 / 共17页
axis使用和配置1.docx_第4页
第4页 / 共17页
axis使用和配置1.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

axis使用和配置1.docx

《axis使用和配置1.docx》由会员分享,可在线阅读,更多相关《axis使用和配置1.docx(17页珍藏版)》请在冰豆网上搜索。

axis使用和配置1.docx

axis使用和配置1

在某些场景中AXIS提供很强大的功能,包括添加消息头,提供NTLM等多种认证方式,进行ACK发送的功能,具体参考SAP的AXISFQA。

本文档主要讲述PI的AXIS部署以及自定handler,涉及2个handler,一个用于外围系统异步发送系统的时候发生ACK给外围系统,另一个是PI采用Handler实现NTLMV2安全认证。

SP15,SP10之后SAP推出了针对ApacheHTTPClientlibrary的补丁,参考note2062567-IntegrationofApacheHttpClientlibraryinthePIAxisadapter可以实现NTLMV2。

而对于这2个补丁之前的版本SAP不支持NTLMV2协议。

本例的方法是根据SAP的SP包中的相关类进行反编译后的源代码封装成自己的handler类。

首先PI要支持AXIS,则需要部署部署情况可以通过网址jar(开始使用版本,发现有bug:

(NTLMV2用到此包,下面的2个包也一样)

用工具sdaMakerTool进行压缩。

如果是自己开发的handler类没有用到其他PI标准类的话也可以独立部署到这个包中,如果用到了其他类,其他的jar类也一并压缩到这个包中,并要进行加载,另外一种方式是把自定的handler类在SAP的axissampleadapter中实现,参考AXIS的FQA.

本文档中的两个类都是独立的类,用到的SAP标准的jar文件也压缩到其中。

ACKhandler类实现,网上有这个blog,照着blog实现。

代码如下。

packageclassZResponseHandlerextendsBasicHandler{

protectedstaticLoglog=publicvoidinvoke(MessageContextmsgContext)throwsAxisFault

{

/**ResponsehandlertowritecustomAribaresponse

*/

try{

StringMsg_id=("");

("PImessageidis"+Msg_id);

if(""))

Msg_id="0001";

StringrespTxt=createResponseText(Msg_id);

/**

*Gettingresponsesoapmessageenvelopandadd

*responsemessagetosoapbody

*/

etEnvelope().setTextContent(respTxt);

(msg);

}catch(Exceptione){

throw(e);

}

}

privateStringcreateResponseText(Stringmsgid)

{

StringpayloadID="1234";

Stringts=getTimeStamp();

StringrespText="\r\n"+

"

Envelopexmlns:

SOAP-ENV=\"">

Header/>\r\n"+

"

Body>"+

"

lang=\"en\"timestamp=\""+ts+"\">\r\n"+

"\r\n"+

"\r\n"+

""+msgid+""+

"\r\n"+

"\r\n"+

"

Body>\r\n"+

"

Envelope>";

returnrespText;

}

privateStringgetTimeStamp()

{

Datetoday=newDate();

SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd'T'HH:

mm:

ssZ");

etLog("");

PlainConnectionSocketFactoryplainsf;

booleancheckForDefaultPort;

booleanauthenticationPreemptive;

CloseableHttpClienthttpclient;

CommonsHTTPClientPropertiesclientProperties;

booleanhttpChunkStream;

publicvoidinit()

{

();

authenticationPreemptive=((String)getOption("")).booleanValue();

clientProperties=();

}

publicMyntlm(){

etProperty("checkForDefaultPort"));

HttpClientContextcontext=();

httpclientbuilder=createHttpClient(msgContext,context,targetURL);

RequestConfigreqConf=createRequestConfig(msgContext,targetURL,

httpclientbuilder);

booleanrestful=(

("enableREST")).booleanValue();

booleanposting=true;

StringwebMethod=null;

if()==

webMethod=("");

if(webMethod==null)

webMethod="POST";

else

posting=("POST")||("PUT");

if(posting){

if("put"))

method=newHttpPut());

else

method=newHttpPost());

}else{

method=newHttpGet());

}

addContextInfo(method,reqConf,msgContext,targetURL);

(reqConf);

StringhttpVersion=msgContext

.getStrProp("");

if(httpVersion!

=null&&("HTTP/"))

;

else

;

ByteArrayOutputStreambinReq=newByteArrayOutputStream();

StringcontentType="text/xml";

MessagereqMsg=();

if(reqMsg!

=null){

if(restful){

SOAPPartpart=();

Stringtypes[]=("Content-Type");

if(types!

=null&&>0)

contentType=types[0];

if(!

"Content-Type").getValue())){

("Content-Type");

("Content-Type",contentType);

}

(null);

("",

"false");

((newStringBuilder()).append("restmessageis:

")

.append(newString()))

.toString());

}else{

contentType=(msgContext

.getSOAPConstants());

}

(binReq);

}

((newStringBuilder()).append(

"Contenttypeofrequestmessagedeterminedto:

").append(

contentType).toString());

HttpEntityreqEntity=null;

if(posting){

EntityBuilderreqBuilder=();

());

if(""))

();

elseif())

();

(contentType));

reqEntity=();

if(method

.containsHeader){

("removingoldcontentencodingvalue...");

method

.removeHeaders;

}

((newStringBuilder()).append("settingchunkedto")

.append(httpChunkStream).toString());

((AbstractHttpEntity)reqEntity).setChunked(httpChunkStream);

((HttpEntityEnclosingRequest)method).setEntity(reqEntity);

}

HttpHosttarget=newHttpHost(),targetURL

.getPort(),());

httpclient=();

((newStringBuilder()).append("targetconfiguredto:

")

.append()).append("andcallingit...")

.toString());

CloseableHttpResponseresp=(target,method,

context);

intrespCode=().getStatusCode();

((newStringBuilder()).append(

"CalledsuccessfullywithHTTPcode:

").append(respCode)

.toString());

contentType=getHeader(resp,"Content-Type");

StringcontentLocation=getHeader(resp,"Content-Location");

StringcontentLength=getHeader(resp,"Content-Length");

if((respCode<=199||respCode>=300)

&&("text/html".equalsIgnoreCase(contentType)

||respCode<=499||respCode>=600)){

StringstatusMessage=().getReasonPhrase();

AxisFaultfault=newAxisFault("HTTP",(newStringBuilder())

.append("(").append(respCode).append(")").append(

statusMessage).toString(),null,null);

("return01",

(newStringBuilder()).append("").append(

()))

.toString()));

(respCode));

throwfault;

}

respBody=();

HeadercontEnc=();

if(contEnc!

=null){

HeaderElementelems[]=();

HeaderElementarr$[]=elems;

intlen$=arr$.length;

for(inti$=0;i$

HeaderElementel=arr$[i$];

if("gzip".equalsIgnoreCase())){

respBody=newGzipDecompressingEntity(respBody);

(respBody);

}

}

}

HeaderresponseHeaders[]=();

Stringenc=(respBody);

if(enc==null)

enc="iso-8859-1";

MessageoutMsg=null;

((newStringBuilder()).append(

"Contenttypeofresponsemessagedeterminedto:

").append(

contentType).toString());

if(restful){

outMsg=newMessage(respBody

.getContent(),enc,"UTF-8",false),false,

contentType,contentLocation);

().setMimeHeader("Content-Type",contentType);

try{

("",

"UTF-8");

}catch(SOAPExceptione){

("Errorwhilesettingmessageencoding",e);

}

}elseif(contentLength!

=null

&&"0".equalsIgnoreCase(contentLength))

outMsg=newMessage(newSOAPEnvelope());

else

outMsg=newMessage(),false,contentType,

contentLocation);

();

MimeHeadersresponseMimeHeaders=();

for(inti=0;i<;i++){

HeaderresponseHeader=responseHeaders[i];

(),

());

}

("response");

(outMsg);

if()){

Headerheaders[]=();

for(inti=0;i<;i++){

if(headers[i].getName().equalsIgnoreCase("Set-Cookie")){

handleCookie("Cookie",headers[i].getValue(),

msgContext);

continue;

}

if(headers[i].getName().equalsIgnoreCase("Set-Cookie2"))

handleCookie("Cookie2",headers[i].getValue(),

msgContext);

}

}

}catch(Exceptione){

("Error",e);

thrownewAxisFault("ErrorwhileinvokingHttpClientSender:

",e);

}

if(httpclient!

=null)

try{

();

}catch(IOExceptione){

("Errorwhileclosinghttpclient:

",e);

}

try{

();

}catch(IOExceptione){

("Errorwhileclosinghttpclient:

",e);

}

}

publicvoidhandleCookie(StringcookieName,Stringacookie,

MessageContextmsgContext){

Stringck[]=(",");

ArrayListcookies=newArrayList();

for(inti=0;i<;i++){

intindex=ck[i].indexOf(";");

if(index!

=-1)

ck[i]=ck[i].substring(0,index);

index=ck[i].indexOf("=");

Stringkey=index!

=-1ck[i].substring(0,index):

ck[i];

ObjectoldCookies=(cookieName);

booleanalreadyExist=false;

if(oldCookies!

=null)

if(oldCookiesinstanceofString[]){

StringoldCookiesArray[]=(String[])(String[])oldCookies;

for(intj=0;j<;j++){

StringanOldCookie=oldCookiesArray[j];

if(key!

=null&&(key)==0){

anOldCookie=ck[i];

alreadyExist=true;

}

(anOldCookie);

}

}else{

StringoldCookie=(String)oldCookies;

if(key!

=null&&(key)==0){

oldCookie=ck[i];

alreadyExist=true;

}

(oldCookie);

}

if(!

alreadyExist)

(ck[i]);

}

if()==1)

(cookieName,(0));

elseif()>1)

(cookieName,((Object)(cookies

.toArray(newString[()]))));

}

privateStringgetHeader(HttpResponseresp,Stringheader){

Headerh=(header);

returnh!

=null():

null;

}

privatevoidaddContextInfo(HttpRequestBasemethod,RequestConfigreqConf,

MessageContextmsgContext,URLtargetURL)throwsException{

Stringaction=()msgContext

.getSOAPActionURI():

"";

if(action==null)

action="";

Messagemsg=();

if(msg!

=null){

StringcontentType=(msgContext

.getSOAPConstants());

if()

&&()==

&&()==0)

contentType=(newStringBuilder()).append(contentType).append(

";action=\"").append(action).append("\"").toString();

("Content-Type",contentType);

}

if()==

||("attachment_encapsulation_format")=="")

("SOAPAction",(newStringBuilder()).append("\"")

.append(action).append("\"").toString());

("User-Agent",("axisUserAgent"));

if(""))

("Accept-Encoding","gzip");

MimeHea

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工作范文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1