Added:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/MessageService.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/SIPMessageManager.java
(contents, props changed)
- copied, changed from r201,
/trunk/sipana-server-ejb/src/main/java/org/sipana/server/dao/SIPMessageManager.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/SIPPerformanceMetrics.java
- copied, changed from r200,
/trunk/sipana-server-ejb/src/main/java/org/sipana/server/sip/metric/SIPPerformanceMetrics.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/SIPSessionMDB.java
(contents, props changed)
- copied, changed from r201,
/trunk/sipana-server-ejb/src/main/java/org/sipana/server/sip/SIPSessionMDB.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/SIPSessionManager.java
(contents, props changed)
- copied, changed from r201,
/trunk/sipana-server-ejb/src/main/java/org/sipana/server/dao/SIPSessionManager.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/AbstractManagerBean.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/MessageServiceBean.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/SIPMessageManagerBean.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/SIPPerformanceMetricsBean.java
- copied, changed from r200,
/trunk/sipana-server-ejb/src/main/java/org/sipana/server/sip/metric/SIPPerformanceMetricsBean.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/SIPSessionFindParams.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/SIPSessionManagerBean.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/mbean/
trunk/sipana-server-ejb/src/main/java/org/sipana/server/mbean/SIPHandlerMBean.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/sip/SIPHandler.java
trunk/sipana-server-war/src/main/java/org/sipana/server/web/sip/SIPSessionController.java
(contents, props changed)
- copied, changed from r201,
/trunk/sipana-server-war/src/main/java/org/sipana/server/web/sip/session/SIPSessionController.java
trunk/sipana-sipscenario/src/main/java/org/sipana/sip/SIPScenario.java
trunk/sipana-sipscenario/src/main/resources/
Removed:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/dao/AbstractManagerBean.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/dao/SIPMessageManager.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/dao/SIPMessageManagerBean.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/dao/SIPSessionFindParams.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/dao/SIPSessionManager.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/dao/SIPSessionManagerBean.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/sip/SIPSessionMDB.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/sip/metric/SIPPerformanceMetrics.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/sip/metric/SIPPerformanceMetricsBean.java
trunk/sipana-server-war/src/main/java/org/sipana/server/web/sip/session/SIPSessionController.java
trunk/sipana-sipscenario/src/main/java/org/sipana/sip/scenario/SIPScenario.java
Modified:
trunk/sipana-server-ejb/pom.xml
trunk/sipana-server-ejb/src/main/java/org/sipana/server/service/Service.java
trunk/sipana-server-ejb/src/main/java/org/sipana/server/service/ServiceLocator.java
trunk/sipana-server-ejb/src/test/java/org/sipana/server/test/sip/SIPPerformanceMetricsTest.java
trunk/sipana-server-war/src/main/webapp/WEB-INF/faces-config.xml
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPMessageWSImpl.java
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPScenarioStreamingOutput.java
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPScenarioWSImpl.java
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPSessionWSImpl.java
trunk/sipana-sipscenario/src/test/java/org/sipana/sip/scenario/SIPScenarioTest.java
Log:
EJB module package refactoring.
Modified: trunk/sipana-server-ejb/pom.xml
==============================================================================
--- trunk/sipana-server-ejb/pom.xml (original)
+++ trunk/sipana-server-ejb/pom.xml Mon May 25 20:33:09 2009
@@ -43,5 +43,6 @@
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
+
</dependencies>
</project>
Added:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/MessageService.java
==============================================================================
--- (empty file)
+++
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/MessageService.java
Mon May 25 20:33:09 2009
@@ -0,0 +1,30 @@
+/**
+ * This file is part of Sipana project <http://sipana.org/>
+ *
+ * Sipana is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 3 of the License.
+ *
+ * Sipana is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.sipana.server.ejb;
+
+import java.util.List;
+import javax.ejb.Local;
+import org.sipana.protocol.sip.SIPMessage;
+
+/**
+ *
+ * @author mhack
+ */
+@Local
+public interface MessageService {
+ public void processMessage(SIPMessage message);
+ public void processMessage(List<SIPMessage> messageList);
+}
Copied:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/SIPMessageManager.java
(from r201,
/trunk/sipana-server-ejb/src/main/java/org/sipana/server/dao/SIPMessageManager.java)
==============================================================================
---
/trunk/sipana-server-ejb/src/main/java/org/sipana/server/dao/SIPMessageManager.java
(original)
+++
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/SIPMessageManager.java
Mon May 25 20:33:09 2009
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.sipana.server.dao;
+package org.sipana.server.ejb;
import java.util.List;
import javax.ejb.Local;
Copied:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/SIPPerformanceMetrics.java
(from r200,
/trunk/sipana-server-ejb/src/main/java/org/sipana/server/sip/metric/SIPPerformanceMetrics.java)
==============================================================================
---
/trunk/sipana-server-ejb/src/main/java/org/sipana/server/sip/metric/SIPPerformanceMetrics.java
(original)
+++
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/SIPPerformanceMetrics.java
Mon May 25 20:33:09 2009
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.sipana.server.sip.metric;
+package org.sipana.server.ejb;
import java.util.List;
import javax.ejb.Local;
Copied:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/SIPSessionMDB.java
(from r201,
/trunk/sipana-server-ejb/src/main/java/org/sipana/server/sip/SIPSessionMDB.java)
==============================================================================
---
/trunk/sipana-server-ejb/src/main/java/org/sipana/server/sip/SIPSessionMDB.java
(original)
+++
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/SIPSessionMDB.java
Mon May 25 20:33:09 2009
@@ -13,9 +13,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.sipana.server.sip;
+package org.sipana.server.ejb;
-import org.sipana.server.dao.*;
+import org.sipana.server.ejb.impl.SIPSessionManagerBean;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
Copied:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/SIPSessionManager.java
(from r201,
/trunk/sipana-server-ejb/src/main/java/org/sipana/server/dao/SIPSessionManager.java)
==============================================================================
---
/trunk/sipana-server-ejb/src/main/java/org/sipana/server/dao/SIPSessionManager.java
(original)
+++
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/SIPSessionManager.java
Mon May 25 20:33:09 2009
@@ -13,8 +13,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.sipana.server.dao;
+package org.sipana.server.ejb;
+import org.sipana.server.ejb.impl.SIPSessionFindParams;
import java.util.List;
import javax.ejb.Local;
Added:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/AbstractManagerBean.java
==============================================================================
--- (empty file)
+++
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/AbstractManagerBean.java
Mon May 25 20:33:09 2009
@@ -0,0 +1,49 @@
+/**
+ * This file is part of Sipana project <http://sipana.org/>
+ *
+ * Sipana is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 3 of the License.
+ *
+ * Sipana is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.sipana.server.ejb.impl;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+/**
+ *
+ * @author Marcos Hack <marco...@gmail.com>
+ */
+public abstract class AbstractManagerBean {
+
+ @PersistenceContext(unitName = "sipana")
+ protected EntityManager manager;
+
+ private boolean isCacheable;
+
+ public boolean isCacheable() {
+ return isCacheable;
+ }
+
+ public void setCacheable(boolean isCacheable) {
+ this.isCacheable = isCacheable;
+ }
+
+ protected Query createQuery(String query) {
+ Query q = manager.createQuery(query);
+ return q;
+ }
+
+ protected Query createQuery(StringBuilder sbQuery) {
+ return createQuery(sbQuery.toString());
+ }
+}
Added:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/MessageServiceBean.java
==============================================================================
--- (empty file)
+++
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/MessageServiceBean.java
Mon May 25 20:33:09 2009
@@ -0,0 +1,38 @@
+/**
+ * This file is part of Sipana project <http://sipana.org/>
+ *
+ * Sipana is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 3 of the License.
+ *
+ * Sipana is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.sipana.server.ejb.impl;
+
+import java.util.List;
+import javax.ejb.Stateless;
+import org.sipana.protocol.sip.SIPMessage;
+import org.sipana.server.ejb.MessageService;
+
+/**
+ *
+ * @author mhack
+ */
+@Stateless
+public class MessageServiceBean implements MessageService {
+
+ public void processMessage(SIPMessage message) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void processMessage(List<SIPMessage> messageList) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+}
Added:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/SIPMessageManagerBean.java
==============================================================================
--- (empty file)
+++
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/SIPMessageManagerBean.java
Mon May 25 20:33:09 2009
@@ -0,0 +1,76 @@
+/**
+ * This file is part of Sipana project <http://sipana.org/>
+ *
+ * Sipana is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 3 of the License.
+ *
+ * Sipana is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.sipana.server.ejb.impl;
+
+import org.sipana.server.ejb.*;
+import java.util.ArrayList;
+import java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.Query;
+import org.apache.commons.lang.StringUtils;
+import org.sipana.protocol.sip.SIPMessage;
+import org.sipana.protocol.sip.SIPMessageList;
+
+/**
+ *
+ * @author Marcos Hack <marco...@gmail.com>
+ */
+@Stateless
+public class SIPMessageManagerBean extends AbstractManagerBean implements
SIPMessageManager {
+
+ public SIPMessage find(long id) {
+ return manager.find(SIPMessage.class, id);
+ }
+
+ public List<SIPMessage> findBySessionID(Long sessionId) {
+ List<Long> sessionIdList = new ArrayList<Long>();
+ sessionIdList.add(sessionId);
+ return findBySessionID(sessionIdList);
+ }
+
+ public List<SIPMessage> findBySessionID(List<Long> sessionIdList) {
+ StringBuilder sbQuery = new StringBuilder("SELECT m FROM
SIPMessage m INNER JOIN m.sipSession AS s WHERE s.id IN (");
+ sbQuery.append("'").append(StringUtils.join(sessionIdList, "','"));
+ sbQuery.append("') ORDER BY m.time");
+
+ Query q = createQuery(sbQuery);
+ return q.getResultList();
+ }
+
+ public List<SIPMessage> findByCallID(String callId) {
+ ArrayList<String> callIdList = new ArrayList<String>();
+ callIdList.add(callId);
+ return findByCallID(callIdList);
+ }
+
+ public List<SIPMessage> findByCallID(List<String> callIdList) {
+ StringBuilder sbQuery = new StringBuilder("SELECT m FROM
SIPMessage m WHERE m.callId IN (");
+
sbQuery.append("'").append(StringUtils.join(callIdList, "','")).append("')
ORDER BY m.time");
+
+ Query q = createQuery(sbQuery);
+ return q.getResultList();
+ }
+
+ public void save(SIPMessage message) {
+ manager.persist(message);
+ }
+
+ public void save(List<SIPMessage> messageList) {
+ for (SIPMessage m : messageList) {
+ save(m);
+ }
+ }
+}
Copied:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/SIPPerformanceMetricsBean.java
(from r200,
/trunk/sipana-server-ejb/src/main/java/org/sipana/server/sip/metric/SIPPerformanceMetricsBean.java)
==============================================================================
---
/trunk/sipana-server-ejb/src/main/java/org/sipana/server/sip/metric/SIPPerformanceMetricsBean.java
(original)
+++
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/SIPPerformanceMetricsBean.java
Mon May 25 20:33:09 2009
@@ -13,8 +13,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.sipana.server.sip.metric;
+package org.sipana.server.ejb.impl;
+import org.sipana.server.ejb.SIPPerformanceMetrics;
import java.util.List;
import javax.ejb.Stateless;
import javax.sip.message.Request;
Added:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/SIPSessionFindParams.java
==============================================================================
--- (empty file)
+++
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/SIPSessionFindParams.java
Mon May 25 20:33:09 2009
@@ -0,0 +1,107 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.sipana.server.ejb.impl;
+
+import java.util.Date;
+import java.util.List;
+import org.sipana.protocol.sip.SIPSessionState;
+
+/**
+ *
+ * @author mhack
+ */
+public class SIPSessionFindParams {
+ private Date startDate;
+ private Date endDate;
+ private String requestMethod;
+ private String callID;
+ private Integer responseCode;
+ private String fromUser;
+ private String toUser;
+ private List<String> srcAddressList;
+ private List<String> dstAddressList;
+ private SIPSessionState state;
+
+ public String getCallID() {
+ return callID;
+ }
+
+ public void setCallID(String callID) {
+ this.callID = callID;
+ }
+
+ public List<String> getDstAddressList() {
+ return dstAddressList;
+ }
+
+ public void setDstAddressList(List<String> dstAddressList) {
+ this.dstAddressList = dstAddressList;
+ }
+
+ public Date getEndDate() {
+ return endDate;
+ }
+
+ public void setEndDate(Date endDate) {
+ this.endDate = endDate;
+ }
+
+ public String getFromUser() {
+ return fromUser;
+ }
+
+ public void setFromUser(String fromUser) {
+ this.fromUser = fromUser;
+ }
+
+ public String getRequestMethod() {
+ return requestMethod;
+ }
+
+ public void setRequestMethod(String requestMethod) {
+ this.requestMethod = requestMethod;
+ }
+
+ public Integer getResponseCode() {
+ return responseCode;
+ }
+
+ public void setResponseCode(Integer responseCode) {
+ this.responseCode = responseCode;
+ }
+
+ public List<String> getSrcAddressList() {
+ return srcAddressList;
+ }
+
+ public void setSrcAddressList(List<String> srcAddressList) {
+ this.srcAddressList = srcAddressList;
+ }
+
+ public Date getStartDate() {
+ return startDate;
+ }
+
+ public void setStartDate(Date startDate) {
+ this.startDate = startDate;
+ }
+
+ public SIPSessionState getState() {
+ return state;
+ }
+
+ public void setState(SIPSessionState state) {
+ this.state = state;
+ }
+
+ public String getToUser() {
+ return toUser;
+ }
+
+ public void setToUser(String toUser) {
+ this.toUser = toUser;
+ }
+}
Added:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/SIPSessionManagerBean.java
==============================================================================
--- (empty file)
+++
trunk/sipana-server-ejb/src/main/java/org/sipana/server/ejb/impl/SIPSessionManagerBean.java
Mon May 25 20:33:09 2009
@@ -0,0 +1,170 @@
+/**
+ * This file is part of Sipana project <http://sipana.org/>
+ *
+ * Sipana is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 3 of the License.
+ *
+ * Sipana is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.sipana.server.ejb.impl;
+
+import org.sipana.server.ejb.impl.SIPSessionFindParams;
+import org.sipana.server.ejb.*;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+import javax.ejb.Stateless;
+import javax.persistence.NoResultException;
+import javax.persistence.Query;
+
+import org.apache.commons.lang.StringUtils;
+import org.sipana.protocol.sip.SIPSession;
+
+@Stateless
+public class SIPSessionManagerBean extends AbstractManagerBean implements
SIPSessionManager {
+
+ public SIPSession find(long id) {
+ return manager.find(SIPSession.class, id);
+ }
+
+ public SIPSession findByCallID(String callID) {
+ String strQuery = "SELECT s FROM SIPSession s WHERE s.callId
= :callid";
+ Query query = manager.createQuery(strQuery);
+ query.setParameter("callid", callID);
+
+ try {
+ return (SIPSession) query.getSingleResult();
+ } catch (NoResultException e) {
+ return null;
+ }
+ }
+
+ public long getSIPSessionCount() {
+ String strQuery = "select count(*) from SIPSession";
+ return (Long) createQuery(strQuery).getSingleResult();
+ }
+
+ // TODO [mhack] remade find(SIPSessionFindParams) method.
+ public List<SIPSession> find(SIPSessionFindParams params) {
+ List<String> ipAddrList = new ArrayList<String>();
+
+ if (params.getDstAddressList() != null) {
+ ipAddrList.addAll(params.getDstAddressList());
+ }
+ if (params.getSrcAddressList() != null) {
+ ipAddrList.addAll(params.getSrcAddressList());
+ }
+
+ Date startDate = params.getStartDate();
+ Long startTime = startDate != null ? startDate.getTime() : 0L;
+
+ Date endDate = params.getEndDate();
+ Long endTime;
+ if (endDate != null) {
+ endTime = endDate.getTime();
+ } else {
+ endTime = GregorianCalendar.getInstance().getTimeInMillis();
+ }
+
+ String method = params.getRequestMethod();
+ String fromUser = params.getFromUser();
+ String toUser = params.getToUser();
+ String callID = params.getCallID();
+
+ StringBuilder sbQuery = new StringBuilder("SELECT DISTINCT s FROM
SIPSession s ");
+
+ if (ipAddrList != null && ipAddrList.size() > 0) {
+ sbQuery.append("INNER JOIN s.messages AS m ");
+ }
+
+ sbQuery.append("WHERE s.startTime >= :start AND s.endTime
<= :end ");
+
+ if (method != null && !method.equals("")) {
+ sbQuery.append("AND s.requestMethod
= '").append(method.toUpperCase()).append("' ");
+ }
+
+ if (fromUser != null && !fromUser.equals("")) {
+ sbQuery.append("AND s.fromUser
LIKE '%").append(fromUser).append("%' ");
+ }
+
+ if (toUser != null && !toUser.equals("")) {
+ sbQuery.append("AND s.toUser
LIKE '%").append(toUser).append("%' ");
+ }
+
+ if (callID != null && !callID.equals("")) {
+ sbQuery.append("AND s.callId
LIKE '%").append(callID).append("%' ");
+ }
+
+ if (ipAddrList != null && ipAddrList.size() > 0) {
+ String csvList = StringUtils.join(ipAddrList, "','");
+ String ipAddrInList = new
StringBuilder("'").append(csvList).append("'").toString();
+ sbQuery.append("AND (m.srcAddress IN (").append(ipAddrInList);
+ sbQuery.append(") OR m.dstAddress IN
(").append(ipAddrInList).append(")) ");
+ }
+
+ // If startTime/endTime is null set it to min/max values
+ if (startTime == null) {
+ startTime = 0L;
+ }
+ if (endTime == null) {
+ endTime = Calendar.getInstance().getTimeInMillis();
+ }
+
+ sbQuery.append("ORDER BY s.startTime DESC");
+
+ Query query = createQuery(sbQuery);
+ query.setParameter("start", startTime);
+ query.setParameter("end", endTime);
+
+ return query.getResultList();
+ }
+
+ @Deprecated
+ public List<SIPSession> find(
+ Long startTime,
+ Long endTime,
+ String method,
+ String fromUser,
+ String toUser,
+ String callId,
+ List<String> ipAddrList) {
+ SIPSessionFindParams params = new SIPSessionFindParams();
+
+ Calendar calendar = GregorianCalendar.getInstance();
+ if (startTime != null) {
+ calendar.setTimeInMillis(startTime);
+ params.setStartDate(calendar.getTime());
+ }
+
+ if (endTime != null) {
+ calendar.setTimeInMillis(endTime);
+ params.setEndDate(calendar.getTime());
+ }
+
+ params.setRequestMethod(method);
+ params.setFromUser(fromUser);
+ params.setToUser(toUser);
+ params.setCallID(callId);
+ params.setSrcAddressList(ipAddrList);
+
+ return find(params);
+ }
+
+ public void save(SIPSession session) {
+ if (session.getId() > 0) {
+ manager.merge(session);
+ } else {
+ manager.persist(session);
+ }
+ }
+}
Added:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/mbean/SIPHandlerMBean.java
==============================================================================
--- (empty file)
+++
trunk/sipana-server-ejb/src/main/java/org/sipana/server/mbean/SIPHandlerMBean.java
Mon May 25 20:33:09 2009
@@ -0,0 +1,14 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.sipana.server.mbean;
+
+/**
+ *
+ * @author mhack
+ */
+public interface SIPHandlerMBean {
+
+}
Modified:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/service/Service.java
==============================================================================
---
trunk/sipana-server-ejb/src/main/java/org/sipana/server/service/Service.java
(original)
+++
trunk/sipana-server-ejb/src/main/java/org/sipana/server/service/Service.java
Mon May 25 20:33:09 2009
@@ -15,9 +15,9 @@
*/
package org.sipana.server.service;
-import org.sipana.server.dao.SIPMessageManagerBean;
-import org.sipana.server.dao.SIPSessionManagerBean;
-import org.sipana.server.sip.metric.SIPPerformanceMetricsBean;
+import org.sipana.server.ejb.impl.SIPMessageManagerBean;
+import org.sipana.server.ejb.impl.SIPSessionManagerBean;
+import org.sipana.server.ejb.impl.SIPPerformanceMetricsBean;
public interface Service {
Modified:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/service/ServiceLocator.java
==============================================================================
---
trunk/sipana-server-ejb/src/main/java/org/sipana/server/service/ServiceLocator.java
(original)
+++
trunk/sipana-server-ejb/src/main/java/org/sipana/server/service/ServiceLocator.java
Mon May 25 20:33:09 2009
@@ -18,9 +18,9 @@
import javax.naming.InitialContext;
import org.apache.log4j.Logger;
+import org.sipana.server.sip.SIPHandler;
public class ServiceLocator {
- private static final Object classLock = ServiceLocator.class;
private static ServiceLocator instance = null;
private Logger logger = Logger.getLogger(ServiceLocator.class);
@@ -29,7 +29,7 @@
}
public static ServiceLocator getInstance() {
- synchronized (classLock) {
+ synchronized (ServiceLocator.class) {
if (instance == null) {
instance = new ServiceLocator();
}
@@ -59,4 +59,8 @@
throw new ServiceLocatorException("Fail getting service " +
serviceName, e);
}
}
+
+ public SIPHandler getSIPHandler() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
}
Added:
trunk/sipana-server-ejb/src/main/java/org/sipana/server/sip/SIPHandler.java
==============================================================================
--- (empty file)
+++
trunk/sipana-server-ejb/src/main/java/org/sipana/server/sip/SIPHandler.java
Mon May 25 20:33:09 2009
@@ -0,0 +1,15 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.sipana.server.sip;
+
+import org.sipana.server.mbean.SIPHandlerMBean;
+
+/**
+ *
+ * @author mhack
+ */
+public class SIPHandler implements SIPHandlerMBean {
+
+}
Modified:
trunk/sipana-server-ejb/src/test/java/org/sipana/server/test/sip/SIPPerformanceMetricsTest.java
==============================================================================
---
trunk/sipana-server-ejb/src/test/java/org/sipana/server/test/sip/SIPPerformanceMetricsTest.java
(original)
+++
trunk/sipana-server-ejb/src/test/java/org/sipana/server/test/sip/SIPPerformanceMetricsTest.java
Mon May 25 20:33:09 2009
@@ -23,8 +23,8 @@
import org.junit.Test;
import org.sipana.protocol.sip.SIPRequest;
import org.sipana.protocol.sip.SIPSession;
-import org.sipana.server.sip.metric.SIPPerformanceMetrics;
-import org.sipana.server.sip.metric.SIPPerformanceMetricsBean;
+import org.sipana.server.ejb.SIPPerformanceMetrics;
+import org.sipana.server.ejb.impl.SIPPerformanceMetricsBean;
public class SIPPerformanceMetricsTest {
private SIPPerformanceMetrics metrics;
Copied:
trunk/sipana-server-war/src/main/java/org/sipana/server/web/sip/SIPSessionController.java
(from r201,
/trunk/sipana-server-war/src/main/java/org/sipana/server/web/sip/session/SIPSessionController.java)
==============================================================================
---
/trunk/sipana-server-war/src/main/java/org/sipana/server/web/sip/session/SIPSessionController.java
(original)
+++
trunk/sipana-server-war/src/main/java/org/sipana/server/web/sip/SIPSessionController.java
Mon May 25 20:33:09 2009
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package org.sipana.server.web.sip.session;
+package org.sipana.server.web.sip;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -29,7 +29,7 @@
import org.sipana.protocol.sip.SIPSession;
import org.sipana.server.service.Service;
import org.sipana.server.service.ServiceLocator;
-import org.sipana.server.dao.SIPSessionManager;
+import org.sipana.server.ejb.SIPSessionManager;
public class SIPSessionController {
Modified: trunk/sipana-server-war/src/main/webapp/WEB-INF/faces-config.xml
==============================================================================
--- trunk/sipana-server-war/src/main/webapp/WEB-INF/faces-config.xml
(original)
+++ trunk/sipana-server-war/src/main/webapp/WEB-INF/faces-config.xml Mon
May 25 20:33:09 2009
@@ -16,9 +16,7 @@
<managed-bean>
<managed-bean-name>sipSession</managed-bean-name>
- <managed-bean-class>
- org.sipana.server.web.sip.session.SIPSessionController
- </managed-bean-class>
+
<managed-bean-class>org.sipana.server.web.sip.SIPSessionController</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
Modified:
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPMessageWSImpl.java
==============================================================================
---
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPMessageWSImpl.java
(original)
+++
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPMessageWSImpl.java
Mon May 25 20:33:09 2009
@@ -22,7 +22,7 @@
import org.sipana.protocol.sip.SIPMessageList;
import org.sipana.server.service.Service;
import org.sipana.server.service.ServiceLocator;
-import org.sipana.server.dao.SIPMessageManager;
+import org.sipana.server.ejb.SIPMessageManager;
import org.sipana.server.ws.xml.SIPMessageWSXML;
/**
Modified:
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPScenarioStreamingOutput.java
==============================================================================
---
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPScenarioStreamingOutput.java
(original)
+++
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPScenarioStreamingOutput.java
Mon May 25 20:33:09 2009
@@ -6,7 +6,7 @@
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.StreamingOutput;
import org.sipana.protocol.sip.SIPMessage;
-import org.sipana.sip.scenario.SIPScenario;
+import org.sipana.sip.SIPScenario;
/**
*
Modified:
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPScenarioWSImpl.java
==============================================================================
---
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPScenarioWSImpl.java
(original)
+++
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPScenarioWSImpl.java
Mon May 25 20:33:09 2009
@@ -21,7 +21,7 @@
import javax.ws.rs.core.StreamingOutput;
import org.apache.log4j.Logger;
import org.sipana.protocol.sip.SIPMessage;
-import org.sipana.server.dao.SIPMessageManager;
+import org.sipana.server.ejb.SIPMessageManager;
import org.sipana.server.service.Service;
import org.sipana.server.service.ServiceLocator;
import org.sipana.server.ws.jpeg.SIPScenarioWSJPEG;
Modified:
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPSessionWSImpl.java
==============================================================================
---
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPSessionWSImpl.java
(original)
+++
trunk/sipana-server-ws/src/main/java/org/sipana/server/ws/impl/SIPSessionWSImpl.java
Mon May 25 20:33:09 2009
@@ -24,7 +24,7 @@
import org.sipana.protocol.sip.SIPSessionList;
import org.sipana.server.service.Service;
import org.sipana.server.service.ServiceLocator;
-import org.sipana.server.dao.SIPSessionManager;
+import org.sipana.server.ejb.SIPSessionManager;
/**
*
Added:
trunk/sipana-sipscenario/src/main/java/org/sipana/sip/SIPScenario.java
==============================================================================
--- (empty file)
+++ trunk/sipana-sipscenario/src/main/java/org/sipana/sip/SIPScenario.java
Mon May 25 20:33:09 2009
@@ -0,0 +1,257 @@
+/**
+ * This file is part of Sipana project <http://sipana.org/>
+ *
+ * Sipana is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 3 of the License.
+ *
+ * Sipana is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.sipana.sip;
+
+import org.sipana.*;
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Polygon;
+import java.awt.Rectangle;
+import java.awt.image.BufferedImage;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.sipana.SipanaProperties;
+import org.sipana.SipanaPropertyType;
+import org.sipana.protocol.sip.SIPMessage;
+import org.sipana.protocol.sip.SIPRequest;
+import org.sipana.protocol.sip.SIPResponse;
+
+import java.io.IOException;
+import javax.imageio.ImageIO;
+
+/**
+ *
+ * @author Marcos Hack <marco...@gmail.com>
+ */
+public class SIPScenario {
+
+ private static final int IMAGE_BORDER = 20;
+ private static final int HOST_INIT_W = 80;
+ private static final int HOST_INIT_H = 20;
+ private static final int HOST_STEP_W = 150;
+ private static final int HOST_LINE_OFFSET_W = 54;
+ private static final int HOST_LINE_OFFSET_H = 8;
+ private static final int HOST_LINE_TO_MSG_BOX_OFFSET_H = 5;
+ private static final int MSG_STEP_H = 26;
+ private static final List<Color> colors = createColorList();
+ private static final String DEFAULT_IMAGE_FORMAT = "png";
+ private String imageFormat;
+ private int currColor = 0;
+ private int imgWidth;
+ private int imgHeight;
+ private List<SIPMessage> messages;
+ private Map<String, Color> sessionColors;
+ private HashMap<String, Integer> hostList;
+
+ public SIPScenario(List<SIPMessage> messages) {
+ this(messages, DEFAULT_IMAGE_FORMAT);
+ }
+
+ public SIPScenario(List<SIPMessage> messages, String format) {
+ this.messages = messages;
+ hostList = createHostListWithWeightPosition(messages);
+ imageFormat = format;
+ sessionColors = new HashMap<String, Color>();
+ }
+
+ /**
+ * Create SIP Scenario diagram and save it as a JPEG image file.
+ *
+ * @param List of messages to create SIP scenario diagram
+ * @param OutputStream to write the encoded JPEG image to
+ * @author Marcos Hack <marco...@gmail.com>
+ */
+ public void create(OutputStream outputStream) throws IOException {
+ BufferedImage buffImage;
+
+ if (messages.size() > 0) {
+ imgWidth = (HOST_STEP_W * hostList.size()) + HOST_INIT_W;
+ imgHeight = (MSG_STEP_H * messages.size()) + (IMAGE_BORDER *
3);
+
+ buffImage = new BufferedImage(imgWidth, imgHeight,
BufferedImage.TYPE_INT_RGB);
+ Graphics2D graph = buffImage.createGraphics();
+ graph.setBackground(Color.WHITE);
+ graph.clearRect(1, 1, imgWidth - 2, imgHeight - 2);
+ drawMessages(graph, messages, hostList);
+ drawHosts(graph, imgHeight, hostList);
+
+ } else {
+ // Empty SIPScenario, only a warning about that
+ imgWidth = 400;
+ imgHeight = 200;
+
+ buffImage = new BufferedImage(imgWidth, imgHeight,
BufferedImage.TYPE_INT_RGB);
+ Graphics2D graph = buffImage.createGraphics();
+ graph.setBackground(Color.WHITE);
+ graph.clearRect(1, 1, imgWidth - 2, imgHeight - 2);
+ graph.setColor(Color.BLACK);
+ graph.drawString("Empty message list. Unable to draw SIP
scenario.", 50, imgHeight/2);
+ }
+
+ ImageIO.write(buffImage, imageFormat, outputStream);
+ }
+
+ private void drawMessages(Graphics2D graph, List<SIPMessage> messages,
+ HashMap<String, Integer> hostList) {
+ // stroke for message's continuous line
+ float dash[] = null;
+ BasicStroke bs = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
+ graph.setStroke(bs);
+
+ // Height to start to drawing the colored message boxes: Below the
host
+ // list and a little bit (HOST_LINE_TO_MSG_BOX_OFFSET_H) bellow
the host
+ // vertical stroke line
+ int h = HOST_INIT_H * 2 + HOST_LINE_TO_MSG_BOX_OFFSET_H;
+
+ Long startTime = null;
+ int msgBoxWidth = imgWidth - (IMAGE_BORDER * 2);
+
+ for (SIPMessage message : messages) {
+ String srcAddr = new
StringBuilder(message.getSrcAddress()).append(":").append(message.getSrcPort()).toString();
+ String dstAddr = new
StringBuilder(message.getDstAddress()).append(":").append(message.getDstPort()).toString();
+ int srcWPos = hostList.get(srcAddr);
+ int dstWPos = hostList.get(dstAddr);
+
+ // draw session's background color
+ Color msgBkgrdColor = getSessionColor(message.getCallID());
+ graph.setColor(msgBkgrdColor);
+ int yBox = h - (MSG_STEP_H / 2);
+ Rectangle msgColorBox = new Rectangle(IMAGE_BORDER, yBox,
msgBoxWidth, MSG_STEP_H);
+ graph.fill(msgColorBox);
+ graph.draw(msgColorBox);
+
+ graph.setColor(Color.BLACK);
+
+ // set start time with first message's time
+ if (startTime == null) {
+ startTime = message.getTime();
+ }
+
+ // relative time stamp
+ long relativeTime = message.getTime() - startTime;
+ graph.drawString(String.valueOf(relativeTime), IMAGE_BORDER, h
+ 5);
+
+ // arrow line
+ graph.drawLine(srcWPos, h, dstWPos, h);
+
+ // arrow
+ int arrowWidth =
SipanaProperties.getPropertyInt(SipanaPropertyType.SIPSCENARIO_ARROW_WIDTH);
+ int arrowHeight =
SipanaProperties.getPropertyInt(SipanaPropertyType.SIPSCENARIO_ARROW_HEIGHT);
+ Polygon arrow = new Polygon();
+ arrow.addPoint(dstWPos, h);
+ int wInc = (dstWPos > srcWPos) ? -arrowWidth : arrowWidth;
+ arrow.addPoint(dstWPos + wInc, h - arrowHeight);
+ arrow.addPoint(dstWPos + wInc, h + arrowHeight);
+ graph.fillPolygon(arrow);
+ graph.drawPolygon(arrow);
+
+ // text
+ String text = null;
+ if (message instanceof SIPRequest) {
+ text = ((SIPRequest) message).getMethod();
+ } else {
+ text = ((SIPResponse) message).getStatusCode() + " " +
((SIPResponse) message).getReasonPhrase();
+ }
+
+ int stepCenter = HOST_STEP_W / 2;
+ int textWCenter = dstWPos + ((dstWPos > srcWPos) ?
-stepCenter : stepCenter);
+ int textWPos = textWCenter - HOST_STEP_W / 4;
+ graph.drawString(text, textWPos, h - 2);
+
+ h += MSG_STEP_H;
+ }
+ }
+
+ private void drawHosts(Graphics2D graph, int height,
+ HashMap<String, Integer> hostList) {
+ graph.setColor(Color.BLACK);
+ graph.drawString("Delta", IMAGE_BORDER, HOST_INIT_H);
+
+ // stroke for host's dashed line
+ float dash[] = {3.0f};
+ BasicStroke bs = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
+ graph.setStroke(bs);
+
+ for (String hostAddr : hostList.keySet()) {
+ int lineWeight = hostList.get(hostAddr);
+ graph.drawString(hostAddr, (lineWeight - HOST_LINE_OFFSET_W),
HOST_INIT_H);
+ graph.drawLine(lineWeight, HOST_INIT_H + HOST_LINE_OFFSET_H,
lineWeight, height - HOST_INIT_H);
+ }
+ }
+
+ private HashMap<String, Integer> createHostListWithWeightPosition(
+ List<SIPMessage> messages) {
+ HashMap<String, Integer> resHostList = new HashMap<String,
Integer>();
+ int lineWeigh = HOST_INIT_W + HOST_LINE_OFFSET_W;
+
+ for (SIPMessage message : messages) {
+ String srcAddr = new
StringBuilder(message.getSrcAddress()).append(":").append(message.getSrcPort()).toString();
+ String dstAddr = new
StringBuilder(message.getDstAddress()).append(":").append(message.getDstPort()).toString();
+
+ if (resHostList.get(srcAddr) == null) {
+ resHostList.put(srcAddr, lineWeigh);
+ lineWeigh += HOST_STEP_W;
+ }
+
+ if (resHostList.get(dstAddr) == null) {
+ resHostList.put(dstAddr, lineWeigh);
+ lineWeigh += HOST_STEP_W;
+ }
+ }
+
+ return resHostList;
+ }
+
+ private Color getSessionColor(String callId) {
+ Color color;
+
+ // Get color for session with the specified callId, otherwise get
the
+ // next available color and associate it to this callId.
+ if (sessionColors.containsKey(callId)) {
+ color = sessionColors.get(callId);
+ } else {
+ // Restart current color if all available was used
+ if (currColor == colors.size()) {
+ currColor = 0;
+ }
+
+ color = colors.get(currColor++);
+ sessionColors.put(callId, color);
+ }
+
+ return color;
+ }
+
+ private static List<Color> createColorList() {
+ String strColorList =
SipanaProperties.getProperty(SipanaPropertyType.SIPSCENARIO_COLORS);
+ String colorList[] = strColorList.split(",");
+
+ List<Color> resultColors = new ArrayList<Color>();
+
+ for (String strColor : colorList) {
+ int rgbColor = Integer.parseInt(strColor, 16);
+ Color color = new Color(rgbColor);
+ resultColors.add(color);
+ }
+
+ return resultColors;
+ }
+}
Modified:
trunk/sipana-sipscenario/src/test/java/org/sipana/sip/scenario/SIPScenarioTest.java
==============================================================================
---
trunk/sipana-sipscenario/src/test/java/org/sipana/sip/scenario/SIPScenarioTest.java
(original)
+++
trunk/sipana-sipscenario/src/test/java/org/sipana/sip/scenario/SIPScenarioTest.java
Mon May 25 20:33:09 2009
@@ -15,6 +15,7 @@
*/
package org.sipana.sip.scenario;
+import org.sipana.sip.SIPScenario;
import static org.junit.Assert.assertTrue;
import java.io.File;