| public InputStream excecute() throws ConfigurationException, HttpException, |
| IOException, HttpConnectionNotOkException { |
| if (url == null) { |
| throw new ConfigurationException("url must be set."); |
| } |
| if (bodyEntity == null) { |
| throw new ConfigurationException("body Entity is not filled"); |
| } |
| HttpClient client = new HttpClient(); |
| initProxyAuth(client, this.proxyAuthConfig); |
| initHostAuth(client, this.hostAuthConfig); |
| |
| PostMethod postMethod = new PostMethod(url); |
| |
| |
| Iterator itKey = httpHeader.keySet().iterator(); |
| while (itKey.hasNext()) { |
| String headerName = itKey.next().toString(); |
| String headerValue = httpHeader.get(headerName).toString(); |
| postMethod.addRequestHeader(headerName, headerValue); |
| } |
| |
| postMethod.setRequestEntity(bodyEntity); |
| |
| |
| int ret = client.executeMethod(postMethod); |
| if (ret != 200) { |
| String retAsString = postMethod.getResponseBodyAsString(); |
| |
| throw new HttpConnectionNotOkException("Return code was: " + ret + "\nmsg=" + retAsString); |
| } |
| |
| InputStream is = postMethod.getResponseBodyAsStream(); |
| return is; |
| |
| } |
| |
| private void initProxyAuth(HttpClient client, ProxyAuthConfig config) { |
| if (config != null) { |
| client.getHostConfiguration().setProxy(config.getHost(), |
| config.getPort()); |
| HttpState state = client.getState(); |
| AuthScope authScope = new AuthScope(config.getHost(), config |
| .getPort(), AuthScope.ANY_REALM); |
| state.setProxyCredentials(authScope, |
| new UsernamePasswordCredentials(config.getUser(), config |
| .getPwd())); |
| client.getParams().setAuthenticationPreemptive(true); |
| |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| private void initHostAuth(HttpClient client, HostAuthConfig config) { |
| if (config != null) { |
| HttpState state = client.getState(); |
| AuthScope authScope = new AuthScope(config.getHost(), config |
| .getPort(), AuthScope.ANY_REALM); |
| state.setCredentials(authScope, new UsernamePasswordCredentials( |
| config.getUser(), config.getPwd())); |
| client.getParams().setAuthenticationPreemptive(true); |
| } |
| |
| } |
| |
| |
| |
| |
| private Object sendSoap(String body) throws HttpException, |
| ConfigurationException, IOException, HttpConnectionNotOkException, |
| JDOMException { |
| Object ret = null; |
| String strMsg = "Module " + agtModule + ", sendSoap():"; |
| |
| InputStream is = null; |
| |
| post = new DoPost(); |
| |
| |
| post.setUrl(SOAPUrlTarget + SOAPUrlParams); |
| post.setProxyAuth(wsProxyAuth); |
| post.setHostAuth(wsHostAuth); |
| |
| |
| post.setBodyEntity(body); |
| |
| post.addHttpHeader("Content-Type", "text/xml; charset=utf-8"); |
| post.addHttpHeader("Accept", |
| "application/soap+xml, application/dime, multipart/related, text/*"); |
| post.addHttpHeader("User-Agent", "Axis/1.4"); |
| post.addHttpHeader("Cache-Control", "no-cache"); |
| post.addHttpHeader("Pragma", "no-cache"); |
| post.addHttpHeader("SOAPAction", |
| "http://sap.com/xi/WebService/soap1.1"); |
| |
| |
| |
| |
| try { |
| |
| is = post.excecute(); |
| |
| SoapSapToBean parser = new SoapSapToBean(); |
| |
| |
| |
| |
| |
| ResponseBean bean = new ResponseBean(); |
| |
| ret = parser.process(is, bean); |
| |
| is.close(); |
| is = null; |
| |
| } finally { |
| |
| |
| |
| |
| if (is != null) { |
| try { |
| is.close(); |
| } catch (java.io.IOException ioe) { |
| |
| SPIErrorHandler.handleError(ioe.toString(), dbCurrent); |
| } |
| } |
| |
| } |
| |
| |
| return ret; |
| |
| } |