/[projects]/miscJava/CircuitBreaker/src/main/java/dk/thoerup/circuitbreaker/invocations/UrlInvocation.java
ViewVC logotype

Annotation of /miscJava/CircuitBreaker/src/main/java/dk/thoerup/circuitbreaker/invocations/UrlInvocation.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 622 - (hide annotations) (download)
Mon Mar 8 09:01:35 2010 UTC (14 years, 2 months ago) by torben
Original Path: CircuitBreaker/src/dk/thoerup/circuitbreaker/invocations/UrlInvocation.java
File size: 969 byte(s)
Use larger chunk for UrlInvocation
1 torben 469 package dk.thoerup.circuitbreaker.invocations;
2    
3     import java.io.ByteArrayOutputStream;
4     import java.io.InputStream;
5     import java.net.URL;
6     import java.net.URLConnection;
7    
8     import dk.thoerup.circuitbreaker.CircuitInvocation;
9    
10     public class UrlInvocation implements CircuitInvocation {
11    
12     private String urlStr;
13     private int timeout;
14    
15     public UrlInvocation(String url) {
16     this(url,1000);
17     }
18    
19     public UrlInvocation(String url, int timeout) {
20     this.urlStr = url;
21     this.timeout = timeout;
22     }
23    
24     public byte[] proceed() throws Exception {
25     URLConnection con = new URL(urlStr).openConnection();
26     con.setConnectTimeout( timeout );
27     InputStream is = con.getInputStream();
28     ByteArrayOutputStream os = new ByteArrayOutputStream();
29 torben 622 byte[] message = new byte[8192];
30 torben 469 int readBytes = 0;;
31     while ((readBytes = is.read(message)) != -1) {
32     os.write(message, 0, readBytes);
33     }
34     is.close();
35     os.close();
36     return os.toByteArray();
37     }
38    
39     }

  ViewVC Help
Powered by ViewVC 1.1.20