1、axis使用和配置1在某些场景中AXIS提供很强大的功能,包括添加消息头,提供NTLM等多种认证方式,进行ACK发送的功能,具体参考SAP 的AXIS FQA。本文档主要讲述PI的AXIS部署以及自定handler,涉及2个handler,一个用于外围系统异步发送系统的时候发生ACK给外围系统,另一个是PI采用Handler实现NTLM V2安全认证。 SP15 , SP10之后SAP推出了针对Apache HTTP Client library的补丁,参考note 2062567 - Integration of Apache HttpClient library in the PI Axi
2、s adapter可以实现NTLM V2。而对于这2个补丁之前的版本SAP不支持 NTLM V2协议。本例的方法是根据SAP的SP包中的相关类进行反编译后的源代码封装成自己的handler类。首先PI要支持AXIS,则需要部署部署情况可以通过网址 jar(开始使用版本,发现有bug: ) (NTLM V2 用到此包,下面的2个包也一样) 用工具sdaMakerTool进行压缩。如果是自己开发的handler类没有用到其他PI标准类的话也可以独立部署到这个包中,如果用到了其他类,其他的jar类也一并压缩到这个包中,并要进行加载,另外一种方式是把自定的handler类在SAP 的axis samp
3、le adapter中实现,参考AXIS的FQA.本文档中的两个类都是独立的类,用到的SAP标准的jar文件也压缩到其中。ACK handler类实现,网上有这个blog,照着blog实现。代码如下。package class ZResponseHandler extends BasicHandler protected static Log log = public void invoke(MessageContext msgContext) throws AxisFault /* Response handler to write custom Ariba response */ try
4、String Msg_id = (); (PI messageid is +Msg_id); if () Msg_id = 0001; String respTxt = createResponseText(Msg_id); /* * Getting response soap message envelop and add * response message to soap body */ etEnvelope().setTextContent(respTxt); (msg); catch (Exception e) throw (e); private String createResp
5、onseText(String msgid) String payloadID = 1234; String ts = getTimeStamp(); String respText = rn+ rn + + rn + rn + rn + +msgid+ rn + rn + rn + ; return respText; private String getTimeStamp() Date today = new Date(); SimpleDateFormat sdf = new SimpleDateFormat(yyyy-MM-ddTHH:mm:ssZ); etLog(); PlainCo
6、nnectionSocketFactory plainsf; boolean checkForDefaultPort; boolean authenticationPreemptive; CloseableHttpClient httpclient; CommonsHTTPClientProperties clientProperties; boolean httpChunkStream; public void init() (); authenticationPreemptive = (String)getOption().booleanValue(); clientProperties
7、= (); public Myntlm() etProperty(checkForDefaultPort); HttpClientContext context = (); httpclientbuilder = createHttpClient(msgContext, context, targetURL); RequestConfig reqConf = createRequestConfig(msgContext, targetURL, httpclientbuilder); boolean restful = ( (enableREST).booleanValue(); boolean
8、 posting = true; String webMethod = null; if () = webMethod = (); if (webMethod = null) webMethod = POST; else posting = (POST) | (PUT); if (posting) if (put) method = new HttpPut(); else method = new HttpPost(); else method = new HttpGet(); addContextInfo(method, reqConf, msgContext, targetURL); (r
9、eqConf); String httpVersion = msgContext .getStrProp(); if (httpVersion != null & (HTTP/) ; else ; ByteArrayOutputStream binReq = new ByteArrayOutputStream(); String contentType = text/xml; Message reqMsg = (); if (reqMsg != null) if (restful) SOAPPart part = (); String types = (Content-Type); if (t
10、ypes != null & 0) contentType = types0; if (!( Content-Type).getValue() (Content-Type); (Content-Type, contentType); (null); (, false); (new StringBuilder().append(rest message is: ) .append(new String() .toString(); else contentType = (msgContext .getSOAPConstants(); (binReq); (new StringBuilder().
11、append( Content type of request message determined to: ).append( contentType).toString(); HttpEntity reqEntity = null; if (posting) EntityBuilder reqBuilder = (); (); if () (); else if () (); (contentType); reqEntity = (); if (method .containsHeader) (removing old content encoding value.); method .r
12、emoveHeaders; (new StringBuilder().append(setting chunked to ) .append(httpChunkStream).toString(); (AbstractHttpEntity) reqEntity).setChunked(httpChunkStream); (HttpEntityEnclosingRequest) method).setEntity(reqEntity); HttpHost target = new HttpHost(), targetURL .getPort(), (); httpclient = (); (ne
13、w StringBuilder().append(target configured to: ) .append().append( and calling it .) .toString(); CloseableHttpResponse resp = (target, method, context); int respCode = ().getStatusCode(); (new StringBuilder().append( Called successfully with HTTP code: ).append(respCode) .toString(); contentType =
14、getHeader(resp, Content-Type); String contentLocation = getHeader(resp, Content-Location); String contentLength = getHeader(resp, Content-Length); if (respCode = 300) & (text/html.equalsIgnoreCase(contentType) | respCode = 600) String statusMessage = ().getReasonPhrase(); AxisFault fault = new AxisF
15、ault(HTTP, (new StringBuilder() .append().append(respCode).append().append( statusMessage).toString(), null, null); (return01, (new StringBuilder().append().append( () .toString(); , (respCode); throw fault; respBody = (); Header contEnc = (); if (contEnc != null) HeaderElement elems = (); HeaderEle
16、ment arr$ = elems; int len$ = arr$.length; for (int i$ = 0; i$ len$; i$+) HeaderElement el = arr$i$; if (gzip.equalsIgnoreCase() respBody = new GzipDecompressingEntity(respBody); (respBody); Header responseHeaders = (); String enc = (respBody); if (enc = null) enc = iso-8859-1; Message outMsg = null
17、; (new StringBuilder().append( Content type of response message determined to: ).append( contentType).toString(); if (restful) outMsg = new Message(respBody .getContent(), enc, UTF-8, false), false, contentType, contentLocation); ().setMimeHeader(Content-Type, contentType); try (, UTF-8); catch (SOA
18、PException e) (Error while setting message encoding, e); else if (contentLength != null & 0.equalsIgnoreCase(contentLength) outMsg = new Message(new SOAPEnvelope(); else outMsg = new Message(), false, contentType, contentLocation); (); MimeHeaders responseMimeHeaders = (); for (int i = 0; i ; i+) He
19、ader responseHeader = responseHeadersi; (), (); (response); (outMsg); if () Header headers = (); for (int i = 0; i ; i+) if (headersi.getName().equalsIgnoreCase(Set-Cookie) handleCookie(Cookie, headersi.getValue(), msgContext); continue; if (headersi.getName().equalsIgnoreCase(Set-Cookie2) handleCoo
20、kie(Cookie2, headersi.getValue(), msgContext); catch (Exception e) (Error , e); throw new AxisFault(Error while invoking HttpClientSender: , e); if (httpclient != null) try (); catch (IOException e) (Error while closing http client: , e); try (); catch (IOException e) (Error while closing http clien
21、t: , e); public void handleCookie(String cookieName, String acookie, MessageContext msgContext) String ck = (,); ArrayList cookies = new ArrayList(); for (int i = 0; i ; i+) int index = cki.indexOf(;); if (index != -1) cki = cki.substring(0, index); index = cki.indexOf(=); String key = index != -1 c
22、ki.substring(0, index) : cki; Object oldCookies = (cookieName); boolean alreadyExist = false; if (oldCookies != null) if (oldCookies instanceof String) String oldCookiesArray = (String) (String) oldCookies; for (int j = 0; j 1) (cookieName, (Object) (cookies .toArray(new String(); private String get
23、Header(HttpResponse resp, String header) Header h = (header); return h != null () : null; private void addContextInfo(HttpRequestBase method, RequestConfig reqConf, MessageContext msgContext, URL targetURL) throws Exception String action = () msgContext .getSOAPActionURI() : ; if (action = null) act
24、ion = ; Message msg = (); if (msg != null) String contentType = (msgContext .getSOAPConstants(); if () & () = & () = 0) contentType = (new StringBuilder().append(contentType).append( ; action=).append(action).append().toString(); (Content-Type, contentType); if () = | (attachment_encapsulation_format) = ) (SOAPAction, (new StringBuilder().append() .append(action).append().toString(); (User-Agent, (axisUserAgent); if () (Accept-Encoding, gzip); MimeHea
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1