Revision 21a76038 src/gr/ebs/gss/server/webdav/milton/GssOthersResource.java

b/src/gr/ebs/gss/server/webdav/milton/GssOthersResource.java
18 18
 */
19 19
package gr.ebs.gss.server.webdav.milton;
20 20

  
21
import static gr.ebs.gss.server.configuration.GSSConfigurationFactory.getConfiguration;
21 22
import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
22 23
import gr.ebs.gss.client.exceptions.RpcException;
23 24
import gr.ebs.gss.server.domain.User;
25
import gr.ebs.gss.server.ejb.ExternalAPI;
24 26

  
25 27
import java.io.IOException;
26 28
import java.io.OutputStream;
......
29 31
import java.util.List;
30 32
import java.util.Map;
31 33

  
34
import javax.naming.Context;
35
import javax.naming.InitialContext;
36
import javax.naming.NamingException;
37
import javax.rmi.PortableRemoteObject;
38

  
32 39
import org.slf4j.Logger;
33 40
import org.slf4j.LoggerFactory;
34 41

  
......
159 166
		List<GssOtherUserResource> result = new ArrayList<GssOtherUserResource>();
160 167
		List<User> users;
161 168
		try {
162
			users = factory.getService().getUsersSharingFoldersForUser(getCurrentUser().getId());
169
			users = getService().getUsersSharingFoldersForUser(getCurrentUser().getId());
163 170
			log.info("USERS:"+users);
164 171
			for(User u : users){
165 172
				result.add(new GssOtherUserResource(host, factory, u));
......
188 195
    	if(username!=null){
189 196
    		username=GSSResourceFactory.getUsernameFromAuthHeader(username);
190 197
    		try {
191
				currentUser = factory.getService().getUserByUserName(username);
198
				currentUser = getService().getUserByUserName(username);
192 199
			} catch (RpcException e) {
193 200
				// TODO Auto-generated catch block
194
				e.printStackTrace();
195 201
				return null;
196 202
			}
197 203
    	}
198 204
    	return currentUser;
199 205
	}
206
	
207
	/**
208
	 * A helper method that retrieves a reference to the ExternalAPI bean and
209
	 * stores it for future use.
210
	 *
211
	 * @return an ExternalAPI instance
212
	 * @throws RpcException in case an error occurs
213
	 */
214
	private ExternalAPI getService() throws RpcException {
215
		try {
216
			final Context ctx = new InitialContext();
217
			final Object ref = ctx.lookup(getConfiguration().getString("externalApiPath"));
218
			return (ExternalAPI) PortableRemoteObject.narrow(ref, ExternalAPI.class);
219
		} catch (final NamingException e) {
220
			log.error("Unable to retrieve the ExternalAPI EJB", e);
221
			throw new RpcException("An error occurred while contacting the naming service");
222
		}
223
	}
200 224

  
201 225
}

Also available in: Unified diff