1 | /*
|
---|
2 | * MyGetUserAndPassword.java
|
---|
3 | * Copyright (C) 2005 New Zealand Digital Library, http://www.nzdl.org
|
---|
4 | *
|
---|
5 | * This program is free software; you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program; if not, write to the Free Software
|
---|
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
18 | */
|
---|
19 | package org.greenstone.anttasks;
|
---|
20 |
|
---|
21 | import java.net.Authenticator;
|
---|
22 | import java.net.PasswordAuthentication;
|
---|
23 |
|
---|
24 | /** A new ant task for as the setproxy task has a bug in it.
|
---|
25 | * To use this task, the compiled class must be put in the classpath. add a taskdef line to the build.xml:
|
---|
26 | * <taskdef name="mysetproxy" classname="MySetProxy" />
|
---|
27 | * and call it like the following:
|
---|
28 | * <mysetproxy proxyhost="" proxyport="" proxyuser="" proxypassword=""/>
|
---|
29 | */
|
---|
30 | public class MySetProxy
|
---|
31 | extends org.apache.tools.ant.Task {
|
---|
32 |
|
---|
33 | String host = null;
|
---|
34 | String port = null;
|
---|
35 | String user = null;
|
---|
36 | String password = null;
|
---|
37 |
|
---|
38 | public void setProxyhost(String proxy_host) {
|
---|
39 | host = proxy_host;
|
---|
40 | }
|
---|
41 |
|
---|
42 | public void setProxyPort(int proxy_port) {
|
---|
43 | port = Integer.toString(proxy_port);
|
---|
44 | }
|
---|
45 |
|
---|
46 | public void setProxyuser(String proxy_user) {
|
---|
47 | user = proxy_user;
|
---|
48 | }
|
---|
49 |
|
---|
50 | public void setProxypassword(String proxy_password) {
|
---|
51 | password = proxy_password;
|
---|
52 | }
|
---|
53 |
|
---|
54 | public void execute() {
|
---|
55 |
|
---|
56 | try {
|
---|
57 | System.setProperty("http.proxyType", "4");
|
---|
58 | System.setProperty("http.proxyHost", host);
|
---|
59 | System.setProperty("http.proxyPort", port);
|
---|
60 | System.setProperty("http.proxySet", "true");
|
---|
61 | Authenticator.setDefault(new Authenticator(){
|
---|
62 | protected PasswordAuthentication getPasswordAuthentication(){
|
---|
63 | return new PasswordAuthentication(user, new String(password).toCharArray());
|
---|
64 | }
|
---|
65 | });
|
---|
66 | } catch (Exception e) {
|
---|
67 | System.err.println("MySetProxy Error: couldn't set up the proxy");
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|