aboutsummaryrefslogtreecommitdiffstats
path: root/wso2bpel-ext/wso2bpel-core/wso2bpel-mgr/src/main/java/org/openo/carbon/bpel/util/ClientWsdlLoader.java
blob: 70a95881d858a929888540988b07e6931467756d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
 * Copyright 2016 ZTE Corporation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.openo.carbon.bpel.util;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URL;
import org.apache.log4j.Logger;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;

import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlLoader;

public class ClientWsdlLoader extends WsdlLoader {
  private static Logger logger = Logger.getLogger(ClientWsdlLoader.class);

  private boolean isAborted = false;
  private HttpClient httpClient;

  public ClientWsdlLoader(String url, HttpClient httpClient) {
    super(url);
    this.httpClient = httpClient;
  }

  public InputStream load(String url) throws Exception {
    GetMethod httpGetMethod;

    if (url.startsWith("file")) {
      return new URL(url).openStream();
    }

    // Authentication is not being overridden on the method. It needs
    // to be present on the supplied HttpClient instance!
    httpGetMethod = new GetMethod(url);
    httpGetMethod.setDoAuthentication(true);

    try {
      int result = httpClient.executeMethod(httpGetMethod);

      if (result != HttpStatus.SC_OK) {
        if (result < 200 || result > 299) {
          throw new HttpException(
              "Received status code '" + result + "' on WSDL HTTP (GET) request: '" + url + "'.");
        } else {
          logger.warn(
              "Received status code '" + result + "' on WSDL HTTP (GET) request: '" + url + "'.");
        }
      }

      return new ByteArrayInputStream(httpGetMethod.getResponseBody());
    } finally {
      httpGetMethod.releaseConnection();
    }
  }

  public boolean abort() {
    isAborted = true;
    return true;
  }

  public boolean isAborted() {
    return isAborted;
  }

  public void close() {}
}