Subversion Repositories XServices

Rev

Rev 49 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 49 Rev 54
Line 14... Line 14...
14
 *   limitations under the License.
14
 *   limitations under the License.
15
 */
15
 */
16
package net.brutex.xservices.ws.impl;
16
package net.brutex.xservices.ws.impl;
Line 17... Line 17...
17
 
17
 
-
 
18
import java.io.File;
-
 
19
import java.io.FileInputStream;
-
 
20
import java.io.FileNotFoundException;
-
 
21
import java.io.FileOutputStream;
-
 
22
import java.io.IOException;
-
 
23
import java.io.InputStream;
-
 
24
import java.io.UnsupportedEncodingException;
-
 
25
import java.util.List;
-
 
26
 
18
import java.io.File;
27
import javax.activation.DataHandler;
19
import javax.jws.WebMethod;
28
import javax.jws.WebMethod;
20
import javax.jws.WebParam;
29
import javax.jws.WebParam;
-
 
30
import javax.jws.WebService;
-
 
31
 
21
import javax.jws.WebService;
32
import net.brutex.xservices.types.AntProperty;
-
 
33
import net.brutex.xservices.types.ArchiveResource;
22
import net.brutex.xservices.types.ArchiveResource;
34
import net.brutex.xservices.types.AttachmentType;
23
import net.brutex.xservices.types.FileResource;
35
import net.brutex.xservices.types.FileResource;
24
import net.brutex.xservices.types.FileSetResource;
36
import net.brutex.xservices.types.FileSetResource;
25
import net.brutex.xservices.types.ResourceInterface;
37
import net.brutex.xservices.types.ResourceInterface;
26
import net.brutex.xservices.types.ReturnCode;
38
import net.brutex.xservices.types.ReturnCode;
27
import net.brutex.xservices.util.BrutexNamespaces;
39
import net.brutex.xservices.util.BrutexNamespaces;
28
import net.brutex.xservices.util.RunTask;
40
import net.brutex.xservices.util.RunTask;
29
import net.brutex.xservices.ws.FileService;
41
import net.brutex.xservices.ws.FileService;
Line -... Line 42...
-
 
42
import net.brutex.xservices.ws.XServicesFault;
-
 
43
 
-
 
44
import org.apache.commons.codec.binary.Base64;
-
 
45
import org.apache.commons.codec.binary.Base64InputStream;
30
import net.brutex.xservices.ws.XServicesFault;
46
import org.apache.cxf.aegis.type.mtom.StreamDataSource;
31
 
47
import org.apache.tools.ant.BuildException;
32
import org.apache.tools.ant.taskdefs.Basename;
48
import org.apache.tools.ant.taskdefs.Basename;
33
import org.apache.tools.ant.taskdefs.Chmod;
49
import org.apache.tools.ant.taskdefs.Chmod;
34
import org.apache.tools.ant.taskdefs.Copy;
50
import org.apache.tools.ant.taskdefs.Copy;
Line 40... Line 56...
40
 
56
 
41
/**
57
/**
42
 *
58
 * 
43
 * @author Brian Rosenberger, bru@brutex.de
59
 * @author Brian Rosenberger, bru@brutex.de
44
 */
-
 
45
@WebService(
-
 
46
		targetNamespace = BrutexNamespaces.WS_XSERVICES, 
60
 */
47
		endpointInterface ="net.brutex.xservices.ws.FileService", 
-
 
48
		serviceName = "FileService"
-
 
49
			)
61
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.FileService", serviceName = "FileService")
Line -... Line 62...
-
 
62
public class FileServiceImpl implements FileService {
50
public class FileServiceImpl implements FileService {
63
 
-
 
64
	/*
51
 
65
	 * (non-Javadoc)
-
 
66
	 * 
52
    /* (non-Javadoc)
67
	 * @see net.brutex.xservices.ws.impl.FileService#basename(java.lang.String,
53
	 * @see net.brutex.xservices.ws.impl.FileService#basename(java.lang.String, java.lang.String)
68
	 * java.lang.String)
54
	 */
69
	 */
55
    @Override
70
	@Override
56
	@WebMethod(operationName = "basename")
71
	@WebMethod(operationName = "basename")
57
    public ReturnCode basename(@WebParam(name = "file") String filename,
72
	public ReturnCode basename(@WebParam(name = "file") String filename,
58
            @WebParam(name = "suffix") String suffix) {
73
			@WebParam(name = "suffix") String suffix) {
Line -... Line 74...
-
 
74
		return basename(new File(filename), suffix);
-
 
75
	}
-
 
76
 
-
 
77
	/*
-
 
78
	 * (non-Javadoc)
-
 
79
	 * 
-
 
80
	 * @see
-
 
81
	 * net.brutex.xservices.ws.impl.FileService#base64Encode(net.brutex.xservices
-
 
82
	 * .types.FileSetResource)
-
 
83
	 */
-
 
84
	@Override
-
 
85
	@WebMethod(operationName = "downloadFile")
-
 
86
	public AttachmentType downloadFile(@WebParam(name = "file") FileResource res) {
-
 
87
		InputStream is = null;
-
 
88
		try {
-
 
89
			is = res.getAntResource(null).getInputStream();
-
 
90
		} catch (IOException e) {
-
 
91
			// TODO Auto-generated catch block
-
 
92
			e.printStackTrace();
-
 
93
		}
-
 
94
		DataHandler h = new DataHandler(new StreamDataSource(
-
 
95
				"application/binary", is));
-
 
96
		AttachmentType t = new AttachmentType();
-
 
97
		t.setContent(h);
-
 
98
		return t;
-
 
99
	}
-
 
100
 
-
 
101
	/*
-
 
102
	 * (non-Javadoc)
-
 
103
	 * 
-
 
104
	 * @see
-
 
105
	 * net.brutex.xservices.ws.impl.FileService#base64Decode(net.brutex.xservices
-
 
106
	 * .types.AttachmentType)
-
 
107
	 */
-
 
108
	@Override
-
 
109
	@WebMethod(operationName = "uploadFile")
-
 
110
	public String uploadFile(@WebParam(name = "file") AttachmentType file) {
-
 
111
		DataHandler h =  file.getContent();
-
 
112
		File f = new File(file.getFilename());
-
 
113
		FileOutputStream fout;
-
 
114
		try {
-
 
115
			fout = new FileOutputStream(f);
-
 
116
			/*
-
 
117
			 * InputStream in = h.getInputStream();
-
 
118
			int b;
-
 
119
			while( (b=in.read())!= -1 ) {
-
 
120
				fout.write(b);
-
 
121
			}
-
 
122
			*/
-
 
123
			h.writeTo(fout);
-
 
124
			fout.flush();
-
 
125
			fout.close();
-
 
126
			//in.close();
-
 
127
		} catch (FileNotFoundException e) {
-
 
128
			throw new BuildException(e);
-
 
129
		} catch (IOException e) {
-
 
130
			throw new BuildException(e);
-
 
131
		}
-
 
132
		return file.getFilename();
59
        return basename(new File(filename), suffix);
133
	}
-
 
134
 
-
 
135
	/*
60
    }
136
	 * (non-Javadoc)
-
 
137
	 * 
61
 
138
	 * @see
62
    /* (non-Javadoc)
139
	 * net.brutex.xservices.ws.impl.FileService#copy(net.brutex.xservices.types
63
	 * @see net.brutex.xservices.ws.impl.FileService#copy(net.brutex.xservices.types.FileSetResource, java.lang.String, boolean, boolean, java.lang.String)
140
	 * .FileSetResource, java.lang.String, boolean, boolean, java.lang.String)
64
	 */
141
	 */
65
    @Override
142
	@Override
66
	@WebMethod(operationName = "copy")
143
	@WebMethod(operationName = "copy")
67
    public ReturnCode copy(@WebParam(name = "fileset") FileSetResource src,
144
	public ReturnCode copy(@WebParam(name = "fileset") FileSetResource src,
68
            @WebParam(name = "todir") String todir,
145
			@WebParam(name = "todir") String todir,
69
            @WebParam(name = "preservelastmodified") boolean plm,
-
 
70
            @WebParam(name = "overwrite") boolean overwrite,
146
			@WebParam(name = "preservelastmodified") boolean plm,
71
            @WebParam(name = "encoding") String encoding)
147
			@WebParam(name = "overwrite") boolean overwrite,
Line -... Line 148...
-
 
148
			@WebParam(name = "encoding") String encoding) throws XServicesFault {
72
            throws XServicesFault {
149
		return copy(src, new File(todir), plm, overwrite, encoding);
-
 
150
	}
-
 
151
 
73
        return copy(src, new File(todir), plm, overwrite, encoding);
152
	/*
-
 
153
	 * (non-Javadoc)
74
    }
154
	 * 
75
 
155
	 * @see
76
    /* (non-Javadoc)
156
	 * net.brutex.xservices.ws.impl.FileService#loadRes(net.brutex.xservices
77
	 * @see net.brutex.xservices.ws.impl.FileService#loadRes(net.brutex.xservices.types.FileResource, java.lang.String)
157
	 * .types.FileResource, java.lang.String)
78
	 */
158
	 */
Line 84... Line 164...
84
            encoding = System.getProperty("file.encoding");
164
			encoding = System.getProperty("file.encoding");
85
        }
165
		}
86
        return loadResource(res, encoding);
166
		return loadResource(res, encoding);
87
    }
167
	}
Line -... Line 168...
-
 
168
 
88
 
169
	/*
-
 
170
	 * (non-Javadoc)
-
 
171
	 * 
89
    /* (non-Javadoc)
172
	 * @see
-
 
173
	 * net.brutex.xservices.ws.impl.FileService#loadResFromArchive(net.brutex
90
	 * @see net.brutex.xservices.ws.impl.FileService#loadResFromArchive(net.brutex.xservices.types.ArchiveResource, java.lang.String)
174
	 * .xservices.types.ArchiveResource, java.lang.String)
91
	 */
175
	 */
92
    @Override
176
	@Override
-
 
177
	@WebMethod(operationName = "loadResourceFromArchive")
93
	@WebMethod(operationName = "loadResourceFromArchive")
178
	public ReturnCode loadResFromArchive(
94
    public ReturnCode loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
179
			@WebParam(name = "archiveresource") ArchiveResource res,
95
            @WebParam(name = "encoding") String encoding) {
180
			@WebParam(name = "encoding") String encoding) {
96
        if (encoding == null || encoding.equals("")) {
181
		if (encoding == null || encoding.equals("")) {
97
            encoding = System.getProperty("file.encoding");
182
			encoding = System.getProperty("file.encoding");
98
        }
183
		}
99
        return loadResource(res, encoding);
184
		return loadResource(res, encoding);
Line -... Line 185...
-
 
185
	}
100
    }
186
 
-
 
187
	/*
101
 
188
	 * (non-Javadoc)
-
 
189
	 * 
102
    /* (non-Javadoc)
190
	 * @see net.brutex.xservices.ws.impl.FileService#echo2file(java.lang.String,
103
	 * @see net.brutex.xservices.ws.impl.FileService#echo2file(java.lang.String, java.lang.String, java.lang.String, boolean)
191
	 * java.lang.String, java.lang.String, boolean)
104
	 */
192
	 */
105
    @Override
193
	@Override
-
 
194
	@WebMethod(operationName = "echoToFile")
106
	@WebMethod(operationName = "echoToFile")
195
	public ReturnCode echo2file(@WebParam(name = "message") String message,
107
    public ReturnCode echo2file(@WebParam(name = "message") String message,
196
			@WebParam(name = "file") String file,
108
            @WebParam(name = "file") String file, @WebParam(name = "encoding") String encoding,
197
			@WebParam(name = "encoding") String encoding,
109
            @WebParam(name = "append") boolean append) {
198
			@WebParam(name = "append") boolean append) {
Line -... Line 199...
-
 
199
		return echo(message, new File(file), encoding, append);
110
        return echo(message, new File(file), encoding, append);
200
	}
-
 
201
 
-
 
202
	/*
111
    }
203
	 * (non-Javadoc)
-
 
204
	 * 
112
 
205
	 * @see
113
    /* (non-Javadoc)
206
	 * net.brutex.xservices.ws.impl.FileService#changeOwner(net.brutex.xservices
114
	 * @see net.brutex.xservices.ws.impl.FileService#changeOwner(net.brutex.xservices.types.FileSetResource, java.lang.String)
207
	 * .types.FileSetResource, java.lang.String)
-
 
208
	 */
115
	 */
209
	@Override
116
    @Override
210
	@WebMethod(operationName = "changeOwner")
117
	@WebMethod(operationName = "changeOwner")
211
	public ReturnCode changeOwner(
118
    public ReturnCode changeOwner(@WebParam(name = "fileset") FileSetResource res,
212
			@WebParam(name = "fileset") FileSetResource res,
Line -... Line 213...
-
 
213
			@WebParam(name = "owner") String owner) {
119
            @WebParam(name = "owner") String owner) {
214
		return chown(res, owner);
-
 
215
	}
-
 
216
 
120
        return chown(res, owner);
217
	/*
-
 
218
	 * (non-Javadoc)
121
    }
219
	 * 
122
 
220
	 * @see
123
    /* (non-Javadoc)
221
	 * net.brutex.xservices.ws.impl.FileService#changeGroup(net.brutex.xservices
-
 
222
	 * .types.FileSetResource, java.lang.String)
124
	 * @see net.brutex.xservices.ws.impl.FileService#changeGroup(net.brutex.xservices.types.FileSetResource, java.lang.String)
223
	 */
125
	 */
224
	@Override
126
    @Override
225
	@WebMethod(operationName = "changeGroup")
127
	@WebMethod(operationName = "changeGroup")
226
	public ReturnCode changeGroup(
Line -... Line 227...
-
 
227
			@WebParam(name = "fileset") FileSetResource res,
128
    public ReturnCode changeGroup(@WebParam(name = "fileset") FileSetResource res,
228
			@WebParam(name = "group") String group) {
-
 
229
		return chgrp(res, group);
-
 
230
	}
129
            @WebParam(name = "group") String group) {
231
 
-
 
232
	/*
130
        return chgrp(res, group);
233
	 * (non-Javadoc)
131
    }
234
	 * 
132
 
235
	 * @see
-
 
236
	 * net.brutex.xservices.ws.impl.FileService#changeMode(net.brutex.xservices
133
    /* (non-Javadoc)
237
	 * .types.FileSetResource, java.lang.String)
134
	 * @see net.brutex.xservices.ws.impl.FileService#changeMode(net.brutex.xservices.types.FileSetResource, java.lang.String)
238
	 */
135
	 */
239
	@Override
136
    @Override
240
	@WebMethod(operationName = "changeMode")
Line 137... Line 241...
137
	@WebMethod(operationName = "changeMode")
241
	public ReturnCode changeMode(
138
    public ReturnCode changeMode(@WebParam(name="fileset") FileSetResource res,
242
			@WebParam(name = "fileset") FileSetResource res,
139
            @WebParam(name="permissions") String perm) {
-
 
140
        return chmod(res, perm);
243
			@WebParam(name = "permissions") String perm) {
141
    }
244
		return chmod(res, perm);
142
 
245
	}
143
    @WebMethod(exclude = true)
246
 
144
    private ReturnCode basename(File file,
247
	@WebMethod(exclude = true)
Line 164... Line 267...
164
        lr.setProperty("LoadResource.out");
267
		lr.setProperty("LoadResource.out");
165
        return runner.postTask();
268
		return runner.postTask();
166
    }
269
	}
Line 167... Line 270...
167
 
270
 
168
    @WebMethod(exclude = true)
271
	@WebMethod(exclude = true)
-
 
272
	private ReturnCode echo(String msg, File file, String encoding,
169
    private ReturnCode echo(String msg, File file, String encoding, boolean append) {
273
			boolean append) {
170
        Echo echo = new Echo();
274
		Echo echo = new Echo();
171
        echo.setTaskName("toFile");
275
		echo.setTaskName("toFile");
172
        RunTask runTask = new RunTask(echo);
276
		RunTask runTask = new RunTask(echo);
173
        echo.addText(msg);
277
		echo.addText(msg);
Line 176... Line 280...
176
        echo.setAppend(append);
280
		echo.setAppend(append);
177
        return runTask.postTask();
281
		return runTask.postTask();
178
    }
282
	}
Line 179... Line 283...
179
 
283
 
180
    @WebMethod(exclude = true)
284
	@WebMethod(exclude = true)
181
    private ReturnCode copy(FileSetResource src, File dst, boolean preservelastmodified,
285
	private ReturnCode copy(FileSetResource src, File dst,
182
            boolean overwrite, String encoding) {
286
			boolean preservelastmodified, boolean overwrite, String encoding) {
183
        Copy copy = new Copy();
287
		Copy copy = new Copy();
184
        copy.setTaskName("Copy");
288
		copy.setTaskName("Copy");
185
        RunTask runner = new RunTask(copy);
289
		RunTask runner = new RunTask(copy);
186
        FileSet set = src.getAntFileSet(copy.getProject());
290
		FileSet set = src.getAntResource(copy.getProject());
Line 187... Line 291...
187
        copy.add(set);
291
		copy.add(set);
188
 
292
 
189
        if (dst.isDirectory()) {
293
		if (dst.isDirectory()) {
Line 207... Line 311...
207
    private ReturnCode chown(FileSetResource src, String owner) {
311
	private ReturnCode chown(FileSetResource src, String owner) {
208
        Chown chown = new Chown();
312
		Chown chown = new Chown();
209
        chown.setTaskName("Chown");
313
		chown.setTaskName("Chown");
210
        RunTask runner = new RunTask(chown);
314
		RunTask runner = new RunTask(chown);
211
        chown.setOwner(owner);
315
		chown.setOwner(owner);
212
        FileSet set = src.getAntFileSet(chown.getProject());
316
		FileSet set = src.getAntResource(chown.getProject());
213
        chown.add(set);
317
		chown.add(set);
214
        chown.setMaxParallel(300);
318
		chown.setMaxParallel(300);
215
        return runner.postTask();
319
		return runner.postTask();
216
    }
320
	}
Line 219... Line 323...
219
    private ReturnCode chgrp(FileSetResource src, String group) {
323
	private ReturnCode chgrp(FileSetResource src, String group) {
220
        Chgrp chgrp = new Chgrp();
324
		Chgrp chgrp = new Chgrp();
221
        chgrp.setTaskName("Chgrp");
325
		chgrp.setTaskName("Chgrp");
222
        RunTask runner = new RunTask(chgrp);
326
		RunTask runner = new RunTask(chgrp);
223
        chgrp.setGroup(group);
327
		chgrp.setGroup(group);
224
        FileSet set = src.getAntFileSet(chgrp.getProject());
328
		FileSet set = src.getAntResource(chgrp.getProject());
225
        chgrp.add(set);
329
		chgrp.add(set);
226
        chgrp.setMaxParallel(300);
330
		chgrp.setMaxParallel(300);
227
        return runner.postTask();
331
		return runner.postTask();
228
    }
332
	}
Line 229... Line 333...
229
 
333
 
230
    @WebMethod(exclude = true)
334
	@WebMethod(exclude = true)
231
    private ReturnCode chmod(FileSetResource src, String perm) {
335
	private ReturnCode chmod(FileSetResource src, String perm) {
232
        Chmod chmod = new Chmod();
336
		Chmod chmod = new Chmod();
233
        chmod.setTaskName("Chmod");
337
		chmod.setTaskName("Chmod");
234
        RunTask runner = new RunTask(chmod);
338
		RunTask runner = new RunTask(chmod);
235
        FileSet set = src.getAntFileSet(chmod.getProject());
339
		FileSet set = src.getAntResource(chmod.getProject());
236
        chmod.add(set);
340
		chmod.add(set);
237
        chmod.setMaxParallel(300);
341
		chmod.setMaxParallel(300);
238
        chmod.setPerm(perm);
342
		chmod.setPerm(perm);
239
        chmod.setVerbose(true);
343
		chmod.setVerbose(true);