1 | |
package org.apache.maven.wagon.providers.http; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.IOException; |
23 | |
import java.io.InputStream; |
24 | |
import java.util.List; |
25 | |
|
26 | |
import org.apache.commons.httpclient.HttpStatus; |
27 | |
import org.apache.commons.httpclient.methods.GetMethod; |
28 | |
import org.apache.maven.wagon.ResourceDoesNotExistException; |
29 | |
import org.apache.maven.wagon.TransferFailedException; |
30 | |
import org.apache.maven.wagon.authorization.AuthorizationException; |
31 | |
import org.apache.maven.wagon.shared.http.AbstractHttpClientWagon; |
32 | |
import org.apache.maven.wagon.shared.http.HtmlFileListParser; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 116 | public class HttpWagon |
39 | |
extends AbstractHttpClientWagon |
40 | |
{ |
41 | |
public List getFileList( String destinationDirectory ) |
42 | |
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException |
43 | |
{ |
44 | 7 | if ( destinationDirectory.length() > 0 && !destinationDirectory.endsWith( "/" ) ) |
45 | |
{ |
46 | 5 | destinationDirectory += "/"; |
47 | |
} |
48 | |
|
49 | 7 | String url = getRepository().getUrl() + "/" + destinationDirectory; |
50 | |
|
51 | 7 | GetMethod getMethod = new GetMethod( url ); |
52 | |
|
53 | |
try |
54 | |
{ |
55 | 7 | int statusCode = execute( getMethod ); |
56 | |
|
57 | 6 | fireTransferDebug( url + " - Status code: " + statusCode ); |
58 | |
|
59 | |
|
60 | 6 | switch ( statusCode ) |
61 | |
{ |
62 | |
case HttpStatus.SC_OK: |
63 | 4 | break; |
64 | |
|
65 | |
case SC_NULL: |
66 | 0 | throw new TransferFailedException( "Failed to transfer file: " ); |
67 | |
|
68 | |
case HttpStatus.SC_FORBIDDEN: |
69 | 0 | throw new AuthorizationException( "Access denied to: " + url ); |
70 | |
|
71 | |
case HttpStatus.SC_UNAUTHORIZED: |
72 | 0 | throw new AuthorizationException( "Not authorized." ); |
73 | |
|
74 | |
case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED: |
75 | 0 | throw new AuthorizationException( "Not authorized by proxy." ); |
76 | |
|
77 | |
case HttpStatus.SC_NOT_FOUND: |
78 | 2 | throw new ResourceDoesNotExistException( "File: " + url + " does not exist" ); |
79 | |
|
80 | |
|
81 | |
default : |
82 | 0 | throw new TransferFailedException( |
83 | |
"Failed to transfer file: " + url + ". Return code is: " + statusCode ); |
84 | |
} |
85 | |
|
86 | 4 | InputStream is = null; |
87 | |
|
88 | 4 | is = getMethod.getResponseBodyAsStream(); |
89 | |
|
90 | 4 | return HtmlFileListParser.parseFileList( url, is ); |
91 | |
} |
92 | 1 | catch ( IOException e ) |
93 | |
{ |
94 | 1 | throw new TransferFailedException( "Could not read response body.", e ); |
95 | |
} |
96 | |
finally |
97 | |
{ |
98 | 7 | getMethod.releaseConnection(); |
99 | |
} |
100 | |
} |
101 | |
} |