AXIS使用和配置_第1頁
AXIS使用和配置_第2頁
AXIS使用和配置_第3頁
AXIS使用和配置_第4頁
AXIS使用和配置_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、在某些場(chǎng)景中AXIS提供很強(qiáng)大的功能,包括添加消息頭,提供NTLM等多種認(rèn)證方式,進(jìn)行ACK發(fā)送的功能,具體參考SAP 的AXIS FQA。本文檔主要講述PI的AXIS部署以及自定handler,涉及2個(gè)handler,一個(gè)用于外圍系統(tǒng)異步發(fā)送系統(tǒng)的時(shí)候發(fā)生ACK給外圍系統(tǒng),另一個(gè)是PI采用Handler實(shí)現(xiàn)NTLM V2安全認(rèn)證。PI7.31 SP15 ,PI7.4 SP10之后SAP推出了針對(duì)Apache HTTP Client library的補(bǔ)丁,參考note 2062567 - Integration of Apache HttpClient library in the PI Ax

2、is adapter可以實(shí)現(xiàn)NTLM V2。而對(duì)于這2個(gè)補(bǔ)丁之前的版本SAP不支持 NTLM V2協(xié)議。本例的方法是根據(jù)SAP的SP包中的相關(guān)類進(jìn)行反編譯后的源代碼封裝成自己的handler類。首先PI要支持AXIS,則需要部署部署情況可以通過網(wǎng)址http:/<host>:<port>/XIAxisAdapter/MessageServlet進(jìn)行校驗(yàn)。用到下面的類:commons-codec-1.9. jar(開始使用1.3版本,發(fā)現(xiàn)有bug: java.lang.RuntimeException: java.lang.NoSuchMethodError: mons.c

3、odec.binary.Base64.(I)V;) (NTLM V2 用到此包,下面的2個(gè)包也一樣) 用工具sdaMakerTool進(jìn)行壓縮。如果是自己開發(fā)的handler類沒有用到其他PI標(biāo)準(zhǔn)類的話也可以獨(dú)立部署到這個(gè)包中,如果用到了其他類,其他的jar類也一并壓縮到這個(gè)包中,并要進(jìn)行加載,另外一種方式是把自定的handler類在SAP 的axis sample adapter中實(shí)現(xiàn),參考AXIS的FQA.本文檔中的兩個(gè)類都是獨(dú)立的類,用到的SAP標(biāo)準(zhǔn)的jar文件也壓縮到其中。ACK handler類實(shí)現(xiàn),網(wǎng)上有這個(gè)blog,照著blog實(shí)現(xiàn)。代碼如下。package com.sap.aii

4、.axis.sample.handlers;import java.io.ByteArrayInputStream;import ;import ;import ;import ;import ;import ;import java.nio.charset.Charset;import ;import java.text.SimpleDateFormat;import ;import java.util.Date;import ;import java.util.TimeZone;import ;import javax.xml.soap.MessageFactory;import java

5、x.xml.soap.MimeHeaders;import ;import ;import javax.xml.soap.SOAPMessage;import ;import ;import ;import ;import ;import ;import ;import ;import ;import org.apache.axis.AxisFault;import ;import org.apache.axis.MessageContext;import ponents.logger.LogFactory;import org.apache.axis.handlers.BasicHandle

6、r;import ;import ;import ;import mons.logging.Log;import ;import ;import ;import ;public class ZResponseHandler extends BasicHandler protected static Log log = LogFactory.getLog(ZResponseHandler.class.getName();public void invoke(MessageContext msgContext) throws AxisFault /* Response handler to wri

7、te custom Ariba response */ try String Msg_id = msgContext.getStrProp("request.id"); ("PI messageid is "+Msg_id); if (Msg_id.equals("") Msg_id = "0001" String respTxt = createResponseText(Msg_id); /* * Getting response soap message envelop and add * re

8、sponse message to soap body */ /MessageFactory messageFactory = MessageFactory.newInstance(); MessageFactory messageFactory = new org.apache.axis.soap.MessageFactoryImpl(); / SOAPMessage curMsg = messageFactory.createMessage(new MimeHeaders(), / new ByteArrayInputStream(respTxt.getBytes(Charset.forN

9、ame("UTF-8"); /getSoapMessageFromString(respTxt); /setValue(respTxt); / SOAPMessage curMsg = messageFactory.createMessage(); SOAPMessage msg = messageFactory.createMessage(new MimeHeaders(), new ByteArrayInputStream(respTxt.getBytes(Charset.forName("UTF-8"); /curMsg.getSOAPPart()

10、.getEnvelope().setTextContent(respTxt); msgContext.setMessage(msg); catch (Exception e) throw AxisFault.makeFault(e); private String createResponseText(String msgid) String payloadID = "1234" / Get time stamp in GMT-800 format. String ts = getTimeStamp(); String respText = "<?xml v

11、ersion="1.0" encoding="UTF-8"?>rn"+ "<SOAP-ENV:Envelope xmlns:SOAP-ENV="/soap/envelope/"><SOAP-ENV:Header/>rn" + "<SOAP-ENV:Body>"+ "<cXML payloadID=""+payloadID+"" xml:la

12、ng="en" timestamp=""+ts+"">rn" + "<Response>rn" + "<Status code="200" text="OK"/>rn" + "<Msg_id>"+msgid+"</Msg_id>"+ "</Response>rn" + "</cXML>rn"

13、 + "</SOAP-ENV:Body>rn" + "</SOAP-ENV:Envelope>" return respText; private String getTimeStamp() Date today = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); /root.setAttribute("timestamp","2002-03-12T

14、18:39:09-08:00"); sdf.setTimeZone(TimeZone.getTimeZone("GMT-08:00"); / String zone = TimeZone.getAvailableIDs(); /* for(int i =0;i<zone.length;i+) System.out.println(zonei); */ String timeStamp = sdf.format(today); / System.out.println(timeStamp); return timeStamp; 主要是把PI產(chǎn)生的MESSAGE

15、 ID也一并反饋給外圍系統(tǒng)用于跟蹤與確認(rèn)。NTLM Handler類:package com.sap.aii.axis.sample.handlers;import java.io.ByteArrayOutputStream;import java.io.IOException;import .URL;import java.util.ArrayList;import java.util.Hashtable;import java.util.Iterator;import javax.xml.soap.MimeHeader;import javax.xml.soap.MimeHeaders;i

16、mport javax.xml.soap.SOAPException;import javax.xml.soap.SOAPPart;import org.apache.axis.AxisFault;import org.apache.axis.Constants;import org.apache.axis.Message;import org.apache.axis.MessageContext;import .CommonsHTTPClientProperties;import .CommonsHTTPClientPropertiesFactory;import org.apache.ax

17、is.handlers.BasicHandler;import org.apache.axis.message.SOAPEnvelope;import org.apache.axis.soap.SOAPConstants;import org.apache.axis.transport.http.HTTPConstants;import org.apache.axis.utils.Messages;import org.apache.axis.utils.NetworkUtils;import mons.logging.Log;import mons.logging.LogFactory;im

18、port org.apache.http.Header;import org.apache.http.HeaderElement;import org.apache.http.HttpEntity;import org.apache.http.HttpEntityEnclosingRequest;import ;import org.apache.http.HttpHost;import ;import ;import org.apache.http.HttpResponse;import org.apache.http.HttpVersion;import org.apache.http.P

19、rotocolException;import org.apache.http.auth.AuthScope;import org.apache.http.auth.NTCredentials;import org.apache.http.auth.UsernamePasswordCredentials;import org.apache.http.client.AuthCache;import org.apache.http.client.CredentialsProvider;import org.apache.http.client.config.RequestConfig;import

20、 org.apache.http.client.entity.EntityBuilder;import org.apache.http.client.entity.GzipDecompressingEntity;import org.apache.http.client.methods.CloseableHttpResponse;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.methods.HttpPost;import org.apache.http.client.methods.Htt

21、pPut;import org.apache.http.client.methods.HttpRequestBase;import tocol.HttpClientContext;import org.apache.http.config.RegistryBuilder;import org.apache.http.conn.socket.PlainConnectionSocketFactory;import org.apache.http.entity.AbstractHttpEntity;import org.apache.http.en

22、tity.ContentType;import org.apache.http.impl.auth.BasicScheme;import org.apache.http.impl.auth.DigestScheme;import org.apache.http.impl.client.BasicAuthCache;import org.apache.http.impl.client.BasicCredentialsProvider;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl

23、.client.HttpClientBuilder;import org.apache.http.impl.client.HttpClients;import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;import ;import ;import org.apache.http.util.EntityUtils;import .AXISSocketFactory;import com.sap.aii.axis.utils.JavaUtils;public class Myntlm extends BasicHand

24、ler /* * */private static final long serialVersionUID = 1L;protected static Log log = LogFactory.getLog("com.sap.aii.axis.sample.handlers.Myntlm");PlainConnectionSocketFactory plainsf;boolean checkForDefaultPort;boolean authenticationPreemptive;CloseableHttpClient httpclient;CommonsHTTPCli

25、entProperties clientProperties;boolean httpChunkStream;public void init()super.init();authenticationPreemptive = Boolean.valueOf(String)getOption("http.authentication.preemptive").booleanValue();clientProperties = CommonsHTTPClientPropertiesFactory.create();public Myntlm() /useChunckedStre

26、am = true;clientProperties = null;httpChunkStream = true;plainsf = null;/layeredsf = null;checkForDefaultPort = false;/sendAcceptEnc = false;initialize();private void initialize()plainsf = new PlainConnectionSocketFactory();/layeredsf = new IAIKHttpClientSocketFactory();public void invoke(MessageCon

27、text msgContext) throws AxisFault HttpRequestBase method = null;HttpClientBuilder httpclientbuilder = null;httpclient = null;HttpEntity respBody = null;try URL targetURL = new URL(msgContext.getStrProp("transport.url");checkForDefaultPort = Boolean.parseBoolean(String) msgContext.getProper

28、ty("checkForDefaultPort");HttpClientContext context = HttpClientContext.create();httpclientbuilder = createHttpClient(msgContext, context, targetURL);RequestConfig reqConf = createRequestConfig(msgContext, targetURL,httpclientbuilder);boolean restful = Boolean.valueOf(msgContext.getStrProp

29、("enableREST").booleanValue();boolean posting = true;String webMethod = null;if (msgContext.getSOAPConstants() = SOAPConstants.SOAP12_CONSTANTS)webMethod = msgContext.getStrProp("soap12.webmethod");if (webMethod = null)webMethod = "POST"elseposting = webMethod.equals(&q

30、uot;POST") | webMethod.equals("PUT");if (posting) if (webMethod.equalsIgnoreCase("put")method = new HttpPut(targetURL.getFile();elsemethod = new HttpPost(targetURL.getFile(); else method = new HttpGet(targetURL.toURI();addContextInfo(method, reqConf, msgContext, targetURL);m

31、ethod.setConfig(reqConf);String httpVersion = msgContext.getStrProp("axis.transport.version");if (httpVersion != null && httpVersion.equalsIgnoreCase("HTTP/1.0")method.setProtocolVersion(HttpVersion.HTTP_1_0);elsemethod.setProtocolVersion(HttpVersion.HTTP_1_1);ByteArrayOu

32、tputStream binReq = new ByteArrayOutputStream();String contentType = "text/xml"Message reqMsg = msgContext.getRequestMessage();if (reqMsg != null) if (restful) SOAPPart part = reqMsg.getSOAPPart();String types = part.getMimeHeader("Content-Type");if (types != null && type

33、s.length > 0)contentType = types0;if (!contentType.equalsIgnoreCase(method.getFirstHeader("Content-Type").getValue() method.removeHeaders("Content-Type");method.addHeader("Content-Type", contentType);reqMsg.setMessageContext(null);reqMsg.setProperty("javax.xml.s

34、oap.write-xml-declaration","false");log.debug(new StringBuilder().append("rest message is: ").append(new String(reqMsg.getSOAPPartAsBytes().toString(); else contentType = reqMsg.getContentType(msgContext.getSOAPConstants();reqMsg.writeTo(binReq);log.debug(new StringBuilder()

35、.append("Content type of request message determined to: ").append(contentType).toString();HttpEntity reqEntity = null;if (posting) EntityBuilder reqBuilder = EntityBuilder.create();reqBuilder.setBinary(binReq.toByteArray();if (msgContext.isPropertyTrue("transport.http.gzipRequest"

36、;)reqBuilder.gzipCompress();else if (reqBuilder.isGzipCompress()reqBuilder.gzipCompress();reqBuilder.setContentType(ContentType.create(contentType);reqEntity = reqBuilder.build();if (method.containsHeader(HTTPConstants.HEADER_TRANSFER_ENCODING) log.debug("removing old content encoding value.&qu

37、ot;);method.removeHeaders(HTTPConstants.HEADER_TRANSFER_ENCODING);log.debug(new StringBuilder().append("setting chunked to ").append(httpChunkStream).toString();(AbstractHttpEntity) reqEntity).setChunked(httpChunkStream);(HttpEntityEnclosingRequest) method).setEntity(reqEntity);HttpHost ta

38、rget = new HttpHost(targetURL.getHost(), targetURL.getPort(), targetURL.getProtocol();httpclient = httpclientbuilder.build();log.debug(new StringBuilder().append("target configured to: ").append(target.toString().append(" and calling it .").toString();CloseableHttpResponse resp =

39、 httpclient.execute(target, method,context);int respCode = resp.getStatusLine().getStatusCode();log.debug(new StringBuilder().append("Called successfully with HTTP code: ").append(respCode).toString();contentType = getHeader(resp, "Content-Type");String contentLocation = getHeade

40、r(resp, "Content-Location");String contentLength = getHeader(resp, "Content-Length");if (respCode <= 199 | respCode >= 300)&& ("text/html".equalsIgnoreCase(contentType)| respCode <= 499 | respCode >= 600) String statusMessage = resp.getStatusLine().g

41、etReasonPhrase();AxisFault fault = new AxisFault("HTTP", (new StringBuilder().append("(").append(respCode).append(")").append(statusMessage).toString(), null, null);fault.setFaultDetailString(Messages.getMessage("return01",(new StringBuilder().append("&qu

42、ot;).append(EntityUtils.toString(resp.getEntity().toString();fault.addFaultDetail(Constants.QNAME_FAULTDETAIL_HTTPERRORCODE,Integer.toString(respCode);throw fault;respBody = resp.getEntity();Header contEnc = respBody.getContentEncoding();if (contEnc != null) HeaderElement elems = contEnc.getElements

43、();HeaderElement arr$ = elems;int len$ = arr$.length;for (int i$ = 0; i$ < len$; i$+) HeaderElement el = arr$i$;if ("gzip".equalsIgnoreCase(el.getName() respBody = new GzipDecompressingEntity(respBody);resp.setEntity(respBody);Header responseHeaders = resp.getAllHeaders();String enc = E

44、ntityUtils.getContentCharSet(respBody);if (enc = null)enc = "iso-8859-1"Message outMsg = null;log.debug(new StringBuilder().append("Content type of response message determined to: ").append(contentType).toString();if (restful) outMsg = new Message(JavaUtils.createXMLInputStream(r

45、espBody.getContent(), enc, "UTF-8", false), false,contentType, contentLocation);outMsg.getSOAPPart().setMimeHeader("Content-Type", contentType);try outMsg.setProperty("javax.xml.soap.character-set-encoding","UTF-8"); catch (SOAPException e) log.debug("Err

46、or while setting message encoding", e); else if (contentLength != null&& "0".equalsIgnoreCase(contentLength)outMsg = new Message(new SOAPEnvelope();elseoutMsg = new Message(respBody.getContent(), false, contentType,contentLocation);outMsg.getSOAPPartAsString();MimeHeaders resp

47、onseMimeHeaders = outMsg.getMimeHeaders();for (int i = 0; i < responseHeaders.length; i+) Header responseHeader = responseHeadersi;responseMimeHeaders.addHeader(responseHeader.getName(),responseHeader.getValue();outMsg.setMessageType("response");msgContext.setResponseMessage(outMsg);if

48、(msgContext.getMaintainSession() Header headers = resp.getAllHeaders();for (int i = 0; i < headers.length; i+) if (headersi.getName().equalsIgnoreCase("Set-Cookie") handleCookie("Cookie", headersi.getValue(),msgContext);continue;if (headersi.getName().equalsIgnoreCase("Se

49、t-Cookie2")handleCookie("Cookie2", headersi.getValue(),msgContext); catch (Exception e) log.debug("Error ", e);throw new AxisFault("Error while invoking HttpClientSender: ", e);if (httpclient != null)try httpclient.close(); catch (IOException e) log.debug("Err

50、or while closing http client: ", e);try httpclient.close(); catch (IOException e) log.debug("Error while closing http client: ", e);public void handleCookie(String cookieName, String acookie,MessageContext msgContext) String ck = acookie.split(",");ArrayList cookies = new Ar

51、rayList();for (int i = 0; i < ck.length; i+) int index = cki.indexOf("");if (index != -1)cki = cki.substring(0, index);index = cki.indexOf("=");String key = index != -1 ? cki.substring(0, index) : cki;Object oldCookies = msgContext.getProperty(cookieName);boolean alreadyExist

52、= false;if (oldCookies != null)if (oldCookies instanceof String) String oldCookiesArray = (String) (String) oldCookies;for (int j = 0; j < oldCookiesArray.length; j+) String anOldCookie = oldCookiesArrayj;if (key != null && anOldCookie.indexOf(key) = 0) anOldCookie = cki;alreadyExist = tr

53、ue;cookies.add(anOldCookie); else String oldCookie = (String) oldCookies;if (key != null && oldCookie.indexOf(key) = 0) oldCookie = cki;alreadyExist = true;cookies.add(oldCookie);if (!alreadyExist)cookies.add(cki);if (cookies.size() = 1)msgContext.setProperty(cookieName, cookies.get(0);else if (cookies.size() > 1)msgContext.setProperty(cookieName, (Object) (cookies.toArray(new Stringcookies.size();private String getHeader(HttpResponse resp, String header) Header h = r

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論