2 * Copyright 2016 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.openo.carbon.bpel.util;
18 import java.io.ByteArrayInputStream;
19 import java.io.InputStream;
21 import org.apache.log4j.Logger;
23 import org.apache.commons.httpclient.HttpClient;
24 import org.apache.commons.httpclient.HttpException;
25 import org.apache.commons.httpclient.HttpStatus;
26 import org.apache.commons.httpclient.methods.GetMethod;
28 import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlLoader;
30 public class ClientWsdlLoader extends WsdlLoader {
31 private static Logger logger = Logger.getLogger(ClientWsdlLoader.class);
33 private boolean isAborted = false;
34 private HttpClient httpClient;
36 public ClientWsdlLoader(String url, HttpClient httpClient) {
38 this.httpClient = httpClient;
41 public InputStream load(String url) throws Exception {
42 GetMethod httpGetMethod;
44 if (url.startsWith("file")) {
45 return new URL(url).openStream();
48 // Authentication is not being overridden on the method. It needs
49 // to be present on the supplied HttpClient instance!
50 httpGetMethod = new GetMethod(url);
51 httpGetMethod.setDoAuthentication(true);
54 int result = httpClient.executeMethod(httpGetMethod);
56 if (result != HttpStatus.SC_OK) {
57 if (result < 200 || result > 299) {
58 throw new HttpException(
59 "Received status code '" + result + "' on WSDL HTTP (GET) request: '" + url + "'.");
62 "Received status code '" + result + "' on WSDL HTTP (GET) request: '" + url + "'.");
66 return new ByteArrayInputStream(httpGetMethod.getResponseBody());
68 httpGetMethod.releaseConnection();
72 public boolean abort() {
77 public boolean isAborted() {
81 public void close() {}