Subversion Repositories XServices

Rev

Rev 49 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 49 Rev 54
1
/*
1
/*
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
3
 *
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
6
 *   You may obtain a copy of the License at
7
 *
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
13
 *   See the License for the specific language governing permissions and
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;
17
 
17
 
18
import java.io.File;
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
 
-
 
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;
21
import javax.jws.WebService;
30
import javax.jws.WebService;
-
 
31
 
-
 
32
import net.brutex.xservices.types.AntProperty;
22
import net.brutex.xservices.types.ArchiveResource;
33
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;
30
import net.brutex.xservices.ws.XServicesFault;
42
import net.brutex.xservices.ws.XServicesFault;
-
 
43
 
-
 
44
import org.apache.commons.codec.binary.Base64;
-
 
45
import org.apache.commons.codec.binary.Base64InputStream;
-
 
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;
35
import org.apache.tools.ant.taskdefs.Echo;
51
import org.apache.tools.ant.taskdefs.Echo;
36
import org.apache.tools.ant.taskdefs.LoadResource;
52
import org.apache.tools.ant.taskdefs.LoadResource;
37
import org.apache.tools.ant.taskdefs.optional.unix.Chgrp;
53
import org.apache.tools.ant.taskdefs.optional.unix.Chgrp;
38
import org.apache.tools.ant.taskdefs.optional.unix.Chown;
54
import org.apache.tools.ant.taskdefs.optional.unix.Chown;
39
import org.apache.tools.ant.types.FileSet;
55
import org.apache.tools.ant.types.FileSet;
40
 
56
 
41
/**
57
/**
42
 *
58
 * 
43
 * @author Brian Rosenberger, bru@brutex.de
59
 * @author Brian Rosenberger, bru@brutex.de
44
 */
60
 */
45
@WebService(
-
 
46
		targetNamespace = BrutexNamespaces.WS_XSERVICES, 
-
 
47
		endpointInterface ="net.brutex.xservices.ws.FileService", 
61
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.FileService", serviceName = "FileService")
48
		serviceName = "FileService"
-
 
49
			)
-
 
50
public class FileServiceImpl implements FileService {
62
public class FileServiceImpl implements FileService {
-
 
63
 
51
 
64
	/*
-
 
65
	 * (non-Javadoc)
52
    /* (non-Javadoc)
66
	 * 
-
 
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) {
59
        return basename(new File(filename), suffix);
74
		return basename(new File(filename), suffix);
60
    }
75
	}
-
 
76
 
61
 
77
	/*
-
 
78
	 * (non-Javadoc)
-
 
79
	 * 
62
    /* (non-Javadoc)
80
	 * @see
-
 
81
	 * net.brutex.xservices.ws.impl.FileService#base64Encode(net.brutex.xservices
63
	 * @see net.brutex.xservices.ws.impl.FileService#copy(net.brutex.xservices.types.FileSetResource, java.lang.String, boolean, boolean, java.lang.String)
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();
-
 
133
	}
-
 
134
 
-
 
135
	/*
-
 
136
	 * (non-Javadoc)
-
 
137
	 * 
-
 
138
	 * @see
-
 
139
	 * net.brutex.xservices.ws.impl.FileService#copy(net.brutex.xservices.types
-
 
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,
146
			@WebParam(name = "preservelastmodified") boolean plm,
70
            @WebParam(name = "overwrite") boolean overwrite,
147
			@WebParam(name = "overwrite") boolean overwrite,
71
            @WebParam(name = "encoding") String encoding)
-
 
72
            throws XServicesFault {
148
			@WebParam(name = "encoding") String encoding) throws XServicesFault {
73
        return copy(src, new File(todir), plm, overwrite, encoding);
149
		return copy(src, new File(todir), plm, overwrite, encoding);
74
    }
150
	}
-
 
151
 
75
 
152
	/*
-
 
153
	 * (non-Javadoc)
-
 
154
	 * 
76
    /* (non-Javadoc)
155
	 * @see
-
 
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
	 */
79
    @Override
159
	@Override
80
	@WebMethod(operationName = "loadResource")
160
	@WebMethod(operationName = "loadResource")
81
    public ReturnCode loadRes(@WebParam(name = "resource") FileResource res,
161
	public ReturnCode loadRes(@WebParam(name = "resource") FileResource res,
82
            @WebParam(name = "encoding") String encoding) {
162
			@WebParam(name = "encoding") String encoding) {
83
        if (encoding == null || encoding.equals("")) {
163
		if (encoding == null || encoding.equals("")) {
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
	}
-
 
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);
100
    }
185
	}
-
 
186
 
101
 
187
	/*
-
 
188
	 * (non-Javadoc)
102
    /* (non-Javadoc)
189
	 * 
-
 
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
106
	@WebMethod(operationName = "echoToFile")
194
	@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) {
110
        return echo(message, new File(file), encoding, append);
199
		return echo(message, new File(file), encoding, append);
111
    }
200
	}
-
 
201
 
112
 
202
	/*
-
 
203
	 * (non-Javadoc)
-
 
204
	 * 
113
    /* (non-Javadoc)
205
	 * @see
-
 
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)
115
	 */
208
	 */
116
    @Override
209
	@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,
119
            @WebParam(name = "owner") String owner) {
213
			@WebParam(name = "owner") String owner) {
120
        return chown(res, owner);
214
		return chown(res, owner);
121
    }
215
	}
-
 
216
 
122
 
217
	/*
-
 
218
	 * (non-Javadoc)
-
 
219
	 * 
123
    /* (non-Javadoc)
220
	 * @see
-
 
221
	 * net.brutex.xservices.ws.impl.FileService#changeGroup(net.brutex.xservices
124
	 * @see net.brutex.xservices.ws.impl.FileService#changeGroup(net.brutex.xservices.types.FileSetResource, java.lang.String)
222
	 * .types.FileSetResource, java.lang.String)
125
	 */
223
	 */
126
    @Override
224
	@Override
-
 
225
	@WebMethod(operationName = "changeGroup")
127
	@WebMethod(operationName = "changeGroup")
226
	public ReturnCode changeGroup(
128
    public ReturnCode changeGroup(@WebParam(name = "fileset") FileSetResource res,
227
			@WebParam(name = "fileset") FileSetResource res,
129
            @WebParam(name = "group") String group) {
228
			@WebParam(name = "group") String group) {
130
        return chgrp(res, group);
229
		return chgrp(res, group);
131
    }
230
	}
-
 
231
 
132
 
232
	/*
-
 
233
	 * (non-Javadoc)
-
 
234
	 * 
133
    /* (non-Javadoc)
235
	 * @see
-
 
236
	 * net.brutex.xservices.ws.impl.FileService#changeMode(net.brutex.xservices
134
	 * @see net.brutex.xservices.ws.impl.FileService#changeMode(net.brutex.xservices.types.FileSetResource, java.lang.String)
237
	 * .types.FileSetResource, java.lang.String)
135
	 */
238
	 */
136
    @Override
239
	@Override
241
    }
345
	}
242
 
346
 
243
}
347
}