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

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

  
21
import static gr.ebs.gss.server.configuration.GSSConfigurationFactory.getConfiguration;
22

  
23
import javax.naming.Context;
24
import javax.naming.InitialContext;
25
import javax.naming.NamingException;
26
import javax.rmi.PortableRemoteObject;
27

  
21 28
import gr.ebs.gss.client.exceptions.RpcException;
22 29
import gr.ebs.gss.server.domain.User;
30
import gr.ebs.gss.server.ejb.ExternalAPI;
23 31

  
24 32
import org.slf4j.Logger;
25 33
import org.slf4j.LoggerFactory;
......
121 129
			//log.info("username is:"+username);
122 130
			if(username !=null)
123 131
				try {
124
					currentUser = factory.getService().getUserByUserName(username);
132
					currentUser = getService().getUserByUserName(username);
125 133
				} catch (RpcException e) {
126 134
					// TODO Auto-generated catch block
127
					e.printStackTrace();
135
					log.error("unable to access ejb service",e);
128 136
				}
129 137
		}
130 138
		else if(HttpManager.request().getAuthorization()!=null&&HttpManager.request().getAuthorization().getTag()!=null){
......
134 142
		return currentUser;
135 143
	}
136 144
	
145
	/**
146
	 * A helper method that retrieves a reference to the ExternalAPI bean and
147
	 * stores it for future use.
148
	 *
149
	 * @return an ExternalAPI instance
150
	 * @throws RpcException in case an error occurs
151
	 */
152
	protected ExternalAPI getService() throws RpcException {
153
		try {
154
			final Context ctx = new InitialContext();
155
			final Object ref = ctx.lookup(getConfiguration().getString("externalApiPath"));
156
			return (ExternalAPI) PortableRemoteObject.narrow(ref, ExternalAPI.class);
157
			
158
		} catch (final NamingException e) {
159
			log.error("Unable to retrieve the ExternalAPI EJB", e);
160
			throw new RpcException("An error occurred while contacting the naming service");
161
		}
162
	}
163
	
137 164

  
138 165
}

Also available in: Unified diff