1 18 19 package sync4j.transport.http.server; 20 21 import java.util.Map ; 22 import java.util.HashMap ; 23 24 import javax.servlet.http.*; 25 import javax.naming.*; 26 import javax.ejb.CreateException ; 27 import javax.ejb.RemoveException ; 28 import javax.ejb.EJBException ; 29 import javax.rmi.PortableRemoteObject ; 30 31 import sync4j.framework.transport.http.SyncHolder; 32 import sync4j.framework.server.SyncResponse; 33 import sync4j.server.syncbean.SyncLocal; 34 import sync4j.server.syncbean.SyncHomeLocal; 35 36 import sync4j.framework.core.Sync4jException; 37 import sync4j.framework.server.error.ServerException; 38 import sync4j.framework.server.error.ServerFailureException; 39 import sync4j.framework.server.error.NotImplementedException; 40 import sync4j.framework.protocol.ProtocolException; 41 42 43 import javax.security.auth.login.LoginContext ; 44 import javax.security.auth.login.LoginException ; 45 46 52 public class LocalEJBSyncHolder implements SyncHolder { 53 54 56 public static final String SYNCEJB_HOME_JNDI_NAME = 57 "java:comp/env/ejb/LocalSyncBean"; 58 59 61 private SyncLocal sync = null; 62 private String sessionId = null; 63 private SyncHomeLocal home = null; 64 private long creationTimestamp ; 65 66 68 public LocalEJBSyncHolder() throws NamingException { 69 InitialContext ctx = new InitialContext(); 70 home = (SyncHomeLocal)PortableRemoteObject.narrow( 71 ctx.lookup(SYNCEJB_HOME_JNDI_NAME), 72 SyncHomeLocal.class 73 ); 74 creationTimestamp = System.currentTimeMillis(); 75 } 76 77 79 90 public SyncResponse processXMLMessage(final byte[] requestData, 91 final Map parameters , 92 final Map headers ) 93 throws ServerException { 94 return sync.processXMLMessage(requestData, parameters, headers); 95 } 96 97 108 public SyncResponse processWBXMLMessage(final byte[] requestData, 109 final Map parameters , 110 final Map headers ) 111 throws ServerException { 112 return sync.processWBXMLMessage(requestData, parameters, headers); 113 } 114 115 public void setSessionId(String sessionId) throws Sync4jException { 116 try { 117 sync = home.create(sessionId); 118 } catch (CreateException e) { 119 throw new ServerFailureException(e); 120 } 121 122 this.sessionId = sessionId; 123 } 124 125 public String getSessionId() { 126 return sessionId; 127 } 128 129 136 public void close() throws Exception { 137 try { 138 sync.remove(); 139 } catch (RemoveException e) { 140 throw new Exception ("Error in closing the SyncHolder", e); 141 } catch (EJBException e) { 142 throw new Exception ("Error in closing the SyncHolder", e); 143 } 144 } 145 146 152 public long getCreationTimestamp() { 153 return creationTimestamp; 154 } 155 } 156 | Popular Tags |