diff --git a/onebusaway-admin-webapp/pom.xml b/onebusaway-admin-webapp/pom.xml index 64b9af2ea9..3f9cbe4711 100644 --- a/onebusaway-admin-webapp/pom.xml +++ b/onebusaway-admin-webapp/pom.xml @@ -3,7 +3,7 @@ org.onebusaway onebusaway-application-modules - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-admin-webapp war @@ -12,14 +12,33 @@ 2.3.1 1.0.1 - 11-beta - 4.2.10.RELEASE + 20.5 + 5.3.2.RELEASE /var/lib/oba/bundles/builder /var/lib/oba/bundles/staged /var/lib/oba/bundles/active + + + osgeo + Open Source Geospatial Foundation Repository + https://repo.osgeo.org/repository/release/ + + + + + org.slf4j + jcl-over-slf4j + 1.7.5 + + + commons-logging + commons-logging + + + org.slf4j slf4j-api @@ -28,16 +47,45 @@ org.slf4j slf4j-log4j12 - - org.jdom - jdom2 - 2.0.5 - - com.sun.jersey + org.glassfish.jersey.containers + jersey-container-servlet + ${jersey-version} + + + org.glassfish.jersey.core jersey-server - 1.9.1 + ${jersey-version} + + org.glassfish.jersey.inject + jersey-hk2 + ${jersey-version} + + + org.glassfish.jersey.ext + jersey-spring5 + 2.31 + + + + + org.apache.commons + commons-lang3 + 3.8.1 + + + org.ow2.asm + asm + ${asm-version} + + + org.ow2.asm + asm-commons + ${asm-version} + + + org.springframework spring-expression @@ -59,16 +107,6 @@ spring-security-taglibs ${spring.security.version} - - com.sun.jersey.contribs - jersey-spring - 1.9.1 - - - com.sun.jersey - jersey-bundle - 1.10 - junit junit @@ -78,13 +116,12 @@ org.mockito mockito-core - 1.9.0-rc1 + 3.3.3 mysql mysql-connector-java - 5.1.17 org.tuckey @@ -197,8 +234,7 @@ org.onebusaway onebusaway-collections - - 1.2.0 + ${collections-version} @@ -210,6 +246,12 @@ org.geotools gt-main ${geotools.version} + + + com.fasterxml.jackson.core + jackson-core + + org.geotools @@ -217,23 +259,16 @@ ${geotools.version} - - org.geotools - gt-epsg-hsql - ${geotools.version} - - - hsqldb - hsqldb - - - log4j log4j 1.2.16 + + org.slf4j + slf4j-log4j12 + log4j apache-log4j-extras @@ -293,24 +328,34 @@ com.fasterxml.jackson.core jackson-databind - 2.9.10.1 + ${jackson-version} org.apache.commons commons-csv 1.1 - - com.googlecode.json-simple - json-simple - 1.1 - jar - - - org.mitre.dsmiley.httpproxy - smiley-http-proxy-servlet - 1.7 - + + com.googlecode.json-simple + json-simple + 1.1 + jar + + + org.codehaus.jackson + jackson-mapper-asl + + + org.codehaus.jackson + jackson-core-asl + + + + + org.mitre.dsmiley.httpproxy + smiley-http-proxy-servlet + 1.7 + joda-time @@ -332,11 +377,6 @@ war - - com.google.guava - guava - 27.1-jre - com.google.guava guava diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/bundle/StagingBundleProvider.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/bundle/StagingBundleProvider.java index dcb6d3222f..51a459cbc6 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/bundle/StagingBundleProvider.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/bundle/StagingBundleProvider.java @@ -18,9 +18,8 @@ import java.io.File; import java.io.FileNotFoundException; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.onebusaway.admin.bundle.model.BundleMetadata; -import org.onebusaway.transit_data_federation.model.bundle.BundleItem; public class StagingBundleProvider { private static final String META_DATA_LOCATION = "metadata.json"; diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/event/handler/LoginEventListener.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/event/handler/LoginEventListener.java index e444fa32e2..c4aea299ff 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/event/handler/LoginEventListener.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/event/handler/LoginEventListener.java @@ -33,10 +33,21 @@ public class LoginEventListener implements ApplicationListener loadShapeFile( "EPSG", hints); CoordinateReferenceSystem worldCRS = factory.createCoordinateReferenceSystem("EPSG:4326"); - DefaultQuery query = new DefaultQuery(typeName); + Query query = new Query(typeName); query.setCoordinateSystem(sourceCRS); query.setCoordinateSystemReproject(worldCRS); query.setHints(hints); diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/BundleBuildResponseDaoImpl.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/BundleBuildResponseDaoImpl.java index 3904f48de5..2679148364 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/BundleBuildResponseDaoImpl.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/BundleBuildResponseDaoImpl.java @@ -50,7 +50,6 @@ public class BundleBuildResponseDaoImpl implements BundleBuildResponseDao { private SessionFactory _sessionFactory; @Autowired - @Qualifier("bundleBuildResponseSessionFactory") public void setSessionFactory(SessionFactory sessionFactory) { _sessionFactory = sessionFactory; } @@ -60,35 +59,31 @@ private Session getSession(){ } @Override - @Transactional + @Transactional(value="transactionManager", rollbackFor = Throwable.class) public void saveOrUpdate(BundleBuildResponse bundleBuildResponse) { getSession().saveOrUpdate(bundleBuildResponse); } @Override - @Transactional + @Transactional(value="transactionManager", rollbackFor = Throwable.class, readOnly = true) public BundleBuildResponse getBundleBuildResponseForId(String id) { Session session = getSession(); - Transaction tx = session.beginTransaction(); List responses; - Query query = getSession() + Query query = session .createQuery("from BundleBuildResponse where id=:id"); query.setParameter("id", id); responses = query.list(); BundleBuildResponse bbr = responses.get(0); - tx.commit(); return bbr; } @Override - @Transactional + @Transactional(readOnly = true) public int getBundleBuildResponseMaxId() { int maxId = 0; Session session = getSession(); - Transaction tx = session.beginTransaction(); List bundleIds = session.createCriteria(BundleBuildResponse.class) .setProjection(Projections.property("id")).list(); - tx.commit(); for (String bundleId : bundleIds) { int thisId = Integer.parseInt(bundleId); maxId = (thisId > maxId) ? thisId : maxId; diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/BundleBuildingServiceImpl.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/BundleBuildingServiceImpl.java index 694eaeb9c7..c95a966725 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/BundleBuildingServiceImpl.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/BundleBuildingServiceImpl.java @@ -130,7 +130,8 @@ public void setup() { @PreDestroy public void stop() { - _executorService.shutdownNow(); + if (_executorService != null) + _executorService.shutdownNow(); } public void setAuxConfig(String flag) { diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/GtfsArchiveDaoImpl.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/GtfsArchiveDaoImpl.java index cf30b1082f..2adbd8f962 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/GtfsArchiveDaoImpl.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/GtfsArchiveDaoImpl.java @@ -48,7 +48,6 @@ public class GtfsArchiveDaoImpl implements GtfsArchiveDao { private SessionFactory _sessionFactory; @Autowired - @Qualifier("gtfsRealtimeArchiveSessionFactory") public void setSessionFactory(SessionFactory sessionFactory) { _sessionFactory = sessionFactory; } diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/LocalBundleDeployerServiceImpl.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/LocalBundleDeployerServiceImpl.java index 975b85c25c..6ff17aedf8 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/LocalBundleDeployerServiceImpl.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/LocalBundleDeployerServiceImpl.java @@ -39,9 +39,9 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.StreamingOutput; -import org.codehaus.jackson.JsonGenerator; -import org.codehaus.jackson.map.MappingJsonFactory; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.MappingJsonFactory; +import com.fasterxml.jackson.databind.ObjectMapper; import org.joda.time.LocalDate; import org.json.JSONObject; import org.onebusaway.admin.bundle.BundleProvider; @@ -57,10 +57,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Scope; +import org.springframework.http.ContentDisposition; import org.springframework.stereotype.Component; -import com.sun.jersey.core.header.ContentDisposition; - @Component @Qualifier("localBundleDeployerImpl") @Scope("singleton") @@ -297,8 +296,8 @@ public void write(OutputStream os) throws IOException, } }; - ContentDisposition cd = ContentDisposition.type("file").fileName( - requestedFile.getName()).build(); + ContentDisposition cd = ContentDisposition.builder("file").filename(requestedFile.getName()).build(); + Response response = Response.ok(output, MediaType.APPLICATION_OCTET_STREAM).header( "Content-Disposition", cd).header("Content-Length", fileLength).build(); diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/LocalBundleStagerServiceImpl.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/LocalBundleStagerServiceImpl.java index ef23fe1db1..37e359acf2 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/LocalBundleStagerServiceImpl.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/LocalBundleStagerServiceImpl.java @@ -39,9 +39,9 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.StreamingOutput; -import org.codehaus.jackson.JsonGenerator; -import org.codehaus.jackson.map.MappingJsonFactory; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.MappingJsonFactory; +import com.fasterxml.jackson.databind.ObjectMapper; import org.onebusaway.admin.bundle.BundleProvider; import org.onebusaway.admin.bundle.BundlesListMessage; import org.onebusaway.admin.bundle.model.Bundle; @@ -54,9 +54,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Scope; +import org.springframework.http.ContentDisposition; import org.springframework.stereotype.Component; -import com.sun.jersey.core.header.ContentDisposition; @Component @Scope("singleton") @@ -231,8 +231,8 @@ public void write(OutputStream os) throws IOException, } }; - ContentDisposition cd = ContentDisposition.type("file").fileName( - requestedFile.getName()).build(); + + ContentDisposition cd = ContentDisposition.builder("file").filename(requestedFile.getName()).build(); Response response = Response.ok(output, MediaType.APPLICATION_OCTET_STREAM).header( "Content-Disposition", cd).header("Content-Length", fileLength).build(); diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/TdmBundleDeployerServiceImpl.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/TdmBundleDeployerServiceImpl.java index 0f3256f006..5f83e96cbe 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/TdmBundleDeployerServiceImpl.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/impl/TdmBundleDeployerServiceImpl.java @@ -21,7 +21,7 @@ import javax.annotation.PostConstruct; import javax.ws.rs.core.Response; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.onebusaway.admin.service.BundleDeployerService; import org.onebusaway.admin.service.RemoteConnectionService; import org.onebusaway.admin.service.bundle.api.BundleResource; diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/task/GtfsValidationTask.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/task/GtfsValidationTask.java index 86b347c7a7..8b32b9e5e8 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/task/GtfsValidationTask.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/task/GtfsValidationTask.java @@ -69,12 +69,14 @@ public void run() { GtfsValidationService service = new GtfsValidationService(_dao); ValidationResult vr = service.validateRoutes(); log(vr, filename); - vr = service.validateTrips(); - log(vr, filename); - vr = service.duplicateStops(); - log(vr, filename); - vr = service.listReversedTripShapes(); - log(vr, filename); + // TODO GTFSValidationService needs to be updated to use latest JTS + // Until then these methods conflict with geospatial's JTS. + //vr = service.validateTrips(); + //log(vr, filename); + //vr = service.duplicateStops(); + //log(vr, filename); + //vr = service.listReversedTripShapes(); + //log(vr, filename); } catch (Exception any) { // don't let validation issues break the build diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/task/MetadataTask.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/task/MetadataTask.java index 44b8ecc491..9fb9f88d82 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/task/MetadataTask.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/bundle/task/MetadataTask.java @@ -18,7 +18,7 @@ import java.io.File; import java.util.UUID; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.onebusaway.admin.bundle.model.BundleMetadata; import org.onebusaway.admin.model.BundleRequestResponse; import org.onebusaway.admin.service.bundle.impl.BundleBuildingUtil; diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/DiskFileServiceImpl.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/DiskFileServiceImpl.java index b68b7573da..0746febd2a 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/DiskFileServiceImpl.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/DiskFileServiceImpl.java @@ -125,24 +125,32 @@ public boolean deleteBundleDirectory(String filename) { @Override public List listBundleDirectories(int maxResults) { ArrayList bundleDirs = new ArrayList(); - File baseDir = new File(_basePath); - String[] list = baseDir.list(); - if (list == null) { - _log.info("empty list for bundleDirectories at basepath=" + _basePath); - return bundleDirs; - } - // need filename/flag/modified date - for (String dir: list) { - File fDir = new File(baseDir, dir); - String lastModified = new Date(fDir.lastModified()).toString(); - // Since the bundle directory date does not get updated when a build - // is done, get the date on the builds sub-directory. - File buildDir = new File(fDir, _buildPath); - if (buildDir.exists()) { - lastModified = new Date(buildDir.lastModified()).toString(); + _log.info("listBundleDirectories(" + maxResults + ")"); + try { + File baseDir = new File(_basePath); + String[] list = baseDir.list(); + if (list == null) { + _log.info("empty list for bundleDirectories at basepath=" + _basePath); + return bundleDirs; + } + // need filename/flag/modified date + for (String dir : list) { + _log.info("bundle dir: |" + dir + "|"); + File fDir = new File(baseDir, dir); + String lastModified = new Date(fDir.lastModified()).toString(); + // Since the bundle directory date does not get updated when a build + // is done, get the date on the builds sub-directory. + File buildDir = new File(fDir, _buildPath); + if (buildDir.exists()) { + lastModified = new Date(buildDir.lastModified()).toString(); + } + String[] a = {dir, " ", lastModified}; + bundleDirs.add(a); } - String[] a = {dir, " ", lastModified}; - bundleDirs.add(a); + } catch (Throwable t) { + _log.error("Exception retrieving listBundleDiretories=", t, t); + } finally { + _log.info("exiting listBundleDirectories"); } return bundleDirs; } diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/RemoteConnectionServiceImpl.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/RemoteConnectionServiceImpl.java index 60509503da..d361d07f83 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/RemoteConnectionServiceImpl.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/RemoteConnectionServiceImpl.java @@ -33,12 +33,11 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.UniformInterfaceException; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.config.ClientConfig; -import com.sun.jersey.api.client.config.DefaultClientConfig; - +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; @Component public class RemoteConnectionServiceImpl implements RemoteConnectionService { @@ -128,17 +127,13 @@ public String getContent(String url) { @Override public T postBinaryData(String url, File data, Class responseType) { T response = null; - - ClientConfig config = new DefaultClientConfig(); - Client client = Client.create(config); - WebResource resource = client.resource(url); - + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(url); + try { - response = resource.accept("text/csv").type("text/csv") - .post(responseType, new FileInputStream(data)); - } catch (UniformInterfaceException e) { - log.error("Unable to read response from the server."); - e.printStackTrace(); + target.request() + .accept("text/csv").accept("text/csv") + .post(Entity.entity(new FileInputStream(data), MediaType.APPLICATION_OCTET_STREAM), responseType); } catch (FileNotFoundException e) { log.error("CSV File not found. It is not uploaded correctly"); e.printStackTrace(); diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/UserManagementServiceImpl.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/UserManagementServiceImpl.java index 7e2cee06d8..8376fcf4dc 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/UserManagementServiceImpl.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/UserManagementServiceImpl.java @@ -16,7 +16,6 @@ package org.onebusaway.admin.service.impl; import java.math.BigDecimal; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -24,16 +23,15 @@ import org.apache.commons.lang.StringUtils; import org.hibernate.Criteria; -import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; -import org.hibernate.criterion.Order; import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.onebusaway.admin.model.ui.UserDetail; import org.onebusaway.admin.service.UserManagementService; import org.onebusaway.users.client.model.UserBean; +import org.onebusaway.users.impl.authentication.VersionedPasswordEncoder; import org.onebusaway.users.model.User; import org.onebusaway.users.model.UserIndex; import org.onebusaway.users.model.UserRole; @@ -41,7 +39,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.authentication.encoding.PasswordEncoder; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -55,11 +52,10 @@ public class UserManagementServiceImpl implements UserManagementService { private SessionFactory _sessionFactory; private StandardAuthoritiesService authoritiesService; - private UserPropertiesService userPropertiesService; + private UserPropertiesService userPropertiesService; private UserDao userDao; private UserService userService; - private PasswordEncoder passwordEncoder; - + private VersionedPasswordEncoder passwordEncoder; private static final Logger log = LoggerFactory.getLogger(UserManagementServiceImpl.class); @@ -269,6 +265,7 @@ public boolean updateUser(UserDetail userDetail) { //Update user password if(StringUtils.isNotBlank(userDetail.getPassword())) { + // this is done for backward compatibility with Spring 3 String credentials = passwordEncoder.encodePassword(userDetail.getPassword(), userDetail.getUsername()); for(UserIndex userIndex : user.getUserIndices()) { userIndex.setCredentials(credentials); @@ -410,7 +407,7 @@ public void setUserService(UserService userService) { * @param passwordEncoder the passwordEncoder to set */ @Autowired - public void setPasswordEncoder(PasswordEncoder passwordEncoder) { + public void setPasswordEncoder(VersionedPasswordEncoder passwordEncoder) { this.passwordEncoder = passwordEncoder; } diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/VehicleStatusServiceImpl.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/VehicleStatusServiceImpl.java index 52c5f783cb..b074b249b4 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/VehicleStatusServiceImpl.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/impl/VehicleStatusServiceImpl.java @@ -26,9 +26,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; import org.json.JSONArray; import org.json.JSONException; import org.onebusaway.admin.comparator.InferredPhaseComparator; diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/server/impl/BundleServerServiceImpl.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/server/impl/BundleServerServiceImpl.java index 13e5e7d8b8..603fa61eff 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/server/impl/BundleServerServiceImpl.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/server/impl/BundleServerServiceImpl.java @@ -24,12 +24,12 @@ import javax.annotation.PostConstruct; import javax.servlet.ServletContext; -import org.codehaus.jackson.JsonGenerator; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.MappingJsonFactory; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.MappingJsonFactory; +import com.fasterxml.jackson.databind.ObjectMapper; import org.onebusaway.admin.service.RemoteConnectionService; import org.onebusaway.admin.service.server.BundleServerService; import org.slf4j.Logger; @@ -79,7 +79,7 @@ public void setEc2Password(String password) { @PostConstruct @Override public void setup() { - _mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); + _mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); try { if (_isAws) { diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/server/impl/CleverServiceAlertsServiceImpl.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/server/impl/CleverServiceAlertsServiceImpl.java index dfca0d3b98..b1351f7987 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/server/impl/CleverServiceAlertsServiceImpl.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/service/server/impl/CleverServiceAlertsServiceImpl.java @@ -357,7 +357,9 @@ void runPollDMTask() { private class PollDMTask implements Runnable { @Override public void run() { - runPollDMTask(); + if (_cleverAPIUrlString != null) { + runPollDMTask(); + } } } diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/util/LocalizationListener.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/util/LocalizationListener.java index 3594f2cc03..2adaa7a440 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/util/LocalizationListener.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/admin/util/LocalizationListener.java @@ -19,10 +19,12 @@ import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; +import com.opensymphony.xwork2.util.GlobalLocalizedTextProvider; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.opensymphony.xwork2.util.LocalizedTextUtil; + /** * Listen for context configuration for localization. Default to @@ -43,10 +45,11 @@ public void contextInitialized(ServletContextEvent servletContextEvent) { String resource = (String) servletContext.getInitParameter("obanyc.resource"); if (resource != null) { _log.info("found resource override=" + resource); - LocalizedTextUtil.addDefaultResourceBundle(resource); + new GlobalLocalizedTextProvider().addDefaultResourceBundle(resource); } else { _log.info("did not find resource override, using default localization of " + DEFAULT_RESOURCE); - LocalizedTextUtil.addDefaultResourceBundle(DEFAULT_RESOURCE); + // nothing to do + //LocalizedTextUtil.addDefaultResourceBundle(DEFAULT_RESOURCE); } } diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/ForgotPasswordAction.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/ForgotPasswordAction.java index 0b69b55b62..b4320ec37f 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/ForgotPasswordAction.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/ForgotPasswordAction.java @@ -78,10 +78,10 @@ public String execute() { try { _mailSender.send(msg); _log.info("Sent email."); - } catch(Exception e) { + } catch(Throwable e) { _log.error(e.toString(), e); _log.error("Could not send email: " + e.getMessage()); - throw new RuntimeException("Unable to send email."); + throw new RuntimeException("Unable to send email: " + e.toString()); } return SUCCESS; } diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/BarcodeAction.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/BarcodeAction.java index 1503480653..bcf02f76ac 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/BarcodeAction.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/BarcodeAction.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; +import org.apache.struts2.convention.annotation.AllowedMethods; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; import org.onebusaway.admin.service.BarcodeService; @@ -36,6 +37,7 @@ "contentDisposition", "attachment;fileName=\"qrBatch.zip\"", "bufferSize", "1024"}) }) +@AllowedMethods({"genBusStopCode", "generateCodesBatch"}) public class BarcodeAction extends OneBusAwayNYCAdminActionSupport { private static Logger _log = LoggerFactory.getLogger(BarcodeAction.class); private static final long serialVersionUID = 1L; diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/agencymetadata/AgencyMetadataEditAction.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/agencymetadata/AgencyMetadataEditAction.java index ce5491bbd0..414c4ffc8a 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/agencymetadata/AgencyMetadataEditAction.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/agencymetadata/AgencyMetadataEditAction.java @@ -18,6 +18,7 @@ import java.io.IOException; import org.apache.struts2.convention.annotation.Action; +import org.apache.struts2.convention.annotation.AllowedMethods; import org.apache.struts2.convention.annotation.ParentPackage; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; @@ -40,7 +41,7 @@ @Result(type = "redirectAction", name = "cancelResult", params = { "actionName", "agency-metadata", "id", "${id}", "parse", "true"}) }) - +@AllowedMethods({"submit", "cancel", "deleteAgencyMetadata"}) public class AgencyMetadataEditAction extends ActionSupport implements ModelDriven { private static final long serialVersionUID = 1L; diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/apikeymanagement/ApiKeyAction.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/apikeymanagement/ApiKeyAction.java index 8e21ed7510..a3e2a42aab 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/apikeymanagement/ApiKeyAction.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/apikeymanagement/ApiKeyAction.java @@ -17,6 +17,7 @@ import java.util.List; +import org.apache.struts2.convention.annotation.AllowedMethods; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; import org.onebusaway.presentation.impl.NextActionSupport; @@ -36,6 +37,7 @@ */ @Results({@Result(type = "redirectAction", name = "redirect", params = { "actionName", "api-key"})}) +@AllowedMethods({"saveAPIKey", "searchAPIKey", "searchContactEmail", "deleteAPIKey"}) public class ApiKeyAction extends NextActionSupport{ private static final long serialVersionUID = 1L; diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/apikeymanagement/ListApiKeysAction.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/apikeymanagement/ListApiKeysAction.java index e66e704de5..35d50bde0f 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/apikeymanagement/ListApiKeysAction.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/apikeymanagement/ListApiKeysAction.java @@ -15,6 +15,7 @@ */ package org.onebusaway.webapp.actions.admin.apikeymanagement; +import org.apache.struts2.convention.annotation.AllowedMethods; import org.onebusaway.users.client.model.UserBean; import org.onebusaway.users.model.User; import org.onebusaway.users.services.UserService; @@ -26,6 +27,7 @@ import java.util.ArrayList; import java.util.List; +@AllowedMethods({"firstPage", "nextPage", "previousPage"}) public class ListApiKeysAction extends OneBusAwayNYCAdminActionSupport { private static Logger log = LoggerFactory.getLogger(ListApiKeysAction.class); diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/bundles/ManageBundlesAction.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/bundles/ManageBundlesAction.java index 12bfc3eb5c..02895f1488 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/bundles/ManageBundlesAction.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/bundles/ManageBundlesAction.java @@ -43,6 +43,7 @@ import javax.servlet.ServletContext; +import org.apache.struts2.convention.annotation.AllowedMethods; import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; @@ -108,6 +109,9 @@ "contentDisposition", "attachment;filename=\"${downloadFilename}\"", "bufferSize", "1024"}) }) +@AllowedMethods({"selectDirectory", "copyDirectory", "deleteDirectory", "createDirectory", + "fileList", "updateBundleComments", "existingBuildList", "download", "buildList", + "buildOutputZip", "downloadOutputFile", "downloadBundle", "downloadValidateFile"}) public class ManageBundlesAction extends OneBusAwayNYCAdminActionSupport implements ServletContextAware { private static Logger _log = LoggerFactory.getLogger(ManageBundlesAction.class); private static final long serialVersionUID = 1L; @@ -319,13 +323,21 @@ private DirectoryStatus createDirectoryStatus(String statusMessage, boolean sele * @return list of existing directories */ public Set getExistingDirectories() { + _log.info("enter getExistingDirectories"); + Set directories = new TreeSet(); + try { + List existingDirectories = fileService.listBundleDirectories(MAX_RESULTS); - List existingDirectories = fileService.listBundleDirectories(MAX_RESULTS); - Set directories = new TreeSet (); - for(String[] existingDirectory : existingDirectories) { - ExistingDirectory directory = new ExistingDirectory(existingDirectory[0], existingDirectory[1], - existingDirectory[2]); - directories.add(directory); + for (String[] existingDirectory : existingDirectories) { + ExistingDirectory directory = new ExistingDirectory(existingDirectory[0], existingDirectory[1], + existingDirectory[2]); + _log.info("directory=" + directory); + directories.add(directory); + } + } catch (Throwable t) { + _log.error("getExistingDirectories exception=" + t, t); + } finally { + _log.info("exit getExistingDirectories"); } return directories; } @@ -336,12 +348,21 @@ public Set getExistingDirectories() { * @return list of existing directories */ public Set getSortedByDateDirectories() { - Set directories = getExistingDirectories(); - // Resort by date - Set sortedDirectories - = new TreeSet(new DirectoryByDateComp()); - sortedDirectories.addAll(directories); - return sortedDirectories; + Set directories = getExistingDirectories(); + _log.error("getSortedByDateDirectories existing directories input=" + directories); + try { + // Resort by date + Set sortedDirectories + = new TreeSet(new DirectoryByDateComp()); + sortedDirectories.addAll(directories); + _log.info("sorted directories output=" + sortedDirectories); + return sortedDirectories; + } catch (Throwable t) { + _log.error("getSortedByDateDirectories exception sorting directory ", t, t); + return directories; + } finally { + _log.info("getSortedByDateDirectories exit"); + } } public SortedSet getExistingArchivedDirectories() { @@ -497,7 +518,11 @@ public String buildOutputZip() { public String downloadOutputFile() { _log.info("downloadOutputFile with id=" + id + " and file=" + this.downloadFilename); fileService.validateFileName(downloadFilename); - this.bundleBuildResponse = this.bundleRequestService.lookupBuildRequest(getId()); + try { + this.bundleBuildResponse = this.bundleRequestService.lookupBuildRequest(getId()); + } catch (Throwable t) { + _log.error("transaction issue " + t, t); + } if (this.bundleBuildResponse != null) { String dir = bundleBuildResponse.getRemoteOutputDirectory(); if (dir == null) { @@ -816,19 +841,28 @@ public int compare(ExistingDirectory ed1, ExistingDirectory ed2) { private int unsafeCompare(ExistingDirectory ed1, ExistingDirectory ed2) throws Exception { // ExistingDirectory.creationTimestamp is a String 'dow mon dd hh:mm:ss zzz yyyy' - String[] ed1Split = ed1.getCreationTimestamp().split(" "); - String[] ed2Split = ed2.getCreationTimestamp().split(" "); - SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss dd-MMM-yyyy"); - Date ed1Date = new Date(); - Date ed2Date = new Date(); - ed1Date = formatter.parse(ed1Split[3] - + " " + ed1Split[2] + "-" + ed1Split[1] - + "-" + ed1Split[5]); - ed2Date = formatter.parse(ed2Split[3] - + " " + ed2Split[2] + "-" + ed2Split[1] - + "-" + ed2Split[5]); - _log.info("" + ed1Date + " ?= " + ed2Date); - return ed1Date.compareTo(ed2Date) * -1; + try { + String[] ed1Split = ed1.getCreationTimestamp().split(" "); + String[] ed2Split = ed2.getCreationTimestamp().split(" "); + SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss dd-MMM-yyyy"); + Date ed1Date = new Date(); + Date ed2Date = new Date(); + ed1Date = formatter.parse(ed1Split[3] + + " " + ed1Split[2] + "-" + ed1Split[1] + + "-" + ed1Split[5]); + ed2Date = formatter.parse(ed2Split[3] + + " " + ed2Split[2] + "-" + ed2Split[1] + + "-" + ed2Split[5]); + _log.info("" + ed1Date + " ?= " + ed2Date); + int difference = ed1Date.compareTo(ed2Date) * -1; + if (difference == 0) { + return ed1.getName().compareTo(ed2.getName()); + } + return difference; + } catch (Throwable t) { + _log.error("date issue " + t + " for ed1=" + ed1 + " and ed2=" + ed2, t); + return -1; + } } } diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/bundles/ScheduleTimeResultChecker.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/bundles/ScheduleTimeResultChecker.java index 0b00976b6b..0ba4a8e146 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/bundles/ScheduleTimeResultChecker.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/bundles/ScheduleTimeResultChecker.java @@ -26,10 +26,10 @@ import java.util.Set; import java.util.TimeZone; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.SerializationConfig; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.MapperFeature; import org.onebusaway.admin.model.BundleValidateQuery; import org.onebusaway.admin.model.BundleValidationCheckResult; import org.slf4j.Logger; @@ -51,7 +51,7 @@ public BundleValidationCheckResult checkResults(BundleValidateQuery query) { ObjectMapper mapper = new ObjectMapper(); BundleValidationCheckResult checkResult = new BundleValidationCheckResult(); String result = query.getQueryResult(); - mapper.configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS, true); + mapper.configure(MapperFeature.AUTO_DETECT_FIELDS, true); Map parsedResult = new HashMap(); boolean parseFailed = false; try { diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/bundles/StopForRouteResultChecker.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/bundles/StopForRouteResultChecker.java index 2200fdff9e..1e1386a9b4 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/bundles/StopForRouteResultChecker.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/bundles/StopForRouteResultChecker.java @@ -23,10 +23,10 @@ import java.util.HashMap; import java.util.Map; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.SerializationConfig; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.MapperFeature; import org.onebusaway.admin.model.BundleValidateQuery; import org.onebusaway.admin.model.BundleValidationCheckResult; import org.slf4j.Logger; @@ -47,7 +47,7 @@ public BundleValidationCheckResult checkResults(BundleValidateQuery query) { ObjectMapper mapper = new ObjectMapper(); BundleValidationCheckResult checkResult = new BundleValidationCheckResult(); String result = query.getQueryResult(); - mapper.configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS, true); + mapper.configure(MapperFeature.AUTO_DETECT_FIELDS, true); Map parsedResult = new HashMap(); boolean parseFailed = false; try { diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertAction.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertAction.java index 4887410e39..78ba775d53 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertAction.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertAction.java @@ -22,6 +22,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.struts2.convention.annotation.Action; +import org.apache.struts2.convention.annotation.AllowedMethods; import org.apache.struts2.convention.annotation.InterceptorRef; import org.apache.struts2.convention.annotation.InterceptorRefs; import org.apache.struts2.convention.annotation.ParentPackage; @@ -38,7 +39,6 @@ import org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean; import org.onebusaway.transit_data.model.service_alerts.SituationConsequenceBean; import org.onebusaway.transit_data.model.service_alerts.TimeRangeBean; -import org.onebusaway.transit_data.services.TransitDataService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -64,6 +64,7 @@ @Result(type = "redirectAction", name = "addToFavoritesSuccess", params = { "actionName", "service-alerts", "id", "${id}", "parse", "true"}) }) +@AllowedMethods({"submit", "cancel", "addToFavorites", "addAffects", "delete"}) public class ServiceAlertAction extends ActionSupport implements ModelDriven, Preparable { @@ -430,7 +431,7 @@ public void prepare() throws Exception { } } -@Override + @Override public String execute() throws IOException, JSONException, ParseException { _log.info("ServiceAlerts.execute()"); diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertAffectsAction.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertAffectsAction.java index b379865fb0..7c1f9fae91 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertAffectsAction.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertAffectsAction.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Set; +import org.apache.struts2.convention.annotation.AllowedMethods; import org.apache.struts2.convention.annotation.InterceptorRef; import org.apache.struts2.convention.annotation.InterceptorRefs; import org.apache.struts2.convention.annotation.Result; @@ -49,6 +50,7 @@ @Result(type = "redirectAction", name="input", params = {"actionName", "service-alert", "id", "${id}"}), @Result(type = "redirectAction", params = { "actionName", "service-alert", "id", "${id}", "parse", "true"})}) +@AllowedMethods({"update", "delete"}) public class ServiceAlertAffectsAction extends ActionSupport implements ModelDriven { diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertEditAction.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertEditAction.java index 27b8156c26..2b50b4b994 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertEditAction.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertEditAction.java @@ -19,8 +19,7 @@ import java.text.SimpleDateFormat; import java.util.*; -import org.apache.struts2.convention.annotation.InterceptorRef; -import org.apache.struts2.convention.annotation.InterceptorRefs; +import org.apache.struts2.convention.annotation.AllowedMethods; import org.apache.struts2.convention.annotation.ParentPackage; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; @@ -57,7 +56,7 @@ params={"root", "twitterResult"}), }) - +@AllowedMethods({"deleteAlert", "tweetAlert"}) public class ServiceAlertEditAction extends OneBusAwayNYCAdminActionSupport implements ModelDriven { private static Logger _log = LoggerFactory.getLogger(ServiceAlertEditAction.class); diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertsAction.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertsAction.java index 969fa8284a..20bb531c4a 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertsAction.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/servicealerts/ServiceAlertsAction.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.List; +import org.apache.struts2.convention.annotation.AllowedMethods; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; import org.apache.struts2.interceptor.validation.SkipValidation; @@ -42,6 +43,7 @@ @Results({@Result(type = "redirectAction", name = "redirect", params = { "actionName", "service-alerts!agency", "agencyId", "${agencyId}", "parse", "true"})}) +@AllowedMethods({"agency", "deleteAlert", "removeAllForAgency"}) public class ServiceAlertsAction extends OneBusAwayNYCAdminActionSupport { private static final long serialVersionUID = 1L; diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/usermanagement/ManageUsersAction.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/usermanagement/ManageUsersAction.java index 6c3c1de5e2..f32163648e 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/usermanagement/ManageUsersAction.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/usermanagement/ManageUsersAction.java @@ -19,6 +19,7 @@ import java.util.List; import org.apache.commons.lang3.StringUtils; +import org.apache.struts2.convention.annotation.AllowedMethods; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; import org.onebusaway.admin.json.JsonTool; @@ -38,7 +39,7 @@ @Result(name="updateUser", type="json", params= {"root","updateUserMessage"}) }) - +@AllowedMethods({"editUser", "inactivateUser", "activateUser", "deleteUser"}) public class ManageUsersAction extends OneBusAwayNYCAdminActionSupport { private static final long serialVersionUID = 1L; diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/usermanagement/RegisterUserAction.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/usermanagement/RegisterUserAction.java index 1b5a3a7524..770611c671 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/usermanagement/RegisterUserAction.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/usermanagement/RegisterUserAction.java @@ -16,6 +16,7 @@ package org.onebusaway.webapp.actions.admin.usermanagement; import org.apache.commons.lang.StringUtils; +import org.apache.struts2.convention.annotation.AllowedMethods; import org.onebusaway.admin.service.UserManagementService; import org.onebusaway.webapp.actions.OneBusAwayNYCAdminActionSupport; import org.springframework.beans.factory.annotation.Autowired; @@ -28,6 +29,7 @@ * @author abelsare * */ +@AllowedMethods(value="createUser") public class RegisterUserAction extends OneBusAwayNYCAdminActionSupport { private static final long serialVersionUID = 1L; diff --git a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/usermanagement/UpdatePasswordAction.java b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/usermanagement/UpdatePasswordAction.java index 64b172f686..872dcab318 100644 --- a/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/usermanagement/UpdatePasswordAction.java +++ b/onebusaway-admin-webapp/src/main/java/org/onebusaway/webapp/actions/admin/usermanagement/UpdatePasswordAction.java @@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; +import org.apache.struts2.convention.annotation.AllowedMethods; import org.onebusaway.admin.model.ui.UserDetail; import org.onebusaway.admin.service.TemporaryPasswordService; import org.onebusaway.admin.service.UserManagementService; @@ -27,7 +28,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; - +@AllowedMethods({"updatePassword"}) public class UpdatePasswordAction extends OneBusAwayNYCAdminActionSupport { private static final long serialVersionUID = 1L; diff --git a/onebusaway-admin-webapp/src/main/resources/data-sources.xml b/onebusaway-admin-webapp/src/main/resources/data-sources.xml index a92435c14a..b0a32df8d2 100644 --- a/onebusaway-admin-webapp/src/main/resources/data-sources.xml +++ b/onebusaway-admin-webapp/src/main/resources/data-sources.xml @@ -17,10 +17,11 @@ --> + http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> @@ -45,36 +46,16 @@ - - - - - - - - + + + + + + - - - - - - - - - + + - - - - - - - - - - - - - - - - - @@ -170,99 +122,7 @@ - - - - - org.onebusaway.agency_metadata.model.AgencyMetadata - org.onebusaway.agency_metadata.service.AgencyMetadataDaoImpl - - - - - org.hibernate.dialect.MySQLDialect - 1 - - org.hibernate.cache.internal.NoCachingRegionFactory - false - update - 1000 - - - - - - - - org.onebusaway.admin.model.BundleBuildResponse - org.onebusaway.admin.service.bundle.impl.BundleBuildResponseDaoImpl - - - - - org.hibernate.dialect.MySQLDialect - 1 - - org.hibernate.cache.internal.NoCachingRegionFactory - false - update - 1000 - - - - - - - - - org.onebusaway.admin.service.bundle.task.model.GtfsBundleInfo - org.onebusaway.admin.service.bundle.impl.GtfsArchiveDaoImpl - - - - - 1 - - org.hibernate.cache.internal.NoCachingRegionFactory - false - none - 1000 - false - false - - - - - org/onebusaway/gtfs/model/GtfsArchiveMapping.hibernate.xml - - - - - - - - org.onebusaway.admin.model.assignments.Assignment - org.onebusaway.admin.model.assignments.AssignmentConfig - org.onebusaway.admin.service.assignments.impl.AssignmentDaoImpl - org.onebusaway.admin.service.assignments.impl.AssignmentConfigDaoImpl - - - - - org.hibernate.dialect.MySQLDialect - 1 - - org.hibernate.cache.internal.NoCachingRegionFactory - false - update - 1000 - - - @@ -281,21 +141,21 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -305,7 +165,7 @@ - + diff --git a/onebusaway-admin-webapp/src/main/resources/log4j.xml b/onebusaway-admin-webapp/src/main/resources/log4j.xml index 678514e768..b094bf4c6f 100644 --- a/onebusaway-admin-webapp/src/main/resources/log4j.xml +++ b/onebusaway-admin-webapp/src/main/resources/log4j.xml @@ -26,7 +26,7 @@ - + diff --git a/onebusaway-admin-webapp/src/main/resources/org/onebusaway/admin/webapp/application-context-webapp.xml b/onebusaway-admin-webapp/src/main/resources/org/onebusaway/admin/webapp/application-context-webapp.xml index 1cb81c7b66..1fb3a018a9 100644 --- a/onebusaway-admin-webapp/src/main/resources/org/onebusaway/admin/webapp/application-context-webapp.xml +++ b/onebusaway-admin-webapp/src/main/resources/org/onebusaway/admin/webapp/application-context-webapp.xml @@ -21,11 +21,12 @@ xmlns:sec="http://www.springframework.org/schema/security" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> + @@ -35,6 +36,7 @@ + @@ -48,15 +50,31 @@ - org.onebusaway.transit_data_federation.impl.realtime.BlockLocationRecord - org.onebusaway.transit_data_federation.impl.realtime.history.ScheduleDeviationHistory - org.onebusaway.transit_data_federation.impl.reporting.StopProblemReportRecord - org.onebusaway.transit_data_federation.impl.reporting.TripProblemReportRecord + org.onebusaway.admin.model.BundleBuildResponse + org.onebusaway.admin.service.bundle.impl.BundleBuildResponseDaoImpl + org.onebusaway.admin.model.assignments.Assignment + org.onebusaway.admin.model.assignments.AssignmentConfig + + org.onebusaway.admin.service.bundle.task.model.GtfsBundleInfo + org.onebusaway.admin.service.bundle.impl.GtfsArchiveDaoImpl + + + + + org.onebusaway.agency_metadata.model.AgencyMetadata + org.onebusaway.agency_metadata.service.AgencyMetadataDaoImpl + org.onebusaway.alerts.impl.ServiceAlertRecord org.onebusaway.alerts.impl.ServiceAlertLocalizedString org.onebusaway.alerts.impl.ServiceAlertTimeRange org.onebusaway.alerts.impl.ServiceAlertsSituationAffectsClause org.onebusaway.alerts.impl.ServiceAlertSituationConsequenceClause + + org.onebusaway.transit_data_federation.impl.realtime.BlockLocationRecord + org.onebusaway.transit_data_federation.impl.realtime.history.ScheduleDeviationHistory + org.onebusaway.transit_data_federation.impl.reporting.StopProblemReportRecord + org.onebusaway.transit_data_federation.impl.reporting.TripProblemReportRecord + diff --git a/onebusaway-admin-webapp/src/main/resources/struts.xml b/onebusaway-admin-webapp/src/main/resources/struts.xml index 99a001f04a..c545222100 100644 --- a/onebusaway-admin-webapp/src/main/resources/struts.xml +++ b/onebusaway-admin-webapp/src/main/resources/struts.xml @@ -19,7 +19,7 @@ --> + "http://struts.apache.org/dtds/struts-2.5.dtd"> @@ -30,11 +30,13 @@ + - - + + + diff --git a/onebusaway-admin-webapp/src/main/webapp/WEB-INF/content/admin/agencymetadata/agency-metadata-edit.jspx b/onebusaway-admin-webapp/src/main/webapp/WEB-INF/content/admin/agencymetadata/agency-metadata-edit.jspx index b058d508e2..5991939c6b 100644 --- a/onebusaway-admin-webapp/src/main/webapp/WEB-INF/content/admin/agencymetadata/agency-metadata-edit.jspx +++ b/onebusaway-admin-webapp/src/main/webapp/WEB-INF/content/admin/agencymetadata/agency-metadata-edit.jspx @@ -49,11 +49,11 @@ - + - Create Agency Metadata + Create Agency Metadata - Edit Agency Metadata + Edit Agency Metadata

diff --git a/onebusaway-admin-webapp/src/main/webapp/WEB-INF/content/admin/agencymetadata/agency-metadata.jspx b/onebusaway-admin-webapp/src/main/webapp/WEB-INF/content/admin/agencymetadata/agency-metadata.jspx index 644cf31a0f..82c0f05751 100644 --- a/onebusaway-admin-webapp/src/main/webapp/WEB-INF/content/admin/agencymetadata/agency-metadata.jspx +++ b/onebusaway-admin-webapp/src/main/webapp/WEB-INF/content/admin/agencymetadata/agency-metadata.jspx @@ -48,7 +48,7 @@ - +

Manage Agency Metadata

diff --git a/onebusaway-admin-webapp/src/main/webapp/WEB-INF/content/admin/bundles/upload-files.jspx b/onebusaway-admin-webapp/src/main/webapp/WEB-INF/content/admin/bundles/upload-files.jspx index 9751cf6bce..a06f66d5b1 100644 --- a/onebusaway-admin-webapp/src/main/webapp/WEB-INF/content/admin/bundles/upload-files.jspx +++ b/onebusaway-admin-webapp/src/main/webapp/WEB-INF/content/admin/bundles/upload-files.jspx @@ -20,7 +20,7 @@ - +

Upload Files to Dataset

- @@ -82,7 +82,7 @@ - + diff --git a/onebusaway-agency-metadata/pom.xml b/onebusaway-agency-metadata/pom.xml index fa8d6c1117..93686d3b07 100644 --- a/onebusaway-agency-metadata/pom.xml +++ b/onebusaway-agency-metadata/pom.xml @@ -3,7 +3,7 @@ org.onebusaway onebusaway-application-modules - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-agency-metadata jar @@ -40,7 +40,7 @@ org.apache.commons commons-lang3 - 3.1 + 3.8.1 junit @@ -56,7 +56,6 @@ mysql mysql-connector-java - 5.1.17 diff --git a/onebusaway-agency-metadata/src/main/java/org/onebusaway/agency_metadata/service/AgencyMetadataDaoImpl.java b/onebusaway-agency-metadata/src/main/java/org/onebusaway/agency_metadata/service/AgencyMetadataDaoImpl.java index 49f68c52d1..5c77e1782f 100644 --- a/onebusaway-agency-metadata/src/main/java/org/onebusaway/agency_metadata/service/AgencyMetadataDaoImpl.java +++ b/onebusaway-agency-metadata/src/main/java/org/onebusaway/agency_metadata/service/AgencyMetadataDaoImpl.java @@ -40,7 +40,6 @@ public class AgencyMetadataDaoImpl implements AgencyMetadataDao { private SessionFactory _sessionFactory; @Autowired - @Qualifier("agencyMetadataSessionFactory") public void setSessionFactory(SessionFactory sessionFactory) { _sessionFactory = sessionFactory; } diff --git a/onebusaway-agency-metadata/src/main/resources/org/onebusaway/agency_metadata/application-context.xml b/onebusaway-agency-metadata/src/main/resources/org/onebusaway/agency_metadata/application-context.xml index ff92c788fc..344689f6a6 100644 --- a/onebusaway-agency-metadata/src/main/resources/org/onebusaway/agency_metadata/application-context.xml +++ b/onebusaway-agency-metadata/src/main/resources/org/onebusaway/agency_metadata/application-context.xml @@ -23,11 +23,11 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> - - org.codehaus.jackson - jackson-mapper-asl - 1.9.2 - org.onebusaway onebusaway-container diff --git a/onebusaway-alerts-persistence/src/main/java/org/onebusaway/alerts/impl/ServiceAlertsPersistenceDB.java b/onebusaway-alerts-persistence/src/main/java/org/onebusaway/alerts/impl/ServiceAlertsPersistenceDB.java index eae5f69b5b..8c06477842 100644 --- a/onebusaway-alerts-persistence/src/main/java/org/onebusaway/alerts/impl/ServiceAlertsPersistenceDB.java +++ b/onebusaway-alerts-persistence/src/main/java/org/onebusaway/alerts/impl/ServiceAlertsPersistenceDB.java @@ -18,7 +18,7 @@ import java.util.Date; import java.util.List; -import org.hibernate.Query; +import org.hibernate.query.Query; import org.hibernate.SQLQuery; import org.hibernate.Session; import org.hibernate.SessionFactory; diff --git a/onebusaway-api-core/pom.xml b/onebusaway-api-core/pom.xml index cf6fd2fe62..2d30de0867 100644 --- a/onebusaway-api-core/pom.xml +++ b/onebusaway-api-core/pom.xml @@ -3,7 +3,7 @@ org.onebusaway onebusaway-application-modules - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-api-core diff --git a/onebusaway-api-core/src/main/java/org/onebusaway/api/model/ResponseBean.java b/onebusaway-api-core/src/main/java/org/onebusaway/api/model/ResponseBean.java index 1b0974f59e..deb8e9e2da 100644 --- a/onebusaway-api-core/src/main/java/org/onebusaway/api/model/ResponseBean.java +++ b/onebusaway-api-core/src/main/java/org/onebusaway/api/model/ResponseBean.java @@ -17,6 +17,7 @@ import java.io.Serializable; +import com.fasterxml.jackson.annotation.JsonIgnore; import org.onebusaway.csv_entities.schema.annotations.CsvField; import org.onebusaway.util.SystemTime; @@ -24,6 +25,8 @@ public class ResponseBean implements Serializable { private static final long serialVersionUID = 1L; + @JsonIgnore + private boolean isText = false; private int version; private int code; private long currentTime = SystemTime.currentTimeMillis(); @@ -41,6 +44,15 @@ public ResponseBean(int version, int code, String text, Object data) { this.data = data; } + public ResponseBean(int version, int code, String text, Object data, boolean isText) { + this.version = version; + this.code = code; + this.text = text; + this.data = data; + this.isText = isText; + } + + public int getCode() { return code; } @@ -60,4 +72,7 @@ public long getCurrentTime() { public Object getData() { return data; } + + @JsonIgnore + public boolean isString() { return isText; } } diff --git a/onebusaway-api-webapp/pom.xml b/onebusaway-api-webapp/pom.xml index b6c6517a9a..55400d9c33 100644 --- a/onebusaway-api-webapp/pom.xml +++ b/onebusaway-api-webapp/pom.xml @@ -3,7 +3,7 @@ org.onebusaway onebusaway-application-modules - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-api-webapp war @@ -89,7 +89,7 @@ org.apache.struts struts2-convention-plugin - + org.apache.struts struts2-rest-plugin @@ -99,6 +99,12 @@ struts2-rome-plugin 0.3 + + net.sf.json-lib + json-lib + 2.4 + jdk15 + com.rometools @@ -148,19 +154,11 @@ junit test - - org.tuckey - urlrewritefilter - 3.2.0 - jar - compile - mysql mysql-connector-java - 5.1.17 org.mockito diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/api/ApiActionSupport.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/api/ApiActionSupport.java index 78be1c1fa3..67f18791a0 100644 --- a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/api/ApiActionSupport.java +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/api/ApiActionSupport.java @@ -115,6 +115,12 @@ protected DefaultHttpHeaders setOkResponse(Object data) { return new DefaultHttpHeaders(); } + protected DefaultHttpHeaders setOkResponseText(String text) { + _response = new ResponseBean(getReturnVersion(), ResponseCodes.RESPONSE_OK, + "OK", text, true); + return new DefaultHttpHeaders(); + } + protected DefaultHttpHeaders setValidationErrorsResponse() { ValidationErrorBean bean = new ValidationErrorBean(new ArrayList( getActionErrors()), getFieldErrors()); diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/api/ApiKeyInterceptor.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/api/ApiKeyInterceptor.java index 2bc9e6fd5f..6a15d25c86 100644 --- a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/api/ApiKeyInterceptor.java +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/api/ApiKeyInterceptor.java @@ -15,6 +15,7 @@ */ package org.onebusaway.api.actions.api; +import org.apache.struts2.dispatcher.Parameter; import org.onebusaway.api.ResponseCodes; import org.onebusaway.api.model.ResponseBean; import org.onebusaway.users.services.ApiKeyPermissionService; @@ -74,8 +75,8 @@ public String intercept(ActionInvocation invocation) throws Exception { private ApiKeyPermissionService.Status isAllowed(ActionInvocation invocation) { ActionContext context = invocation.getInvocationContext(); - Map parameters = context.getParameters(); - String[] keys = (String[]) parameters.get("key"); + Parameter key = context.getParameters().get("key"); + String[] keys = (String[]) key.getObject(); if( keys == null || keys.length == 0) return ApiKeyPermissionService.Status.UNAUTHORIZED; diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/api/ExceptionInterceptor.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/api/ExceptionInterceptor.java index abcf18de6b..e33c2da201 100644 --- a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/api/ExceptionInterceptor.java +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/api/ExceptionInterceptor.java @@ -15,6 +15,7 @@ */ package org.onebusaway.api.actions.api; +import java.util.HashMap; import java.util.Map; import org.onebusaway.api.ResponseCodes; @@ -95,7 +96,10 @@ private String getActionAsUrl(ActionInvocation invocation) { b.append("!"); b.append(proxy.getMethod()); - Map params = context.getParameters(); + Map params = new HashMap<>(); + for (String key : context.getParameters().keySet()) { + params.put(key, context.getParameters().get(key).getValue()); + } if (!params.isEmpty()) { b.append("?"); diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/LinesRequestV2Action.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/LinesRequestV2Action.java index 958ae760be..032e361d0b 100644 --- a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/LinesRequestV2Action.java +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/LinesRequestV2Action.java @@ -23,25 +23,16 @@ import java.util.List; import java.util.Map; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.lang.StringUtils; import org.apache.struts2.interceptor.ServletRequestAware; import org.apache.struts2.interceptor.ServletResponseAware; import org.apache.struts2.rest.DefaultHttpHeaders; -import org.onebusaway.api.actions.api.ApiActionSupport; import org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters; import org.onebusaway.api.actions.siri.model.DetailLevel; import org.onebusaway.geospatial.model.CoordinateBounds; import org.onebusaway.gtfs.model.AgencyAndId; import org.onebusaway.presentation.impl.DateUtil; import org.onebusaway.transit_data_federation.siri.SiriUpcomingServiceExtension; -import org.onebusaway.util.impl.analytics.GoogleAnalyticsServiceImpl; -import org.springframework.beans.factory.annotation.Autowired; - -import com.brsanthu.googleanalytics.EventHit; -import com.brsanthu.googleanalytics.PageViewHit; import uk.org.siri.siri_2.AnnotatedLineStructure; import uk.org.siri.siri_2.ErrorDescriptionStructure; @@ -51,7 +42,7 @@ import uk.org.siri.siri_2.ServiceDeliveryErrorConditionStructure; import uk.org.siri.siri_2.Siri; -public class LinesRequestV2Action extends MonitoringActionBase +public class LinesRequestV2Action extends MonitoringActionV2Base implements ServletRequestAware, ServletResponseAware { private static final long serialVersionUID = 1L; @@ -59,23 +50,6 @@ public class LinesRequestV2Action extends MonitoringActionBase private static final String LINES_DETAIL_LEVEL = "LinesDetailLevel"; private static final String INCLUDE_POLYLINES = "includePolylines"; - @Autowired - private GoogleAnalyticsServiceImpl _gaService; - - private Siri _response; - - private HttpServletRequest _request; - - private HttpServletResponse _servletResponse; - - // See urlrewrite.xml as to how this is set. Which means this action doesn't - // respect an HTTP Accept: header. - private String _type = "xml"; - - public void setType(String type) { - _type = type; - } - public DefaultHttpHeaders index() throws IOException { long responseTimestamp = getTime(); @@ -90,14 +64,14 @@ public DefaultHttpHeaders index() throws IOException { boolean validBoundDistance = true; // User Parameters - String boundingBox = _request.getParameter(BOUNDING_BOX); - String circle = _request.getParameter(CIRCLE); - String lineRef = _request.getParameter(LINE_REF); - String directionId = _request.getParameter(DIRECTION_REF); - String agencyId = _request.getParameter(OPERATOR_REF); - String hasUpcomingScheduledService = _request.getParameter(UPCOMING_SCHEDULED_SERVICE); - String detailLevelParam = _request.getParameter(LINES_DETAIL_LEVEL); - String includePolylines = _request.getParameter(INCLUDE_POLYLINES); + String boundingBox = _servletRequest.getParameter(BOUNDING_BOX); + String circle = _servletRequest.getParameter(CIRCLE); + String lineRef = _servletRequest.getParameter(LINE_REF); + String directionId = _servletRequest.getParameter(DIRECTION_REF); + String agencyId = _servletRequest.getParameter(OPERATOR_REF); + String hasUpcomingScheduledService = _servletRequest.getParameter(UPCOMING_SCHEDULED_SERVICE); + String detailLevelParam = _servletRequest.getParameter(LINES_DETAIL_LEVEL); + String includePolylines = _servletRequest.getParameter(INCLUDE_POLYLINES); //get the detail level parameter or set it to default if not specified DetailLevel detailLevel; @@ -195,16 +169,11 @@ public DefaultHttpHeaders index() throws IOException { } } - _response = generateSiriResponse(lines, upcomingServiceAllStops, + _siriResponse = generateSiriResponse(lines, upcomingServiceAllStops, error, responseTimestamp); - try { - this._servletResponse.getWriter().write(getLines()); - } catch (IOException e) { - e.printStackTrace(); - } - - return null; + // use ApiActionSupport to set proper headers instead of writing directly to response + return setOkResponseText(getSiri()); } private Siri generateSiriResponse( @@ -263,52 +232,4 @@ private Siri generateSiriResponse( return siri; } - public String getLines() { - try { - if (_type.equals("xml")) { - this._servletResponse.setContentType("application/xml"); - return _realtimeService.getSiriXmlSerializer() - .getXml(_response); - } else { - this._servletResponse.setContentType("application/json"); - return _realtimeService.getSiriJsonSerializer().getJson( - _response, _request.getParameter("callback")); - } - } catch (Exception e) { - return e.getMessage(); - } - } - - @Override - public void setServletRequest(HttpServletRequest request) { - this._request = request; - } - - @Override - public void setServletResponse(HttpServletResponse servletResponse) { - this._servletResponse = servletResponse; - } - - public HttpServletResponse getServletResponse(){ - return _servletResponse; - } - - private void processGoogleAnalytics(){ - processGoogleAnalyticsPageView(); - processGoogleAnalyticsApiKeys(); - } - - private void processGoogleAnalyticsPageView(){ - _gaService.post(new PageViewHit()); - } - - private void processGoogleAnalyticsApiKeys(){ - String apiKey = _request.getParameter("key"); - if(StringUtils.isBlank(apiKey)) - apiKey = "Key Information Unavailable"; - - _gaService.post(new EventHit(GA_EVENT_CATEGORY, GA_EVENT_ACTION, apiKey, 1)); - } - - } diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/MonitoringActionV1Base.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/MonitoringActionV1Base.java new file mode 100644 index 0000000000..3d9c2a9de3 --- /dev/null +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/MonitoringActionV1Base.java @@ -0,0 +1,60 @@ +/** + * Copyright (C) 2016 Cambridge Systematics, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onebusaway.api.actions.siri; + +import org.onebusaway.presentation.impl.service_alerts.ServiceAlertsHelper; +import org.onebusaway.presentation.services.realtime.RealtimeService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import uk.org.siri.siri.Siri; + +/** + * Base action for Siri Monitoring V1 calls. + */ +public class MonitoringActionV1Base extends SiriAction { + + private static Logger _log = LoggerFactory.getLogger(MonitoringActionV1Base.class); + + // note this is a v1 helper + protected ServiceAlertsHelper _serviceAlertsHelper = new ServiceAlertsHelper(); + // note this is v1 siri + protected Siri _siriResponse; + @Autowired + protected RealtimeService _realtimeService; + + public MonitoringActionV1Base(int defaultVersion) { + super(defaultVersion); + } + + public String getSiri() { + // we no longer set response types here -- custom handlers take care of that + // based on the type param + try { + if(getType().equals("xml")) { + return _realtimeService.getSiriXmlSerializer().getXml(_siriResponse); + } else { + return _realtimeService.getSiriJsonSerializer().getJson(_siriResponse, + /*_servletRequest.getParameter("callback")*/null); + // callback happens at a lower level + } + } catch(Exception e) { + _log.error("Siri v1 serialization failed: ", e,e); + return e.toString(); + } + } + +} diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/MonitoringActionBase.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/MonitoringActionV2Base.java similarity index 84% rename from onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/MonitoringActionBase.java rename to onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/MonitoringActionV2Base.java index 084edab870..1a6db75cdb 100644 --- a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/MonitoringActionBase.java +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/MonitoringActionV2Base.java @@ -19,54 +19,59 @@ import java.util.List; import java.util.Map; -import org.onebusaway.api.actions.api.ApiActionSupport; + +import org.onebusaway.api.actions.siri.impl.ServiceAlertsHelperV2; import org.onebusaway.api.actions.siri.service.RealtimeServiceV2; import org.onebusaway.geospatial.model.CoordinateBounds; import org.onebusaway.geospatial.services.SphericalGeometryLibrary; import org.onebusaway.gtfs.model.AgencyAndId; import org.onebusaway.transit_data.model.StopBean; -import org.onebusaway.transit_data.services.TransitDataService; import org.onebusaway.util.AgencyAndIdLibrary; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import uk.org.siri.siri_2.Siri; -public class MonitoringActionBase extends ApiActionSupport { +/** + * Base action for Siri Monitoring V2 calls. + */ +public class MonitoringActionV2Base extends SiriAction { - private static final int V3 = 3; - - public static final String GA_EVENT_ACTION = "API Key Request"; - public static final String GA_EVENT_CATEGORY = "Stop Monitoring"; - - public static final double MAX_BOUNDS_DISTANCE= 500; - public static final double MAX_BOUNDS_RADIUS= 250; - - public static final String BOUNDING_BOX = "BoundingBox"; - public static final String CIRCLE = "Circle"; - public static final String MONITORING_REF = "MonitoringRef"; - public static final String LINE_REF = "LineRef"; - public static final String STOP_POINTS_DETAIL_LEVEL = "StopPointsDetailLevel"; - public static final String DIRECTION_REF = "DirectionRef"; - public static final String OPERATOR_REF = "OperatorRef"; - public static final String STOP_MONITORING_DETAIL_LEVEL = "StopMonitoringDetailLevel"; - public static final String VEHICLE_MONITORING_DETAIL_LEVEL = "VehicleMonitoringDetailLevel"; - public static final String UPCOMING_SCHEDULED_SERVICE = "hasUpcomingScheduledService"; - public static final String MAX_ONWARD_CALLS = "MaximumNumberOfCallsOnwards"; - public static final String MAX_STOP_VISITS = "MaximumStopVisits"; - public static final String MIN_STOP_VISITS = "MinimumStopVisitsPerLine"; + private static Logger _log = LoggerFactory.getLogger(MonitoringActionV2Base.class); // Errors public static final String ERROR_REQUIRED_PARAMS = "You must provide a valid Circle, BoundingBox or LineRef value. "; public static final String ERROR_NON_NUMERIC = "One or more coordinate values contain a non-numeric value. "; - - @Autowired - public TransitDataService _transitDataService; @Autowired protected RealtimeServiceV2 _realtimeService; - - public MonitoringActionBase() { + + // note this is a v2 helper + protected ServiceAlertsHelperV2 _serviceAlertsHelper = new ServiceAlertsHelperV2(); + // note this is v2 siri + protected Siri _siriResponse; + + + public MonitoringActionV2Base() { super(V3); } - + + protected String getSiri() { + try { + if (getType().equals("xml")) { + return _realtimeService.getSiriXmlSerializer() + .getXml(_siriResponse); + } else { + return _realtimeService.getSiriJsonSerializer().getJson( + _siriResponse, /*_servletRequest.getParameter("callback")*/null); + // callback happens at a lower level + } + } catch (Exception e) { + _log.error("Siri v2 serialization failed: ", e,e); + return e.toString(); + } + } + protected boolean isValidRoute(AgencyAndId routeId) { if (routeId != null && routeId.hasValues() diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/SiriAction.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/SiriAction.java new file mode 100644 index 0000000000..2b0610fd43 --- /dev/null +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/SiriAction.java @@ -0,0 +1,109 @@ +/** + * Copyright (C) 2021 Cambridge Systematics, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onebusaway.api.actions.siri; + +import org.apache.struts2.interceptor.ServletRequestAware; +import org.apache.struts2.interceptor.ServletResponseAware; +import org.onebusaway.api.actions.api.ApiActionSupport; + +import org.onebusaway.transit_data.services.TransitDataService; +import org.onebusaway.util.impl.analytics.GoogleAnalyticsServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Base class for Siri Actions. + */ +public class SiriAction extends ApiActionSupport + implements ServletRequestAware, ServletResponseAware { + + protected static final int V3 = 3; + public static final double MAX_BOUNDS_DISTANCE= 500; + public static final double MAX_BOUNDS_RADIUS= 250; + + public static final String BOUNDING_BOX = "BoundingBox"; + public static final String CIRCLE = "Circle"; + public static final String MONITORING_REF = "MonitoringRef"; + public static final String LINE_REF = "LineRef"; + public static final String STOP_POINTS_DETAIL_LEVEL = "StopPointsDetailLevel"; + public static final String DIRECTION_REF = "DirectionRef"; + public static final String OPERATOR_REF = "OperatorRef"; + public static final String VEHICLE_REF = "VehicleRef"; + public static final String STOP_MONITORING_DETAIL_LEVEL = "StopMonitoringDetailLevel"; + public static final String VEHICLE_MONITORING_DETAIL_LEVEL = "VehicleMonitoringDetailLevel"; + public static final String UPCOMING_SCHEDULED_SERVICE = "hasUpcomingScheduledService"; + public static final String MAX_ONWARD_CALLS = "MaximumNumberOfCallsOnwards"; + public static final String MAX_STOP_VISITS = "MaximumStopVisits"; + public static final String MIN_STOP_VISITS = "MinimumStopVisitsPerLine"; + public static final String RAW_LOCATION = "ShowRawLocation"; + public static final String TRIP_ID = "TripId"; + + + @Autowired + protected TransitDataService _transitDataService; + + @Autowired + private GoogleAnalyticsServiceImpl _gaService; + + protected HttpServletRequest _servletRequest; + protected HttpServletResponse _servletResponse; + + // See urlrewrite.xml as to how this is set. Which means this action doesn't respect an HTTP Accept: header. + private String _type = null; + + public SiriAction(int defaultVersion) { + super(defaultVersion); + } + + public void setType(String type) { + _type = type; + } + + public String getType() { + if (_type == null) { + if (_servletRequest == null || _servletRequest.getRequestURI() == null) { + return "xml"; // default on startup and testing + } + if (_servletRequest.getRequestURI().contains("json")) { + return "json"; + } + // default to xml + return "xml"; + } + return _type; + } + + @Override + public void setServletRequest(HttpServletRequest request) { + this._servletRequest = request; + } + + @Override + public void setServletResponse(HttpServletResponse servletResponse) { + this._servletResponse = servletResponse; + } + + public HttpServletResponse getServletResponse() { + return _servletResponse; + } + + protected void processGoogleAnalytics() { + // no longer supported + } + +} diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/StopMonitoringAction.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/StopMonitoringAction.java index 2c21c934ab..b2f9412788 100644 --- a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/StopMonitoringAction.java +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/StopMonitoringAction.java @@ -24,23 +24,14 @@ import java.util.List; import java.util.Map; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.lang.StringUtils; -import org.apache.struts2.interceptor.ServletRequestAware; -import org.apache.struts2.interceptor.ServletResponseAware; import org.apache.struts2.rest.DefaultHttpHeaders; -import org.onebusaway.api.actions.api.ApiActionSupport; import org.onebusaway.geospatial.model.CoordinateBounds; import org.onebusaway.gtfs.model.AgencyAndId; -import org.onebusaway.presentation.impl.service_alerts.ServiceAlertsHelper; -import org.onebusaway.presentation.services.realtime.RealtimeService; import org.onebusaway.transit_data.model.StopBean; -import org.onebusaway.transit_data.services.TransitDataService; import org.onebusaway.util.AgencyAndIdLibrary; -import org.springframework.beans.factory.annotation.Autowired; -import org.onebusaway.util.impl.analytics.GoogleAnalyticsServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import uk.org.siri.siri.ErrorDescriptionStructure; import uk.org.siri.siri.MonitoredStopVisitStructure; @@ -50,83 +41,55 @@ import uk.org.siri.siri.ServiceDeliveryErrorConditionStructure; import uk.org.siri.siri.Siri; import uk.org.siri.siri.StopMonitoringDeliveryStructure; -import com.brsanthu.googleanalytics.EventHit; -import com.brsanthu.googleanalytics.PageViewHit; -public class StopMonitoringAction extends ApiActionSupport - implements ServletRequestAware, ServletResponseAware { +public class StopMonitoringAction extends MonitoringActionV1Base { + + private static Logger _log = LoggerFactory.getLogger(StopMonitoringAction.class); private static final long serialVersionUID = 1L; private static final int V3 = 3; - - private static final String GA_EVENT_ACTION = "API Key Request"; - - private static final String GA_EVENT_CATEGORY = "Stop Monitoring"; - - @Autowired - public TransitDataService _transitDataService; - - @Autowired - private RealtimeService _realtimeService; - - @Autowired - private GoogleAnalyticsServiceImpl _gaService; - - private Siri _response; - - private ServiceAlertsHelper _serviceAlertsHelper = new ServiceAlertsHelper(); - private HttpServletRequest _request; - - private HttpServletResponse _servletResponse; - - // See urlrewrite.xml as to how this is set. Which means this action doesn't respect an HTTP Accept: header. - private String _type = "xml"; - public StopMonitoringAction() { super(V3); } - public void setType(String type) { - _type = type; - } public DefaultHttpHeaders index() throws IOException { - - processGoogleAnalytics(); - long responseTimestamp = getTime(); + processGoogleAnalytics(); + + long responseTimestamp = getTime(); _realtimeService.setTime(responseTimestamp); - String directionId = _request.getParameter("DirectionRef"); - + String directionId = _servletRequest.getParameter(DIRECTION_REF); + // We need to support the user providing no agency id which means 'all agencies'. // So, this array will hold a single agency if the user provides it or all // agencies if the user provides none. We'll iterate over them later while // querying for vehicles and routes List agencyIds = new ArrayList(); - + // Try to get the agency id passed by the user - String agencyId = _request.getParameter("OperatorRef"); - + String agencyId = _servletRequest.getParameter(OPERATOR_REF); + if (agencyId != null) { // The user provided an agency id so, use it agencyIds.add(agencyId); } else { // They did not provide an agency id, so interpret that an any/all agencies. - Map> agencies = _transitDataService.getAgencyIdsWithCoverageArea(); + Map> agencies = _transitDataService.getAgencyIdsWithCoverageArea(); agencyIds.addAll(agencies.keySet()); } - + List stopIds = new ArrayList(); String stopIdsErrorString = ""; - if (_request.getParameter("MonitoringRef") != null) { + if (_servletRequest.getParameter(MONITORING_REF) != null) { try { // If the user included an agency id as part of the stop id, ignore any OperatorRef arg // or lack of OperatorRef arg and just use the included one. - AgencyAndId stopId = AgencyAndIdLibrary.convertFromString(_request.getParameter("MonitoringRef")); + AgencyAndId stopId = AgencyAndIdLibrary.convertFromString(_servletRequest.getParameter(MONITORING_REF)); if (isValidStop(stopId)) { stopIds.add(stopId); } else { @@ -135,7 +98,7 @@ public DefaultHttpHeaders index() throws IOException { } catch (Exception e) { // The user didn't provide an agency id in the MonitoringRef, so use our list of operator refs for (String agency : agencyIds) { - AgencyAndId stopId = new AgencyAndId(agency, _request.getParameter("MonitoringRef")); + AgencyAndId stopId = new AgencyAndId(agency, _servletRequest.getParameter(MONITORING_REF)); if (isValidStop(stopId)) { stopIds.add(stopId); } else { @@ -148,13 +111,13 @@ public DefaultHttpHeaders index() throws IOException { } else { stopIdsErrorString = "You must provide a MonitoringRef."; } - + List routeIds = new ArrayList(); String routeIdsErrorString = ""; - if (_request.getParameter("LineRef") != null) { + if (_servletRequest.getParameter(LINE_REF) != null) { try { // Same as above for stop id - AgencyAndId routeId = AgencyAndIdLibrary.convertFromString(_request.getParameter("LineRef")); + AgencyAndId routeId = AgencyAndIdLibrary.convertFromString(_servletRequest.getParameter(LINE_REF)); if (isValidRoute(routeId)) { routeIds.add(routeId); } else { @@ -163,7 +126,7 @@ public DefaultHttpHeaders index() throws IOException { } catch (Exception e) { // Same as above for stop id for (String agency : agencyIds) { - AgencyAndId routeId = new AgencyAndId(agency, _request.getParameter("LineRef")); + AgencyAndId routeId = new AgencyAndId(agency, _servletRequest.getParameter(LINE_REF)); if (isValidRoute(routeId)) { routeIds.add(routeId); } else { @@ -174,52 +137,52 @@ public DefaultHttpHeaders index() throws IOException { } if (routeIds.size() > 0) routeIdsErrorString = ""; } - - String detailLevel = _request.getParameter("StopMonitoringDetailLevel"); - int maximumOnwardCalls = 0; + String detailLevel = _servletRequest.getParameter(STOP_MONITORING_DETAIL_LEVEL); + + int maximumOnwardCalls = 0; if (detailLevel != null && detailLevel.equals("calls")) { maximumOnwardCalls = Integer.MAX_VALUE; try { - maximumOnwardCalls = Integer.parseInt(_request.getParameter("MaximumNumberOfCallsOnwards")); + maximumOnwardCalls = Integer.parseInt(_servletRequest.getParameter(MAX_ONWARD_CALLS)); } catch (NumberFormatException e) { maximumOnwardCalls = Integer.MAX_VALUE; } } - int maximumStopVisits = Integer.MAX_VALUE; + int maximumStopVisits = Integer.MAX_VALUE; try { - maximumStopVisits = Integer.parseInt(_request.getParameter("MaximumStopVisits")); + maximumStopVisits = Integer.parseInt(_servletRequest.getParameter(MAX_STOP_VISITS)); } catch (NumberFormatException e) { maximumStopVisits = Integer.MAX_VALUE; } - Integer minimumStopVisitsPerLine = null; + Integer minimumStopVisitsPerLine = null; try { - minimumStopVisitsPerLine = Integer.parseInt(_request.getParameter("MinimumStopVisitsPerLine")); + minimumStopVisitsPerLine = Integer.parseInt(_servletRequest.getParameter(MIN_STOP_VISITS)); } catch (NumberFormatException e) { minimumStopVisitsPerLine = null; } - + // Monitored Stop Visits List visits = new ArrayList(); Map visitsMap = new HashMap(); - + for (AgencyAndId stopId : stopIds) { - + if (!stopId.hasValues()) continue; - + // Stop ids can only be valid here because we only added valid ones to stopIds. List visitsForStop = _realtimeService.getMonitoredStopVisitsForStop(stopId.toString(), maximumOnwardCalls, responseTimestamp); - if (visitsForStop != null) visits.addAll(visitsForStop); + if (visitsForStop != null) visits.addAll(visitsForStop); } - + List filteredVisits = new ArrayList(); Map visitCountByLine = new HashMap(); int visitCount = 0; - + for (MonitoredStopVisitStructure visit : visits) { MonitoredVehicleJourneyStructure journey = visit.getMonitoredVehicleJourney(); @@ -234,7 +197,7 @@ public DefaultHttpHeaders index() throws IOException { if (directionId != null && !thisDirectionId.equals(directionId)) continue; } - + // visit count filters Integer visitCountForThisLine = visitCountByLine.get(thisRouteId); if (visitCountForThisLine == null) { @@ -246,54 +209,47 @@ public DefaultHttpHeaders index() throws IOException { break; } else { if (visitCountForThisLine >= minimumStopVisitsPerLine) { - continue; + continue; } } } - + // unique stops filters - if (visit.getMonitoredVehicleJourney() == null || - visit.getMonitoredVehicleJourney().getVehicleRef() == null || - StringUtils.isBlank(visit.getMonitoredVehicleJourney().getVehicleRef().getValue())){ - continue; + if (visit.getMonitoredVehicleJourney() == null || + visit.getMonitoredVehicleJourney().getVehicleRef() == null || + StringUtils.isBlank(visit.getMonitoredVehicleJourney().getVehicleRef().getValue())) { + continue; + } else { + String visitKey = visit.getMonitoredVehicleJourney().getVehicleRef().getValue(); + if (visitsMap.containsKey(visit.getMonitoredVehicleJourney().getVehicleRef().getValue())) { + if (visit.getMonitoredVehicleJourney().getProgressStatus() == null) { + visitsMap.remove(visitKey); + visitsMap.put(visitKey, visit); + } + continue; + } else { + visitsMap.put(visit.getMonitoredVehicleJourney().getVehicleRef().getValue(), visit); + } } - else{ - String visitKey = visit.getMonitoredVehicleJourney().getVehicleRef().getValue(); - if(visitsMap.containsKey(visit.getMonitoredVehicleJourney().getVehicleRef().getValue())){ - if(visit.getMonitoredVehicleJourney().getProgressStatus() == null){ - visitsMap.remove(visitKey); - visitsMap.put(visitKey, visit); - } - continue; - } - else{ - visitsMap.put(visit.getMonitoredVehicleJourney().getVehicleRef().getValue(), visit); - } - } - + filteredVisits.add(visit); - visitCount++; + visitCount++; visitCountForThisLine++; visitCountByLine.put(thisRouteId, visitCountForThisLine); } visits = filteredVisits; - + Exception error = null; - if (stopIds.size() == 0 || (_request.getParameter("LineRef") != null && routeIds.size() == 0)) { + if (stopIds.size() == 0 || (_servletRequest.getParameter(LINE_REF) != null && routeIds.size() == 0)) { String errorString = (stopIdsErrorString + " " + routeIdsErrorString).trim(); error = new Exception(errorString); } - - _response = generateSiriResponse(visits, stopIds, error, responseTimestamp); - - try { - this._servletResponse.getWriter().write(getStopMonitoring()); - } catch (IOException e) { - e.printStackTrace(); - } - return null; + _siriResponse = generateSiriResponse(visits, stopIds, error, responseTimestamp); + + // use ApiActionSupport to set proper headers instead of writing directly to response + return setOkResponseText(getSiri()); } private boolean isValidRoute(AgencyAndId routeId) { @@ -314,90 +270,45 @@ private boolean isValidStop(AgencyAndId stopId) { } private Siri generateSiriResponse(List visits, List stopIds, Exception error, long responseTimestamp) { - - StopMonitoringDeliveryStructure stopMonitoringDelivery = new StopMonitoringDeliveryStructure(); - stopMonitoringDelivery.setResponseTimestamp(new Date(responseTimestamp)); - - ServiceDelivery serviceDelivery = new ServiceDelivery(); - serviceDelivery.setResponseTimestamp(new Date(responseTimestamp)); - serviceDelivery.getStopMonitoringDelivery().add(stopMonitoringDelivery); - - if (error != null) { - ServiceDeliveryErrorConditionStructure errorConditionStructure = new ServiceDeliveryErrorConditionStructure(); - - ErrorDescriptionStructure errorDescriptionStructure = new ErrorDescriptionStructure(); - errorDescriptionStructure.setValue(error.getMessage()); - - OtherErrorStructure otherErrorStructure = new OtherErrorStructure(); - otherErrorStructure.setErrorText(error.getMessage()); - - errorConditionStructure.setDescription(errorDescriptionStructure); - errorConditionStructure.setOtherError(otherErrorStructure); - - stopMonitoringDelivery.setErrorCondition(errorConditionStructure); - } else { - Calendar gregorianCalendar = new GregorianCalendar(); - gregorianCalendar.setTimeInMillis(responseTimestamp); - gregorianCalendar.add(Calendar.MINUTE, 1); - stopMonitoringDelivery.setValidUntil(gregorianCalendar.getTime()); - stopMonitoringDelivery.getMonitoredStopVisit().addAll(visits); + StopMonitoringDeliveryStructure stopMonitoringDelivery = new StopMonitoringDeliveryStructure(); + stopMonitoringDelivery.setResponseTimestamp(new Date(responseTimestamp)); + ServiceDelivery serviceDelivery = new ServiceDelivery(); serviceDelivery.setResponseTimestamp(new Date(responseTimestamp)); - - _serviceAlertsHelper.addSituationExchangeToSiriForStops(serviceDelivery, visits, _transitDataService, stopIds); - _serviceAlertsHelper.addGlobalServiceAlertsToServiceDelivery(serviceDelivery, _realtimeService); - } + serviceDelivery.getStopMonitoringDelivery().add(stopMonitoringDelivery); - Siri siri = new Siri(); - siri.setServiceDelivery(serviceDelivery); - - return siri; - } + if (error != null) { + ServiceDeliveryErrorConditionStructure errorConditionStructure = new ServiceDeliveryErrorConditionStructure(); - public String getStopMonitoring() { - try { - if(_type.equals("xml")) { - this._servletResponse.setContentType("application/xml"); - return _realtimeService.getSiriXmlSerializer().getXml(_response); + ErrorDescriptionStructure errorDescriptionStructure = new ErrorDescriptionStructure(); + errorDescriptionStructure.setValue(error.getMessage()); + + OtherErrorStructure otherErrorStructure = new OtherErrorStructure(); + otherErrorStructure.setErrorText(error.getMessage()); + + errorConditionStructure.setDescription(errorDescriptionStructure); + errorConditionStructure.setOtherError(otherErrorStructure); + + stopMonitoringDelivery.setErrorCondition(errorConditionStructure); } else { - this._servletResponse.setContentType("application/json"); - return _realtimeService.getSiriJsonSerializer().getJson(_response, _request.getParameter("callback")); + Calendar gregorianCalendar = new GregorianCalendar(); + gregorianCalendar.setTimeInMillis(responseTimestamp); + gregorianCalendar.add(Calendar.MINUTE, 1); + stopMonitoringDelivery.setValidUntil(gregorianCalendar.getTime()); + + stopMonitoringDelivery.getMonitoredStopVisit().addAll(visits); + + serviceDelivery.setResponseTimestamp(new Date(responseTimestamp)); + + _serviceAlertsHelper.addSituationExchangeToSiriForStops(serviceDelivery, visits, _transitDataService, stopIds); + _serviceAlertsHelper.addGlobalServiceAlertsToServiceDelivery(serviceDelivery, _realtimeService); } - } catch(Exception e) { - return e.getMessage(); - } - } - @Override - public void setServletRequest(HttpServletRequest request) { - this._request = request; - } + Siri siri = new Siri(); + siri.setServiceDelivery(serviceDelivery); - @Override - public void setServletResponse(HttpServletResponse servletResponse) { - this._servletResponse = servletResponse; - } - - public HttpServletResponse getServletResponse(){ - return _servletResponse; + return siri; } - - private void processGoogleAnalytics(){ - processGoogleAnalyticsPageView(); - processGoogleAnalyticsApiKeys(); - } - - private void processGoogleAnalyticsPageView(){ - _gaService.post(new PageViewHit()); - } - - private void processGoogleAnalyticsApiKeys(){ - String apiKey = _request.getParameter("key"); - if(StringUtils.isBlank(apiKey)) - apiKey = "Key Information Unavailable"; - - _gaService.post(new EventHit(GA_EVENT_CATEGORY, GA_EVENT_ACTION, apiKey, 1)); - } - + } diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/StopMonitoringV2Action.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/StopMonitoringV2Action.java index 5585220da8..7c42b49dcb 100644 --- a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/StopMonitoringV2Action.java +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/StopMonitoringV2Action.java @@ -23,21 +23,14 @@ import java.util.List; import java.util.Map; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.lang.StringUtils; import org.apache.struts2.interceptor.ServletRequestAware; import org.apache.struts2.interceptor.ServletResponseAware; import org.apache.struts2.rest.DefaultHttpHeaders; -import org.onebusaway.api.actions.siri.impl.ServiceAlertsHelperV2; import org.onebusaway.api.actions.siri.impl.SiriSupportV2; import org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters; import org.onebusaway.api.actions.siri.model.DetailLevel; import org.onebusaway.gtfs.model.AgencyAndId; import org.onebusaway.presentation.impl.DateUtil; -import org.onebusaway.util.impl.analytics.GoogleAnalyticsServiceImpl; -import org.springframework.beans.factory.annotation.Autowired; import uk.org.siri.siri_2.ErrorDescriptionStructure; import uk.org.siri.siri_2.MonitoredStopVisitStructure; @@ -47,47 +40,17 @@ import uk.org.siri.siri_2.Siri; import uk.org.siri.siri_2.StopMonitoringDeliveryStructure; -import com.brsanthu.googleanalytics.EventHit; -import com.brsanthu.googleanalytics.PageViewHit; - -public class StopMonitoringV2Action extends MonitoringActionBase +public class StopMonitoringV2Action extends MonitoringActionV2Base implements ServletRequestAware, ServletResponseAware { private static final long serialVersionUID = 1L; - @Autowired - private GoogleAnalyticsServiceImpl _gaService; - - - private Siri _response; - - private ServiceAlertsHelperV2 _serviceAlertsHelper = new ServiceAlertsHelperV2(); - - private HttpServletRequest _request; - - private HttpServletResponse _servletResponse; - - // See urlrewrite.xml as to how this is set. Which means this action doesn't - // respect an HTTP Accept: header. - private String _type = "xml"; -/* - private MonitoringActionSupport _monitoringActionSupport = new MonitoringActionSupport(); -*/ - public void setType(String type) { - _type = type; - } -/* - @Override - public String execute() { - */ public DefaultHttpHeaders index() throws IOException { long responseTimestamp = getTime(); - //_monitoringActionSupport.setupGoogleAnalytics(_request, - // _configurationService); processGoogleAnalytics(); _realtimeService.setTime(responseTimestamp); - String detailLevelParam = _request.getParameter(STOP_MONITORING_DETAIL_LEVEL); + String detailLevelParam = _servletRequest.getParameter(STOP_MONITORING_DETAIL_LEVEL); //get the detail level parameter or set it to default if not specified DetailLevel detailLevel; @@ -100,13 +63,13 @@ public DefaultHttpHeaders index() throws IOException { } // User Parameters - String lineRef = _request.getParameter(LINE_REF); - String monitoringRef = _request.getParameter(MONITORING_REF); - String directionId = _request.getParameter(DIRECTION_REF); - String agencyId = _request.getParameter(OPERATOR_REF); - String maxOnwardCallsParam = _request.getParameter(MAX_ONWARD_CALLS); - String maxStopVisitsParam = _request.getParameter(MAX_STOP_VISITS); - String minStopVisitsParam = _request.getParameter(MIN_STOP_VISITS); + String lineRef = _servletRequest.getParameter(LINE_REF); + String monitoringRef = _servletRequest.getParameter(MONITORING_REF); + String directionId = _servletRequest.getParameter(DIRECTION_REF); + String agencyId = _servletRequest.getParameter(OPERATOR_REF); + String maxOnwardCallsParam = _servletRequest.getParameter(MAX_ONWARD_CALLS); + String maxStopVisitsParam = _servletRequest.getParameter(MAX_STOP_VISITS); + String minStopVisitsParam = _servletRequest.getParameter(MIN_STOP_VISITS); // Error Strings String routeIdsErrorString = ""; @@ -175,16 +138,11 @@ public DefaultHttpHeaders index() throws IOException { error = new Exception(errorString); } - _response = generateSiriResponse(visits, stopIds, error, + _siriResponse = generateSiriResponse(visits, stopIds, error, responseTimestamp); - try { - this._servletResponse.getWriter().write(getStopMonitoring()); - } catch (IOException e) { - e.printStackTrace(); - } - - return null; + // use ApiActionSupport to set proper headers instead of writing directly to response + return setOkResponseText(getSiri()); } private Siri generateSiriResponse(List visits, @@ -237,51 +195,4 @@ private Siri generateSiriResponse(List visits, return siri; } - - public String getStopMonitoring() { - try { - if (_type.equals("xml")) { - this._servletResponse.setContentType("application/xml"); - return _realtimeService.getSiriXmlSerializer() - .getXml(_response); - } else { - this._servletResponse.setContentType("application/json"); - return _realtimeService.getSiriJsonSerializer().getJson( - _response, _request.getParameter("callback")); - } - } catch (Exception e) { - return e.getMessage(); - } - } - - @Override - public void setServletRequest(HttpServletRequest request) { - this._request = request; - } - - @Override - public void setServletResponse(HttpServletResponse servletResponse) { - this._servletResponse = servletResponse; - } - - public HttpServletResponse getServletResponse() { - return _servletResponse; - } - - private void processGoogleAnalytics(){ - processGoogleAnalyticsPageView(); - processGoogleAnalyticsApiKeys(); - } - - private void processGoogleAnalyticsPageView(){ - _gaService.post(new PageViewHit()); - } - - private void processGoogleAnalyticsApiKeys(){ - String apiKey = _request.getParameter("key"); - if(StringUtils.isBlank(apiKey)) - apiKey = "Key Information Unavailable"; - - _gaService.post(new EventHit(GA_EVENT_CATEGORY, GA_EVENT_ACTION, apiKey, 1)); - } } diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/StopPointsV2Action.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/StopPointsV2Action.java index 1c78430435..03c8c80613 100644 --- a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/StopPointsV2Action.java +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/StopPointsV2Action.java @@ -23,9 +23,6 @@ import java.util.List; import java.util.Map; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.lang.StringUtils; import org.apache.struts2.interceptor.ServletRequestAware; import org.apache.struts2.interceptor.ServletResponseAware; @@ -34,14 +31,8 @@ import org.onebusaway.api.actions.siri.model.DetailLevel; import org.onebusaway.geospatial.model.CoordinateBounds; import org.onebusaway.gtfs.model.AgencyAndId; -//import org.onebusaway.nyc.siri.support.SiriUpcomingServiceExtension; import org.onebusaway.presentation.impl.DateUtil; import org.onebusaway.transit_data_federation.siri.SiriUpcomingServiceExtension; -import org.onebusaway.util.impl.analytics.GoogleAnalyticsServiceImpl; -import org.springframework.beans.factory.annotation.Autowired; - -import com.brsanthu.googleanalytics.EventHit; -import com.brsanthu.googleanalytics.PageViewHit; import uk.org.siri.siri_2.AnnotatedStopPointStructure; import uk.org.siri.siri_2.ErrorDescriptionStructure; @@ -51,29 +42,12 @@ import uk.org.siri.siri_2.Siri; import uk.org.siri.siri_2.StopPointsDeliveryStructure; -public class StopPointsV2Action extends MonitoringActionBase +public class StopPointsV2Action extends MonitoringActionV2Base implements ServletRequestAware, ServletResponseAware { private static final long serialVersionUID = 1L; - @Autowired - private GoogleAnalyticsServiceImpl _gaService; - - private Siri _response; - - private HttpServletRequest _request; - - private HttpServletResponse _servletResponse; - - // See urlrewrite.xml as to how this is set. Which means this action doesn't - // respect an HTTP Accept: header. - private String _type = "xml"; - - public void setType(String type) { - _type = type; - } - - public DefaultHttpHeaders index() throws IOException { + public DefaultHttpHeaders index() throws IOException { long responseTimestamp = getTime(); processGoogleAnalytics(); @@ -87,13 +61,13 @@ public DefaultHttpHeaders index() throws IOException { boolean validBoundDistance = true; // User Parameters - String boundingBox = _request.getParameter(BOUNDING_BOX); - String circle = _request.getParameter(CIRCLE); - String lineRef = _request.getParameter(LINE_REF); - String directionId = _request.getParameter(DIRECTION_REF); - String agencyId = _request.getParameter(OPERATOR_REF); - String hasUpcomingScheduledService = _request.getParameter(UPCOMING_SCHEDULED_SERVICE); - String detailLevelParam = _request.getParameter(STOP_POINTS_DETAIL_LEVEL); + String boundingBox = _servletRequest.getParameter(BOUNDING_BOX); + String circle = _servletRequest.getParameter(CIRCLE); + String lineRef = _servletRequest.getParameter(LINE_REF); + String directionId = _servletRequest.getParameter(DIRECTION_REF); + String agencyId = _servletRequest.getParameter(OPERATOR_REF); + String hasUpcomingScheduledService = _servletRequest.getParameter(UPCOMING_SCHEDULED_SERVICE); + String detailLevelParam = _servletRequest.getParameter(STOP_POINTS_DETAIL_LEVEL); //get the detail level parameter or set it to default if not specified @@ -168,7 +142,7 @@ else if(StringUtils.isNotBlank(boundingBox)){ // Error Handler Exception error = null; if ((bounds == null && !useLineRefOnly) || - (_request.getParameter(LINE_REF) != null && routeIds.size() == 0) || + (_servletRequest.getParameter(LINE_REF) != null && routeIds.size() == 0) || !validBoundDistance) { String errorString = (boundsErrorString + " " + routeIdsErrorString).trim(); error = new Exception(errorString); @@ -191,15 +165,10 @@ else if(StringUtils.isNotBlank(boundingBox)){ } - _response = generateSiriResponse(stopPoints, upcomingServiceAllStops, error, responseTimestamp); - - try { - this._servletResponse.getWriter().write(getStopPoints()); - } catch (IOException e) { - e.printStackTrace(); - } + _siriResponse = generateSiriResponse(stopPoints, upcomingServiceAllStops, error, responseTimestamp); - return null; + // use ApiActionSupport to set proper headers instead of writing directly to response + return setOkResponseText(getSiri()); } private Siri generateSiriResponse( @@ -262,53 +231,4 @@ private Siri generateSiriResponse( return siri; } - public String getStopPoints() { - try { - if (_type.equals("xml")) { - this._servletResponse.setContentType("application/xml"); - return _realtimeService.getSiriXmlSerializer() - .getXml(_response); - } else { - this._servletResponse.setContentType("application/json"); - return _realtimeService.getSiriJsonSerializer().getJson( - _response, _request.getParameter("callback")); - } - } catch (Exception e) { - return e.getMessage(); - } - } - - @Override - public void setServletRequest(HttpServletRequest request) { - this._request = request; - } - - @Override - public void setServletResponse(HttpServletResponse servletResponse) { - this._servletResponse = servletResponse; - } - - public HttpServletResponse getServletResponse() { - return _servletResponse; - } - - private void processGoogleAnalytics(){ - if (_gaService == null) { - return; - } - processGoogleAnalyticsPageView(); - processGoogleAnalyticsApiKeys(); - } - - private void processGoogleAnalyticsPageView(){ - _gaService.post(new PageViewHit()); - } - - private void processGoogleAnalyticsApiKeys(){ - String apiKey = _request.getParameter("key"); - if(StringUtils.isBlank(apiKey)) - apiKey = "Key Information Unavailable"; - - _gaService.post(new EventHit(GA_EVENT_CATEGORY, GA_EVENT_ACTION, apiKey, 1)); - } } diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/VehicleMonitoringAction.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/VehicleMonitoringAction.java index e2ba5cfbea..526f32ea28 100644 --- a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/VehicleMonitoringAction.java +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/VehicleMonitoringAction.java @@ -23,30 +23,17 @@ import java.util.List; import java.util.Map; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.lang3.StringUtils; -import org.apache.struts2.interceptor.ServletRequestAware; -import org.apache.struts2.interceptor.ServletResponseAware; -import org.onebusaway.api.actions.api.ApiActionSupport; +import org.apache.struts2.rest.DefaultHttpHeaders; import org.onebusaway.geospatial.model.CoordinateBounds; import org.onebusaway.gtfs.model.AgencyAndId; import org.onebusaway.transit_data.model.ListBean; import org.onebusaway.transit_data.model.VehicleStatusBean; -import org.onebusaway.transit_data.services.TransitDataService; import org.onebusaway.util.AgencyAndIdLibrary; -import org.onebusaway.util.impl.analytics.GoogleAnalyticsServiceImpl; -import org.onebusaway.presentation.impl.service_alerts.ServiceAlertsHelper; import org.onebusaway.presentation.services.cachecontrol.CacheService; -import org.onebusaway.presentation.services.realtime.RealtimeService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import com.brsanthu.googleanalytics.EventHit; -import com.brsanthu.googleanalytics.PageViewHit; - import uk.org.siri.siri.ErrorDescriptionStructure; import uk.org.siri.siri.MonitoredVehicleJourneyStructure; import uk.org.siri.siri.OtherErrorStructure; @@ -56,41 +43,16 @@ import uk.org.siri.siri.VehicleActivityStructure; import uk.org.siri.siri.VehicleMonitoringDeliveryStructure; -public class VehicleMonitoringAction extends ApiActionSupport - implements ServletRequestAware, ServletResponseAware { +public class VehicleMonitoringAction extends MonitoringActionV1Base { private static final long serialVersionUID = 1L; protected static Logger _log = LoggerFactory.getLogger(VehicleMonitoringAction.class); private static final int V3 = 3; - - private static final String GA_EVENT_ACTION = "API Key Request"; - - private static final String GA_EVENT_CATEGORY = "Vehicle Monitoring"; - @Autowired - public TransitDataService _transitDataService; - - @Autowired - private RealtimeService _realtimeService; - - private GoogleAnalyticsServiceImpl _gaService; - - private Siri _response; - private String _cachedResponse = null; - private ServiceAlertsHelper _serviceAlertsHelper = new ServiceAlertsHelper(); - - HttpServletRequest _request; - - private HttpServletResponse _servletResponse; - - // See urlrewrite.xml as to how this is set. Which means this action doesn't - // respect an HTTP Accept: header. - private String _type = "xml"; - @Autowired private CacheService _cacheService; @@ -98,17 +60,8 @@ public VehicleMonitoringAction() { super(V3); } - public void setType(String type) { - _type = type; - } - - @Autowired - public void set_gaService(GoogleAnalyticsServiceImpl _gaService) { - this._gaService = _gaService; - } - //@Override - public String index() { + public DefaultHttpHeaders index() throws IOException { processGoogleAnalytics(); @@ -116,11 +69,11 @@ public String index() { _realtimeService.setTime(currentTimestamp); - String directionId = _request.getParameter("DirectionRef"); + String directionId = _servletRequest.getParameter(DIRECTION_REF); - String tripId = _request.getParameter("TripId"); + String tripId = _servletRequest.getParameter(TRIP_ID); - boolean showRawLocation = Boolean.valueOf(_request.getParameter("ShowRawLocation")); + boolean showRawLocation = Boolean.valueOf(_servletRequest.getParameter(RAW_LOCATION)); // We need to support the user providing no agency id which means 'all agencies'. // So, this array will hold a single agency if the user provides it or all @@ -128,7 +81,7 @@ public String index() { // querying for vehicles and routes List agencyIds = new ArrayList(); - String agencyId = _request.getParameter("OperatorRef"); + String agencyId = _servletRequest.getParameter(OPERATOR_REF); if (agencyId != null) { agencyIds.add(agencyId); @@ -138,16 +91,16 @@ public String index() { } List vehicleIds = new ArrayList(); - if (_request.getParameter("VehicleRef") != null) { + if (_servletRequest.getParameter(VEHICLE_REF) != null) { try { // If the user included an agency id as part of the vehicle id, ignore any OperatorRef arg // or lack of OperatorRef arg and just use the included one. - AgencyAndId vehicleId = AgencyAndIdLibrary.convertFromString(_request.getParameter("VehicleRef")); + AgencyAndId vehicleId = AgencyAndIdLibrary.convertFromString(_servletRequest.getParameter(VEHICLE_REF)); vehicleIds.add(vehicleId); } catch (Exception e) { // The user didn't provide an agency id in the VehicleRef, so use our list of operator refs for (String agency : agencyIds) { - AgencyAndId vehicleId = new AgencyAndId(agency, _request.getParameter("VehicleRef")); + AgencyAndId vehicleId = new AgencyAndId(agency, _servletRequest.getParameter(VEHICLE_REF)); vehicleIds.add(vehicleId); } } @@ -155,10 +108,10 @@ public String index() { List routeIds = new ArrayList(); String routeIdErrorString = ""; - if (_request.getParameter("LineRef") != null) { + if (_servletRequest.getParameter(LINE_REF) != null) { try { // Same as above for vehicle id - AgencyAndId routeId = AgencyAndIdLibrary.convertFromString(_request.getParameter("LineRef")); + AgencyAndId routeId = AgencyAndIdLibrary.convertFromString(_servletRequest.getParameter(LINE_REF)); if (isValidRoute(routeId)) { routeIds.add(routeId); } else { @@ -167,7 +120,7 @@ public String index() { } catch (Exception e) { // Same as above for vehicle id for (String agency : agencyIds) { - AgencyAndId routeId = new AgencyAndId(agency, _request.getParameter("LineRef")); + AgencyAndId routeId = new AgencyAndId(agency, _servletRequest.getParameter(LINE_REF)); if (isValidRoute(routeId)) { routeIds.add(routeId); } else { @@ -177,14 +130,14 @@ public String index() { } } - String detailLevel = _request.getParameter("VehicleMonitoringDetailLevel"); + String detailLevel = _servletRequest.getParameter(VEHICLE_MONITORING_DETAIL_LEVEL); int maximumOnwardCalls = 0; if (detailLevel != null && detailLevel.equals("calls")) { maximumOnwardCalls = Integer.MAX_VALUE; try { - maximumOnwardCalls = Integer.parseInt(_request.getParameter("MaximumNumberOfCallsOnwards")); + maximumOnwardCalls = Integer.parseInt(_servletRequest.getParameter(MAX_ONWARD_CALLS)); } catch (NumberFormatException e) { maximumOnwardCalls = Integer.MAX_VALUE; } @@ -204,10 +157,10 @@ public String index() { } // No vehicle id validation, so we pass null for error - _response = generateSiriResponse(activities, null, null, currentTimestamp); + _siriResponse = generateSiriResponse(activities, null, null, currentTimestamp); // *** CASE 2: by route, using direction id, if provided - } else if (_request.getParameter("LineRef") != null) { + } else if (_servletRequest.getParameter(LINE_REF) != null) { List activities = new ArrayList(); for (AgencyAndId routeId : routeIds) { @@ -237,16 +190,16 @@ public String index() { } Exception error = null; - if (_request.getParameter("LineRef") != null && routeIds.size() == 0) { + if (_servletRequest.getParameter(LINE_REF) != null && routeIds.size() == 0) { error = new Exception(routeIdErrorString.trim()); } - _response = generateSiriResponse(activities, routeIds, error, currentTimestamp); + _siriResponse = generateSiriResponse(activities, routeIds, error, currentTimestamp); // *** CASE 3: all vehicles } else { try { - int hashKey = _cacheService.hash(maximumOnwardCalls, agencyIds, _type); + int hashKey = _cacheService.hash(maximumOnwardCalls, agencyIds, getType()); List activities = new ArrayList(); if (!_cacheService.containsKey(hashKey)) { @@ -264,9 +217,9 @@ public String index() { } } // There is no input (route id) to validate, so pass null error - _response = generateSiriResponse(activities, null, null, + _siriResponse = generateSiriResponse(activities, null, null, currentTimestamp); - _cacheService.store(hashKey, getVehicleMonitoring()); + _cacheService.store(hashKey, getSiri()); } else { _cachedResponse = _cacheService.retrieve(hashKey); } @@ -275,14 +228,9 @@ public String index() { throw new RuntimeException(e); } } - - try { - this._servletResponse.getWriter().write(getVehicleMonitoring()); - } catch (IOException e) { - e.printStackTrace(); - } - return null; + // use ApiActionSupport to set proper headers instead of writing directly to response + return setOkResponseText(getSiri()); } /** @@ -338,55 +286,12 @@ private boolean isValidRoute(AgencyAndId routeId) { return false; } - public String getVehicleMonitoring() { + public String getSiri() { if (_cachedResponse != null) { // check the cache first return _cachedResponse; } - - try { - if (_type.equals("xml")) { - this._servletResponse.setContentType("application/xml"); - return _realtimeService.getSiriXmlSerializer().getXml(_response); - } else { - this._servletResponse.setContentType("application/json"); - return _realtimeService.getSiriJsonSerializer().getJson(_response, - _request.getParameter("callback")); - } - } catch (Exception e) { - return e.getMessage(); - } + return super.getSiri(); } - @Override - public void setServletRequest(HttpServletRequest request) { - this._request = request; - } - - @Override - public void setServletResponse(HttpServletResponse servletResponse) { - this._servletResponse = servletResponse; - } - - public HttpServletResponse getServletResponse(){ - return _servletResponse; - } - - private void processGoogleAnalytics(){ -// processGoogleAnalyticsPageView(); -// processGoogleAnalyticsApiKeys(); - } - - private void processGoogleAnalyticsPageView(){ - _gaService.post(new PageViewHit()); - } - - private void processGoogleAnalyticsApiKeys(){ - String apiKey = _request.getParameter("key"); - if(StringUtils.isBlank(apiKey)) - apiKey = "Key Information Unavailable"; - - _gaService.post(new EventHit(GA_EVENT_CATEGORY, GA_EVENT_ACTION, apiKey, 1)); - } - } \ No newline at end of file diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/VehicleMonitoringV2Action.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/VehicleMonitoringV2Action.java index 2def098460..55ce275f95 100644 --- a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/VehicleMonitoringV2Action.java +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/actions/siri/VehicleMonitoringV2Action.java @@ -21,14 +21,7 @@ import java.util.GregorianCalendar; import java.util.List; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.lang.StringUtils; -import org.apache.struts2.interceptor.ServletRequestAware; -import org.apache.struts2.interceptor.ServletResponseAware; import org.apache.struts2.rest.DefaultHttpHeaders; -import org.onebusaway.api.actions.siri.impl.ServiceAlertsHelperV2; import org.onebusaway.api.actions.siri.impl.SiriSupportV2; import org.onebusaway.api.actions.siri.model.DetailLevel; import org.onebusaway.gtfs.model.AgencyAndId; @@ -36,13 +29,8 @@ import org.onebusaway.transit_data.model.ListBean; import org.onebusaway.transit_data.model.VehicleStatusBean; import org.onebusaway.util.AgencyAndIdLibrary; -import org.onebusaway.util.impl.analytics.GoogleAnalyticsServiceImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; - -import com.brsanthu.googleanalytics.EventHit; -import com.brsanthu.googleanalytics.PageViewHit; import uk.org.siri.siri_2.ErrorDescriptionStructure; import uk.org.siri.siri_2.MonitoredVehicleJourneyStructure; @@ -53,47 +41,23 @@ import uk.org.siri.siri_2.VehicleActivityStructure; import uk.org.siri.siri_2.VehicleMonitoringDeliveryStructure; -public class VehicleMonitoringV2Action extends MonitoringActionBase - implements ServletRequestAware, ServletResponseAware { +public class VehicleMonitoringV2Action extends MonitoringActionV2Base { private static final long serialVersionUID = 1L; protected static Logger _log = LoggerFactory.getLogger(VehicleMonitoringV2Action.class); private static final String VEHICLE_REF = "VehicleRef"; - @Autowired - private GoogleAnalyticsServiceImpl _gaService; - - private Siri _response; - private String _cachedResponse = null; - private ServiceAlertsHelperV2 _serviceAlertsHelper = new ServiceAlertsHelperV2(); - - HttpServletRequest _request; - - private HttpServletResponse _servletResponse; - - // See urlrewrite.xml as to how this is set. Which means this action doesn't - // respect an HTTP Accept: header. - private String _type = "xml"; - - //private MonitoringActionSupport _monitoringActionSupport = new MonitoringActionSupport(); - - public void setType(String type) { - _type = type; - } - public DefaultHttpHeaders index() throws IOException { long currentTimestamp = getTime(); processGoogleAnalytics(); - //_monitoringActionSupport.setupGoogleAnalytics(_request, _configurationService); - _realtimeService.setTime(currentTimestamp); - String detailLevelParam = _request.getParameter(VEHICLE_MONITORING_DETAIL_LEVEL); + String detailLevelParam = _servletRequest.getParameter(VEHICLE_MONITORING_DETAIL_LEVEL); //get the detail level parameter or set it to default if not specified DetailLevel detailLevel; @@ -106,13 +70,13 @@ public DefaultHttpHeaders index() throws IOException { } // User Parameters - String lineRef = _request.getParameter(LINE_REF); - String vehicleRef = _request.getParameter(VEHICLE_REF); - String directionId = _request.getParameter(DIRECTION_REF); - String agencyId = _request.getParameter(OPERATOR_REF); - String maxOnwardCallsParam = _request.getParameter(MAX_ONWARD_CALLS); - String maxStopVisitsParam = _request.getParameter(MAX_STOP_VISITS); - String minStopVisitsParam = _request.getParameter(MIN_STOP_VISITS); + String lineRef = _servletRequest.getParameter(LINE_REF); + String vehicleRef = _servletRequest.getParameter(VEHICLE_REF); + String directionId = _servletRequest.getParameter(DIRECTION_REF); + String agencyId = _servletRequest.getParameter(OPERATOR_REF); + String maxOnwardCallsParam = _servletRequest.getParameter(MAX_ONWARD_CALLS); + String maxStopVisitsParam = _servletRequest.getParameter(MAX_STOP_VISITS); + String minStopVisitsParam = _servletRequest.getParameter(MIN_STOP_VISITS); // Error Strings String routeIdsErrorString = ""; @@ -159,7 +123,7 @@ public DefaultHttpHeaders index() throws IOException { } // No vehicle id validation, so we pass null for error - _response = generateSiriResponse(activities, null, null, currentTimestamp); + _siriResponse = generateSiriResponse(activities, null, null, currentTimestamp); // *** CASE 2: by route, using direction id, if provided } else if (lineRef != null) { @@ -199,7 +163,7 @@ public DefaultHttpHeaders index() throws IOException { error = new Exception(routeIdsErrorString.trim()); } - _response = generateSiriResponse(activities, routeIds, error, currentTimestamp); + _siriResponse = generateSiriResponse(activities, routeIds, error, currentTimestamp); // *** CASE 3: all vehicles } else { @@ -224,7 +188,7 @@ public DefaultHttpHeaders index() throws IOException { } } // There is no input (route id) to validate, so pass null error - _response = generateSiriResponse(activities, null, null, + _siriResponse = generateSiriResponse(activities, null, null, currentTimestamp); //_siriCacheService.store(hashKey, getVehicleMonitoring()); //} else { @@ -235,24 +199,12 @@ public DefaultHttpHeaders index() throws IOException { throw new RuntimeException(e); } } - - //if (_monitoringActionSupport.canReportToGoogleAnalytics(_configurationService)) { - // _monitoringActionSupport.reportToGoogleAnalytics(_request, "Vehicle Monitoring", gaLabel, _configurationService); - //} - - try { - this._servletResponse.getWriter().write(getVehicleMonitoring()); - } catch (IOException e) { - e.printStackTrace(); - } - - return null; + return setOkResponseText(getSiri()); } /** * Generate a siri response for a set of VehicleActivities * - * @param routeId */ private Siri generateSiriResponse(List activities, List routeIds, Exception error, long currentTimestamp) { @@ -295,54 +247,11 @@ private Siri generateSiriResponse(List activities, return siri; } - public String getVehicleMonitoring() { + public String getSiri() { if (_cachedResponse != null) { // check the cache first return _cachedResponse; } - - try { - if (_type.equals("xml")) { - this._servletResponse.setContentType("application/xml"); - return _realtimeService.getSiriXmlSerializer().getXml(_response); - } else { - this._servletResponse.setContentType("application/json"); - return _realtimeService.getSiriJsonSerializer().getJson(_response, - _request.getParameter("callback")); - } - } catch (Exception e) { - return e.getMessage(); - } - } - - @Override - public void setServletRequest(HttpServletRequest request) { - this._request = request; - } - - @Override - public void setServletResponse(HttpServletResponse servletResponse) { - this._servletResponse = servletResponse; - } - - public HttpServletResponse getServletResponse(){ - return _servletResponse; - } - - private void processGoogleAnalytics(){ - processGoogleAnalyticsPageView(); - processGoogleAnalyticsApiKeys(); - } - - private void processGoogleAnalyticsPageView(){ - _gaService.post(new PageViewHit()); - } - - private void processGoogleAnalyticsApiKeys(){ - String apiKey = _request.getParameter("key"); - if(StringUtils.isBlank(apiKey)) - apiKey = "Key Information Unavailable"; - - _gaService.post(new EventHit(GA_EVENT_CATEGORY, GA_EVENT_ACTION, apiKey, 1)); + return super.getSiri(); } } diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/impl/CustomJsonLibHandler.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/impl/CustomJsonLibHandler.java index 074cddb58d..4ed027e571 100644 --- a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/impl/CustomJsonLibHandler.java +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/impl/CustomJsonLibHandler.java @@ -15,138 +15,92 @@ */ package org.onebusaway.api.impl; -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import java.util.Collection; - -import javax.servlet.http.HttpServletRequest; - +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.*; import com.opensymphony.xwork2.ActionInvocation; -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; -import net.sf.json.JsonConfig; - +import com.opensymphony.xwork2.inject.Inject; import org.apache.struts2.ServletActionContext; -import org.apache.struts2.rest.handler.ContentTypeHandler; - -/** - * Handles JSON content using json-lib - */ -public class CustomJsonLibHandler implements ContentTypeHandler { - - public void toObject(Reader in, Object target) throws IOException { - StringBuilder sb = new StringBuilder(); - char[] buffer = new char[1024]; - int len = 0; - while ((len = in.read(buffer)) > 0) { - sb.append(buffer, 0, len); - } - if (target != null && sb.length() > 0 && sb.charAt(0) == '[') { - JSONArray jsonArray = JSONArray.fromObject(sb.toString()); - if (target.getClass().isArray()) { - JSONArray.toArray(jsonArray, target, new JsonConfig()); - } else { - JSONArray.toList(jsonArray, target, new JsonConfig()); - } - - } else { - JSONObject jsonObject = JSONObject.fromObject(sb.toString()); - JSONObject.toBean(jsonObject, target, new JsonConfig()); - } - } - - @Override - public void toObject(ActionInvocation actionInvocation, Reader in, Object target) throws IOException { - StringBuilder sb = new StringBuilder(); - char[] buffer = new char[1024]; - int len = 0; - while ((len = in.read(buffer)) > 0) { - sb.append(buffer, 0, len); - } - if (target != null && sb.length() > 0 && sb.charAt(0) == '[') { - JSONArray jsonArray = JSONArray.fromObject(sb.toString()); - if (target.getClass().isArray()) { - JSONArray.toArray(jsonArray, target, new JsonConfig()); - } else { - JSONArray.toList(jsonArray, target, new JsonConfig()); - } - - } else { - JSONObject jsonObject = JSONObject.fromObject(sb.toString()); - JSONObject.toBean(jsonObject, target, new JsonConfig()); - } - - } +import org.apache.struts2.rest.handler.AbstractContentTypeHandler; +import org.onebusaway.api.model.ResponseBean; +import org.onebusaway.api.serializers.json.CustomSerializerProvider; - public String fromObject(Object obj, String resultCode, Writer stream) - throws IOException { - - String callback = null; - HttpServletRequest req = ServletActionContext.getRequest(); - if (req != null) - callback = req.getParameter("callback"); - - String value = null; - - if (obj != null) { - if (isArray(obj)) { - JSONArray jsonArray = JSONArray.fromObject(obj); - value = jsonArray.toString(); - } else { - JSONObject jsonObject = JSONObject.fromObject(obj); - value = jsonObject.toString(); - } - } - - if (value != null) { - if (callback != null) - stream.write(callback + "(" + value + ")"); - else - stream.write(value); - } - - return null; - } - - @Override - public String fromObject(ActionInvocation actionInvocation, Object obj, String s, Writer stream) throws IOException { - String callback = null; - HttpServletRequest req = ServletActionContext.getRequest(); - if (req != null) - callback = req.getParameter("callback"); - - String value = null; - - if (obj != null) { - if (isArray(obj)) { - JSONArray jsonArray = JSONArray.fromObject(obj); - value = jsonArray.toString(); - } else { - JSONObject jsonObject = JSONObject.fromObject(obj); - value = jsonObject.toString(); - } - } - - if (value != null) { - if (callback != null) - stream.write(callback + "(" + value + ")"); - else - stream.write(value); - } - - return null; - } - - private boolean isArray(Object obj) { - return obj instanceof Collection || obj.getClass().isArray(); - } +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; - public String getContentType() { - return "application/json"; - } - public String getExtension() { - return "json"; - } +public class CustomJsonLibHandler extends AbstractContentTypeHandler { + + private String defaultEncoding = "ISO-8859-1"; + private ObjectMapper mapper = new ObjectMapper(); + + public void toObject(ActionInvocation invocation, Reader in, Object target) throws IOException { + this.mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); + ObjectReader or = this.mapper.readerForUpdating(target); + or.readValue(in); + } + + public String fromObject(ActionInvocation invocation, Object obj, String resultCode, Writer stream) throws IOException { + String callback = getCallback(); + return fromObject(invocation, obj, resultCode, stream, callback); + } + + public String fromObject(ActionInvocation invocation, Object obj, String resultCode, Writer stream, String callback) throws IOException { + boolean isText = false; + String value = null; + if (obj != null && obj instanceof ResponseBean) { + // check if serialization already occurred as with SIRI calls + ResponseBean bean = (ResponseBean) obj; + isText = bean.isString(); + if (bean.getData() != null) { + value = bean.getData().toString(); + } + } + if (obj != null && !isText) { + mapper.setSerializerProvider(new CustomSerializerProvider()); + mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); + mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); + mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); + + value = mapper.writeValueAsString(obj); + } + if (value != null && callback != null) { + stream.write(callback + "(" + value + ")"); + } + else { + stream.write(value); + } + + return null; + } + + public String getCallback(){ + String callback = null; + HttpServletRequest req = ServletActionContext.getRequest(); + if (req != null) { + callback = req.getParameter("callback"); + } + return callback; + } + + public String getContentType() { + String callback = getCallback(); + if(callback != null){ + return "application/javascript"; + } + // we used to set charset for callbacks + // after Jackson upgrade to 2.12.0 this no longer works + //return "application/json;charset=" + this.defaultEncoding; + return "application/json"; + } + + public String getExtension() { + return "json"; + } + + @Inject("struts.i18n.encoding") + public void setDefaultEncoding(String val) { + this.defaultEncoding = val; + } } diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/impl/CustomXStreamHandler.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/impl/CustomXStreamHandler.java index 83525be62e..53678a82fa 100644 --- a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/impl/CustomXStreamHandler.java +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/impl/CustomXStreamHandler.java @@ -55,8 +55,36 @@ import com.thoughtworks.xstream.XStream; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; + public class CustomXStreamHandler extends XStreamHandler { + @Override + public String fromObject(ActionInvocation invocation, Object obj, String resultCode, Writer out) throws IOException { + if (obj != null) { + if (obj instanceof ResponseBean) { + ResponseBean bean = (ResponseBean) obj; + if (bean.isString() && bean.getData() != null) { + out.write(bean.getData().toString()); + return null; + } + XStream xstream = this.createXStream(invocation); + xstream.toXML(obj, out); + } + + } + + return null; + } + + @Override + public void toObject(ActionInvocation invocation, Reader in, Object target) { + XStream xstream = this.createXStream(invocation); + xstream.fromXML(in, target); + } + @Override protected XStream createXStream(ActionInvocation invocation) { return createXStream(); diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/impl/XmlResult.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/impl/XmlResult.java index 10d6e5d60d..9a3b82c298 100644 --- a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/impl/XmlResult.java +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/impl/XmlResult.java @@ -19,11 +19,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.struts2.ServletActionContext; -import org.apache.struts2.dispatcher.StrutsResultSupport; - import com.opensymphony.xwork2.ActionInvocation; +import org.apache.struts2.ServletActionContext; +import org.apache.struts2.result.StrutsResultSupport; + public class XmlResult extends StrutsResultSupport { private static final long serialVersionUID = 1L; diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/serializers/json/CustomSerializerProvider.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/serializers/json/CustomSerializerProvider.java new file mode 100644 index 0000000000..7d36b33332 --- /dev/null +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/serializers/json/CustomSerializerProvider.java @@ -0,0 +1,59 @@ +/** + * Copyright (C) 2021 Cambridge Systematics, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onebusaway.api.serializers.json; + +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider; +import com.fasterxml.jackson.databind.ser.SerializerFactory; + +import java.util.Collection; +import java.util.List; + +public class CustomSerializerProvider extends DefaultSerializerProvider { + + public CustomSerializerProvider() { + super(); + } + + public CustomSerializerProvider(CustomSerializerProvider provider, SerializationConfig config, + SerializerFactory jsf) { + super(provider, config, jsf); + } + + @Override + public CustomSerializerProvider createInstance(SerializationConfig config, SerializerFactory jsf) { + return new CustomSerializerProvider(this, config, jsf); + } + + @Override + public JsonSerializer findNullValueSerializer(BeanProperty property) throws JsonMappingException { + if (property.getType().getRawClass().equals(String.class)) + return Serializers.EMPTY_STRING_SERIALIZER_INSTANCE; + if (property.getType().getRawClass().equals(Long.class)) + return Serializers.NULL_NUMBER_SERIALIZER_INSTANCE; + if (property.getType().getRawClass().equals(Integer.class)) + return Serializers.NULL_NUMBER_SERIALIZER_INSTANCE; + if (property.getType().getRawClass().equals(Double.class)) + return Serializers.NULL_NUMBER_SERIALIZER_INSTANCE; + if (property.getType().getRawClass().equals(Collection.class) || property.getType().getRawClass().equals(List.class)) + return Serializers.NULL_COLLECTION_SERIALIZER_INSTANCE; + else { + // the defaults have changed, so now we explicitly send a hint + // not to serialize null values other than those above + return null; // don't serialize + } + } +} diff --git a/onebusaway-api-webapp/src/main/java/org/onebusaway/api/serializers/json/Serializers.java b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/serializers/json/Serializers.java new file mode 100644 index 0000000000..924f0905e6 --- /dev/null +++ b/onebusaway-api-webapp/src/main/java/org/onebusaway/api/serializers/json/Serializers.java @@ -0,0 +1,69 @@ +/** + * Copyright (C) 2021 Cambridge Systematics, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onebusaway.api.serializers.json; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; + +import java.io.IOException; + +public class Serializers extends JsonSerializer { + public static final JsonSerializer EMPTY_STRING_SERIALIZER_INSTANCE = new EmptyStringSerializer(); + public static final JsonSerializer NULL_NUMBER_SERIALIZER_INSTANCE = new NullNumberSerializer(); + public static final JsonSerializer NULL_COLLECTION_SERIALIZER_INSTANCE = new NullCollectionSerializer(); + + + public Serializers() {} + + @Override + public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) + throws IOException, JsonProcessingException { + jsonGenerator.writeString(""); + } + + private static class EmptyStringSerializer extends JsonSerializer { + public EmptyStringSerializer() {} + + @Override + public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) + throws IOException, JsonProcessingException { + jsonGenerator.writeString(""); + } + } + + private static class NullNumberSerializer extends JsonSerializer { + public NullNumberSerializer() {} + + @Override + public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) + throws IOException, JsonProcessingException { + jsonGenerator.writeNumber(0); + } + } + + private static class NullCollectionSerializer extends JsonSerializer { + public NullCollectionSerializer() {} + + @Override + public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) + throws IOException, JsonProcessingException { + jsonGenerator.writeStartArray(0); + jsonGenerator.writeEndArray(); + } + } +} diff --git a/onebusaway-api-webapp/src/main/resources/data-sources.xml b/onebusaway-api-webapp/src/main/resources/data-sources.xml index a1fe4a42e9..f3368985b2 100644 --- a/onebusaway-api-webapp/src/main/resources/data-sources.xml +++ b/onebusaway-api-webapp/src/main/resources/data-sources.xml @@ -58,7 +58,7 @@ value="true" /> + class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> diff --git a/onebusaway-api-webapp/src/main/resources/log4j.xml b/onebusaway-api-webapp/src/main/resources/log4j.xml index 370b03027c..1dd90545c5 100644 --- a/onebusaway-api-webapp/src/main/resources/log4j.xml +++ b/onebusaway-api-webapp/src/main/resources/log4j.xml @@ -26,7 +26,7 @@ - + diff --git a/onebusaway-api-webapp/src/main/resources/org/onebusaway/api/application-context-webapp.xml b/onebusaway-api-webapp/src/main/resources/org/onebusaway/api/application-context-webapp.xml index af909eb039..7890c26461 100644 --- a/onebusaway-api-webapp/src/main/resources/org/onebusaway/api/application-context-webapp.xml +++ b/onebusaway-api-webapp/src/main/resources/org/onebusaway/api/application-context-webapp.xml @@ -28,7 +28,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> diff --git a/onebusaway-api-webapp/src/main/resources/struts-onebusaway-api-webapp.xml b/onebusaway-api-webapp/src/main/resources/struts-onebusaway-api-webapp.xml index c627af4beb..6ed080eeb4 100644 --- a/onebusaway-api-webapp/src/main/resources/struts-onebusaway-api-webapp.xml +++ b/onebusaway-api-webapp/src/main/resources/struts-onebusaway-api-webapp.xml @@ -18,7 +18,7 @@ --> + "http://struts.apache.org/dtds/struts-2.5.dtd"> diff --git a/onebusaway-api-webapp/src/main/resources/struts.xml b/onebusaway-api-webapp/src/main/resources/struts.xml index 671125f74f..0fa48e08be 100644 --- a/onebusaway-api-webapp/src/main/resources/struts.xml +++ b/onebusaway-api-webapp/src/main/resources/struts.xml @@ -18,7 +18,7 @@ --> + "http://struts.apache.org/dtds/struts-2.5.dtd"> diff --git a/onebusaway-api-webapp/src/main/webapp/WEB-INF/urlrewrite.xml b/onebusaway-api-webapp/src/main/webapp/WEB-INF/urlrewrite.xml index 45a1c1f45f..78d4a86ecb 100644 --- a/onebusaway-api-webapp/src/main/webapp/WEB-INF/urlrewrite.xml +++ b/onebusaway-api-webapp/src/main/webapp/WEB-INF/urlrewrite.xml @@ -24,26 +24,39 @@ --> + + + + + - 2 - ^HTTPS$ - ^([^;]*)/siri/([^.]*)\.(xml|json)(.*)$ - https://%{server-name}/$1/siri/$2-v2$4&type=$3 + null + ^([^;]*)/siri/([^.]*)\.(json|xml)(.*)$ + $1/siri/$2.$3$4&type=$3 + - ^HTTPS$ - ^([^;]*)/siri/([^.]*)\.(xml|json)(.*)$ - https://%{server-name}/$1/siri/$2$4&type=$3 + json + ^([^;]*)/siri/(vehicle-monitoring)[?](.*)$ + $1/siri/$2.json?$3 - + - 2 - ^([^;]*)/siri/([^.]*)\.(xml|json)(.*)$ - $1/siri/$2-v2$4&type=$3 + xml + ^([^;]*)/siri/(vehicle-monitoring)[?](.*)$ + $1/siri/$2.xml?$3 + - ^([^;]*)/siri/([^.]*)\.(xml|json)(.*)$ - $1/siri/$2$4&type=$3 + json + ^([^;]*)/siri/(stop-monitoring)[?](.*)$ + $1/siri/$2.json?$3 - + + + xml + ^([^;]*)/siri/(stop-monitoring)[?](.*)$ + $1/siri/$2.xml?$3 + + diff --git a/onebusaway-api-webapp/src/main/webapp/WEB-INF/web.xml b/onebusaway-api-webapp/src/main/webapp/WEB-INF/web.xml index c75a303c76..24576c8631 100644 --- a/onebusaway-api-webapp/src/main/webapp/WEB-INF/web.xml +++ b/onebusaway-api-webapp/src/main/webapp/WEB-INF/web.xml @@ -46,7 +46,7 @@ struts-prepare-and-execute - org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter + org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter CorsFilter diff --git a/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/api/where/CurrentTimeActionTest.java b/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/api/where/CurrentTimeActionTest.java index 78109d5936..915dce13b8 100644 --- a/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/api/where/CurrentTimeActionTest.java +++ b/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/api/where/CurrentTimeActionTest.java @@ -53,7 +53,7 @@ public void test() throws ParseException { long delta = Math.abs(time.getTime() - t); assertTrue("check that time delta is within limits: delta=" + delta, - delta < 100); + delta < 500); String readableTime = DateLibrary.getTimeAsIso8601String(new Date( time.getTime())); diff --git a/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/siri/RealtimeServiceTest.java b/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/siri/RealtimeServiceTest.java index 4c39efee70..2974c0214c 100644 --- a/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/siri/RealtimeServiceTest.java +++ b/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/siri/RealtimeServiceTest.java @@ -19,6 +19,7 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyLong; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.when; import java.math.BigDecimal; @@ -161,7 +162,7 @@ public void initialize(){ @Test public void testStopPointsByRoute() throws Exception { - when(transitDataService.getRouteForId("1_100194")).thenReturn(routeBean); + lenient().when(transitDataService.getRouteForId("1_100194")).thenReturn(routeBean); when(transitDataService.getStopsForRoute("1_100194")).thenReturn(stopsForRouteBean); when(transitDataService.stopHasUpcomingScheduledService(anyString(), anyLong(), anyString(), anyString(), anyString())).thenReturn(true); @@ -243,7 +244,7 @@ public void testStopPointsByBounds() throws Exception { StopsBean stopsBean = new StopsBean(); stopsBean.setStops(stops); - when(transitDataService.getRouteForId("1_100194")).thenReturn(routeBean); + lenient().when(transitDataService.getRouteForId("1_100194")).thenReturn(routeBean); when(transitDataService.getStops(any(SearchQueryBean.class))).thenReturn(stopsBean); diff --git a/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/siri/StopPointsActionTest.java b/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/siri/StopPointsActionTest.java index b19dc87a8e..e80ff58098 100644 --- a/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/siri/StopPointsActionTest.java +++ b/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/siri/StopPointsActionTest.java @@ -21,12 +21,9 @@ import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyListOf; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.anyMapOf; +import static org.mockito.Mockito.*; +import static org.onebusaway.api.actions.siri.SiriAction.STOP_POINTS_DETAIL_LEVEL; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; @@ -216,21 +213,11 @@ public void initialize() throws Exception{ // XML Serializer SiriXmlSerializerV2 serializer = new SiriXmlSerializerV2(); when(realtimeService.getSiriXmlSerializer()).thenReturn(serializer ); - - //Print Writer - PrintWriter nothingPrintWriter = new PrintWriter(new OutputStream() { - @Override - public void write(int b) throws IOException { - // Do nothing - } - }); - when(servletResponse.getWriter()).thenReturn(nothingPrintWriter); - when(transitDataService.getRouteForId("1_430")).thenReturn(routeBean); - when(transitDataService.getStopsForRoute("1_430")).thenReturn(stopsForRouteBean); - when(transitDataService.stopHasUpcomingScheduledService(anyString(), anyLong(), anyString(), anyString(), anyString())).thenReturn(true); - when(transitDataService.getAgencyIdsWithCoverageArea()).thenReturn(agencies); + lenient().when(transitDataService.getStopsForRoute("1_430")).thenReturn(stopsForRouteBean); + lenient().when(transitDataService.stopHasUpcomingScheduledService(anyString(), anyLong(), anyString(), anyString(), anyString())).thenReturn(true); + lenient().when(transitDataService.getAgencyIdsWithCoverageArea()).thenReturn(agencies); } @@ -245,7 +232,7 @@ public void testLineRef() throws Exception { action.setServletResponse(servletResponse); action.index(); - String monitoring = action.getStopPoints(); + String monitoring = action.getSiri(); System.out.println(monitoring); assertTrue("Result XML does not match expected", monitoring.matches("(?s).*.+.+.+true.+.+(0|1)\\-[0-9]{1,3}?\\.[0-9]+[0-9]{1,2}?\\.[0-9]+true.*")); @@ -256,13 +243,13 @@ public void testLineRef() throws Exception { public void testDetailLevelCase() throws Exception { when(request.getParameter(eq("LineRef"))).thenReturn("430"); - when(request.getParameter(eq("StopPointsDetailLevel"))).thenReturn("Calls"); + when(request.getParameter(eq(STOP_POINTS_DETAIL_LEVEL))).thenReturn("Calls"); action.setServletRequest(request); action.setServletResponse(servletResponse); action.index(); - String monitoring = action.getStopPoints(); + String monitoring = action.getSiri(); System.out.println(monitoring); assertTrue("Result XML does not match expected", monitoring.matches("(?s).*.+.+.+true.+.+(0|1).+.+true.*")); diff --git a/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/siri/VehicleMonitoringActionTest.java b/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/siri/VehicleMonitoringActionTest.java index 298fea3f37..f4a5e1c828 100644 --- a/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/siri/VehicleMonitoringActionTest.java +++ b/onebusaway-api-webapp/src/test/java/org/onebusaway/api/actions/siri/VehicleMonitoringActionTest.java @@ -20,12 +20,8 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @@ -45,13 +41,13 @@ import org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean; import org.onebusaway.transit_data.model.service_alerts.SituationQueryBean; import org.onebusaway.transit_data.services.TransitDataService; +import org.onebusaway.transit_data_federation.siri.SiriJsonSerializer; import org.onebusaway.transit_data_federation.siri.SiriXmlSerializer; import org.onebusaway.util.impl.analytics.GoogleAnalyticsServiceImpl; import org.onebusaway.util.services.configuration.ConfigurationService; import com.brsanthu.googleanalytics.GoogleAnalyticsRequest; import com.brsanthu.googleanalytics.GoogleAnalyticsResponse; -import com.brsanthu.googleanalytics.PageViewHit; import uk.org.siri.siri.LocationStructure; import uk.org.siri.siri.SituationRefStructure; @@ -90,17 +86,9 @@ public void testExecuteByRoute() throws Exception { when(request.getParameter(eq("LineRef"))).thenReturn("40_100479"); when(request.getParameter(eq("OperatorRef"))).thenReturn("1"); - - PrintWriter nothingPrintWriter = new PrintWriter(new OutputStream() { - @Override - public void write(int b) throws IOException { - // Do nothing - } - }); - when(servletResponse.getWriter()).thenReturn(nothingPrintWriter); - + List vehicleActivities = new ArrayList(); - when(realtimeService.getVehicleActivityForRoute(eq("40_100479"), anyString(), eq(0), anyLong(), eq(false))).thenReturn(vehicleActivities); + when(realtimeService.getVehicleActivityForRoute(eq("40_100479"), any(), eq(0), anyLong(), eq(false))).thenReturn(vehicleActivities); VehicleActivityStructure vehicleActivity = new VehicleActivityStructure(); vehicleActivities.add(vehicleActivity); @@ -115,12 +103,12 @@ public void write(int b) throws IOException { locationStructure.setLongitude(BigDecimal.valueOf(89.0)); ServiceAlertBean serviceAlertBean = ServiceAlertsTestSupport.createServiceAlertBean("1_1"); - when(transitDataService.getServiceAlertForId(anyString())).thenReturn(serviceAlertBean ); + lenient().when(transitDataService.getServiceAlertForId(anyString())).thenReturn(serviceAlertBean ); RouteBean routeBean = RouteBean.builder().create(); when(transitDataService.getRouteForId(anyString())).thenReturn(routeBean); - when(configurationService.getConfigurationValueAsString(eq("display.googleAnalyticsSiteId"), anyString())).thenReturn("foo"); + lenient().when(configurationService.getConfigurationValueAsString(eq("display.googleAnalyticsSiteId"), anyString())).thenReturn("foo"); List sitRef = mvJourney.getSituationRef(); SituationRefStructure sitRefStructure = new SituationRefStructure(); @@ -133,34 +121,94 @@ public void write(int b) throws IOException { when(realtimeService.getSiriXmlSerializer()).thenReturn(serializer ); //doNothing().when(gaService).post(new PageViewHit()); - when(gaService.post(new GoogleAnalyticsRequest())).thenReturn(new GoogleAnalyticsResponse()); + lenient().when(gaService.post(new GoogleAnalyticsRequest())).thenReturn(new GoogleAnalyticsResponse()); action.setServletRequest(request); action.setServletResponse(servletResponse); action.index(); - String monitoring = action.getVehicleMonitoring(); + String monitoring = action.getSiri(); assertTrue("Result XML does not match expected", monitoring.matches("(?s).*.+.+.+situation ref89.088.01_1summarydescription1_10027701_10027711_10019401_1001941.*")); } + @Test + public void testExecuteByRouteJson() throws Exception { + + when(request.getParameter(eq("LineRef"))).thenReturn("40_100479"); + when(request.getParameter(eq("OperatorRef"))).thenReturn("1"); + + List vehicleActivities = new ArrayList(); + when(realtimeService.getVehicleActivityForRoute(eq("40_100479"), any(), eq(0), anyLong(), eq(false))).thenReturn(vehicleActivities); + + VehicleActivityStructure vehicleActivity = new VehicleActivityStructure(); + vehicleActivities.add(vehicleActivity); + + MonitoredVehicleJourney mvJourney = new MonitoredVehicleJourney(); + vehicleActivity.setMonitoredVehicleJourney(mvJourney ); + + LocationStructure locationStructure = new LocationStructure(); + mvJourney.setVehicleLocation(locationStructure ); + + locationStructure.setLatitude(BigDecimal.valueOf(88.0)); + locationStructure.setLongitude(BigDecimal.valueOf(89.0)); + + ServiceAlertBean serviceAlertBean = ServiceAlertsTestSupport.createServiceAlertBean("1_1"); + lenient().when(transitDataService.getServiceAlertForId(anyString())).thenReturn(serviceAlertBean ); + + RouteBean routeBean = RouteBean.builder().create(); + when(transitDataService.getRouteForId(anyString())).thenReturn(routeBean); + + lenient().when(configurationService.getConfigurationValueAsString(eq("display.googleAnalyticsSiteId"), anyString())).thenReturn("foo"); + + List sitRef = mvJourney.getSituationRef(); + SituationRefStructure sitRefStructure = new SituationRefStructure(); + sitRef.add(sitRefStructure ); + SituationSimpleRefStructure sitSimpleRef = new SituationSimpleRefStructure(); + sitRefStructure.setSituationSimpleRef(sitSimpleRef ); + sitSimpleRef.setValue("situation ref"); + + SiriJsonSerializer jsonSerializer = new SiriJsonSerializer(); + when(realtimeService.getSiriJsonSerializer()).thenReturn(jsonSerializer); + + lenient().when(gaService.post(new GoogleAnalyticsRequest())).thenReturn(new GoogleAnalyticsResponse()); + action.setType("json"); + action.setServletRequest(request); + action.setServletResponse(servletResponse); + action.index(); + String monitoring = action.getSiri(); + String example = "{\"Siri\":{\"ServiceDelivery\":{\"ResponseTimestamp\":\"2021-10-30T09:10:49.019-07:00\",\"VehicleMonitoringDelivery\":[{\"VehicleActivity\":[{\"MonitoredVehicleJourney\":{\"SituationRef\":[{\"SituationSimpleRef\":\"situation ref\"}],\"VehicleLocation\":{\"Longitude\":89.0,\"Latitude\":88.0}}}],\"ResponseTimestamp\":\"2021-10-30T09:10:49.019-07:00\",\"ValidUntil\":\"2021-10-30T09:11:49.019-07:00\"}],\"SituationExchangeDelivery\":[{\"Situations\":{\"PtSituationElement\":[{\"Summary\":\"summary\",\"Description\":\"description\",\"Affects\":{\"VehicleJourneys\":{\"AffectedVehicleJourney\":[{\"LineRef\":\"1_100277\",\"DirectionRef\":\"0\"},{\"LineRef\":\"1_100277\",\"DirectionRef\":\"1\"},{\"LineRef\":\"1_100194\",\"DirectionRef\":\"0\"},{\"LineRef\":\"1_100194\",\"DirectionRef\":\"1\"}]}},\"SituationNumber\":\"1_1\"}]}}]}}}"; + String matchPattern = "{\"Siri\":{\"ServiceDelivery\":{\"ResponseTimestamp\":\"...-..-.T..:..:......-0.:00\",\"VehicleMonitoringDelivery\":[{\"VehicleActivity\":[{\"MonitoredVehicleJourney\":{\"SituationRef\":[{\"SituationSimpleRef\":\"situation ref\"}],\"VehicleLocation\":{\"Longitude\":89.0,\"Latitude\":88.0}}}],\"ResponseTimestamp\":\"....-..-..T..:..:......-0.:00\",\"ValidUntil\":\"...-..-..T..:..:......-0.:00\"}],\"SituationExchangeDelivery\":[{\"Situations\":{\"PtSituationElement\":[{\"Summary\":\"summary\",\"Description\":\"description\",\"Affects\":{\"VehicleJourneys\":{\"AffectedVehicleJourney\":[{\"LineRef\":\"1_100277\",\"DirectionRef\":\"0\"},{\"LineRef\":\"1_100277\",\"DirectionRef\":\"1\"},{\"LineRef\":\"1_100194\",\"DirectionRef\":\"0\"},{\"LineRef\":\"1_100194\",\"DirectionRef\":\"1\"}]}},\"SituationNumber\":\"1_1\"}]}}]}}}"; + + String[] expectedFragments = { + "ServiceDelivery", "ResponseTimestamp", "VehicleMonitoringDelivery", "VehicleActivity", + "MonitoredVehicleJourney", "SituationRef", "situation ref", + "VehicleLocation", "\"Longitude\":89.0,\"Latitude\":88.0}", + "SituationExchangeDelivery", "\"Summary\":\"summary\"", + "\"Description\":\"description\"", "Affects", "VehicleJourneys", "AffectedVehicleJourney", + "\"LineRef\":\"1_100277\",\"DirectionRef\":\"0\"", "\"LineRef\":\"1_100277\",\"DirectionRef\":\"1\"", + "\"LineRef\":\"1_100194\",\"DirectionRef\":\"0\"", "\"LineRef\":\"1_100194\",\"DirectionRef\":\"1\"", + "\"SituationNumber\":\"1_1\"" + }; + System.out.println("expected=|\n" + monitoring + "\n|"); + for (String s : expectedFragments) { + boolean expectedMatch = monitoring.contains(s); + if (!expectedMatch) { + System.out.println("expected=|" + s + "|"); + System.out.println("actual=|" + monitoring + "|"); + } + assertTrue("Result JSON does not match expected", expectedMatch); + } + } @Test public void testExecuteByRouteNoActivity() throws Exception { when(request.getParameter(eq("LineRef"))).thenReturn("40_100479"); when(request.getParameter(eq("OperatorRef"))).thenReturn("1"); - PrintWriter nothingPrintWriter = new PrintWriter(new OutputStream() { - @Override - public void write(int b) throws IOException { - // Do nothing - } - }); - when(servletResponse.getWriter()).thenReturn(nothingPrintWriter); - List vehicleActivities = new ArrayList(); - when(realtimeService.getVehicleActivityForRoute(eq("40_100479"), anyString(), eq(0), anyLong(), eq(false))).thenReturn(vehicleActivities); + lenient().when(realtimeService.getVehicleActivityForRoute(eq("40_100479"), anyString(), eq(0), anyLong(), eq(false))).thenReturn(vehicleActivities); ServiceAlertBean serviceAlertBean = ServiceAlertsTestSupport.createServiceAlertBean("1_1"); - when(transitDataService.getServiceAlertForId(anyString())).thenReturn(serviceAlertBean ); + lenient().when(transitDataService.getServiceAlertForId(anyString())).thenReturn(serviceAlertBean ); RouteBean routeBean = RouteBean.builder().create(); when(transitDataService.getRouteForId(anyString())).thenReturn(routeBean); @@ -177,7 +225,7 @@ public void write(int b) throws IOException { action.setServletRequest(request); action.setServletResponse(servletResponse); action.index(); - String monitoring = action.getVehicleMonitoring(); + String monitoring = action.getSiri(); String regex = "(?s).*1_1summarydescription1_10027701_10027711_10019401_10019411_1summarydescription1_10027701_10027711_10019401_1001941.*"; boolean success = monitoring.matches(regex); if (!success) { diff --git a/onebusaway-combined-webapp/pom.xml b/onebusaway-combined-webapp/pom.xml index 5ee0279ff5..0505c31cae 100644 --- a/onebusaway-combined-webapp/pom.xml +++ b/onebusaway-combined-webapp/pom.xml @@ -3,7 +3,7 @@ org.onebusaway onebusaway-application-modules - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-combined-webapp pom diff --git a/onebusaway-combined-webapp/src/main/assembly/api-only/WEB-INF/web.xml b/onebusaway-combined-webapp/src/main/assembly/api-only/WEB-INF/web.xml index cb09028dd6..aa812f2f4d 100644 --- a/onebusaway-combined-webapp/src/main/assembly/api-only/WEB-INF/web.xml +++ b/onebusaway-combined-webapp/src/main/assembly/api-only/WEB-INF/web.xml @@ -37,7 +37,7 @@ struts-prepare-and-execute - org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter + org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter UrlRewriteFilter diff --git a/onebusaway-container/pom.xml b/onebusaway-container/pom.xml index d9f38c9908..59aeb04e64 100644 --- a/onebusaway-container/pom.xml +++ b/onebusaway-container/pom.xml @@ -3,7 +3,7 @@ org.onebusaway onebusaway-application-modules - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-container jar @@ -48,7 +48,7 @@ org.hibernate hibernate-ehcache - 4.0.1.Final + 5.2.2.Final net.sf.ehcache diff --git a/onebusaway-container/src/main/java/org/onebusaway/container/hibernate/EnumUserType.java b/onebusaway-container/src/main/java/org/onebusaway/container/hibernate/EnumUserType.java index e118059328..0a1f42b51c 100644 --- a/onebusaway-container/src/main/java/org/onebusaway/container/hibernate/EnumUserType.java +++ b/onebusaway-container/src/main/java/org/onebusaway/container/hibernate/EnumUserType.java @@ -23,7 +23,7 @@ import java.util.Properties; import org.hibernate.HibernateException; -import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.usertype.EnhancedUserType; import org.hibernate.usertype.ParameterizedType; @@ -75,7 +75,7 @@ public int hashCode(Object x) throws HibernateException { @Override @SuppressWarnings("unchecked") public Object nullSafeGet(ResultSet rs, String[] names, - SessionImplementor session, Object owner) throws HibernateException, + SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException, SQLException { String name = rs.getString(names[0]); return rs.wasNull() ? null : Enum.valueOf(enumClass, name); @@ -85,7 +85,7 @@ public Object nullSafeGet(ResultSet rs, String[] names, @Override @SuppressWarnings("unchecked") public void nullSafeSet(PreparedStatement st, Object value, int index, - SessionImplementor session) throws HibernateException, SQLException { + SharedSessionContractImplementor sharedSessionContractImplementor) throws HibernateException, SQLException { if (value == null) { st.setNull(index, Types.VARCHAR); } else { diff --git a/onebusaway-container/src/main/java/org/onebusaway/container/spring/ehcache/EhCacheRegionFactory.java b/onebusaway-container/src/main/java/org/onebusaway/container/spring/ehcache/EhCacheRegionFactory.java index c716d7c221..a8bc28c444 100644 --- a/onebusaway-container/src/main/java/org/onebusaway/container/spring/ehcache/EhCacheRegionFactory.java +++ b/onebusaway-container/src/main/java/org/onebusaway/container/spring/ehcache/EhCacheRegionFactory.java @@ -15,12 +15,13 @@ */ package org.onebusaway.container.spring.ehcache; +import java.util.Map; import java.util.Properties; import net.sf.ehcache.CacheManager; +import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.CacheException; -import org.hibernate.cfg.Settings; /** * A Hibernate EhCacheRegionFactory implementation that supports directly @@ -52,12 +53,12 @@ public EhCacheRegionFactory(Properties prop) { } @Override - public void start(Settings settings, Properties properties) + public void start(SessionFactoryOptions settings, Map configValues) throws CacheException { if (staticCacheManagerInstance != null) manager = staticCacheManagerInstance; else - super.start(settings, properties); + super.start(settings, configValues); } @Override diff --git a/onebusaway-container/src/main/resources/org/onebusaway/container/application-context-caching.xml b/onebusaway-container/src/main/resources/org/onebusaway/container/application-context-caching.xml index e349e10a5e..c96ca89834 100644 --- a/onebusaway-container/src/main/resources/org/onebusaway/container/application-context-caching.xml +++ b/onebusaway-container/src/main/resources/org/onebusaway/container/application-context-caching.xml @@ -23,7 +23,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> diff --git a/onebusaway-container/src/main/resources/org/onebusaway/container/application-context-common.xml b/onebusaway-container/src/main/resources/org/onebusaway/container/application-context-common.xml index 0f4cd349a2..3cca7af10b 100644 --- a/onebusaway-container/src/main/resources/org/onebusaway/container/application-context-common.xml +++ b/onebusaway-container/src/main/resources/org/onebusaway/container/application-context-common.xml @@ -23,7 +23,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> diff --git a/onebusaway-container/src/main/resources/org/onebusaway/container/application-context-hibernate.xml b/onebusaway-container/src/main/resources/org/onebusaway/container/application-context-hibernate.xml index b5c93502f2..c8e415198f 100644 --- a/onebusaway-container/src/main/resources/org/onebusaway/container/application-context-hibernate.xml +++ b/onebusaway-container/src/main/resources/org/onebusaway/container/application-context-hibernate.xml @@ -23,7 +23,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> @@ -87,7 +87,7 @@ - @@ -97,7 +97,7 @@ - + diff --git a/onebusaway-container/src/main/resources/org/onebusaway/container/application-context.xml b/onebusaway-container/src/main/resources/org/onebusaway/container/application-context.xml index 573335351d..902c799638 100644 --- a/onebusaway-container/src/main/resources/org/onebusaway/container/application-context.xml +++ b/onebusaway-container/src/main/resources/org/onebusaway/container/application-context.xml @@ -23,7 +23,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> diff --git a/onebusaway-core/pom.xml b/onebusaway-core/pom.xml index 782c5a6df1..3512df9a31 100644 --- a/onebusaway-core/pom.xml +++ b/onebusaway-core/pom.xml @@ -3,7 +3,7 @@ org.onebusaway onebusaway-application-modules - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-core jar diff --git a/onebusaway-enterprise-acta-webapp/pom.xml b/onebusaway-enterprise-acta-webapp/pom.xml index 4af4cdd916..3b6b93e402 100644 --- a/onebusaway-enterprise-acta-webapp/pom.xml +++ b/onebusaway-enterprise-acta-webapp/pom.xml @@ -4,7 +4,7 @@ onebusaway-application-modules org.onebusaway - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-enterprise-acta-webapp war @@ -89,10 +89,10 @@ local-multi-port - http://localhost:8081/onebusaway-nyc-vehicle-tracking-webapp - http://localhost:8081/onebusaway-nyc-vehicle-tracking-webapp - http://localhost:8081/onebusaway-nyc-vehicle-tracking-webapp - http://localhost:8081/onebusaway-nyc-report-archive + http://localhost:8080/onebusaway-nyc-vehicle-tracking-webapp + http://localhost:8080/onebusaway-nyc-vehicle-tracking-webapp + http://localhost:8080/onebusaway-nyc-vehicle-tracking-webapp + http://localhost:8080/onebusaway-nyc-report-archive stdout true diff --git a/onebusaway-enterprise-acta-webapp/src/main/resources/branded-sources.xml b/onebusaway-enterprise-acta-webapp/src/main/resources/branded-sources.xml index 58f5456545..70269f85f2 100644 --- a/onebusaway-enterprise-acta-webapp/src/main/resources/branded-sources.xml +++ b/onebusaway-enterprise-acta-webapp/src/main/resources/branded-sources.xml @@ -29,7 +29,7 @@ - ${git.commit.id:} + ${git.commit.id} diff --git a/onebusaway-enterprise-acta-webapp/src/main/resources/log4j.xml b/onebusaway-enterprise-acta-webapp/src/main/resources/log4j.xml index 7d6c155398..84f8518f84 100644 --- a/onebusaway-enterprise-acta-webapp/src/main/resources/log4j.xml +++ b/onebusaway-enterprise-acta-webapp/src/main/resources/log4j.xml @@ -26,7 +26,7 @@ - + diff --git a/onebusaway-enterprise-acta-webapp/src/main/resources/onebusaway-enterprise.properties b/onebusaway-enterprise-acta-webapp/src/main/resources/onebusaway-enterprise.properties index ba29728d6f..6b1a22cd1e 100644 --- a/onebusaway-enterprise-acta-webapp/src/main/resources/onebusaway-enterprise.properties +++ b/onebusaway-enterprise-acta-webapp/src/main/resources/onebusaway-enterprise.properties @@ -79,7 +79,7 @@ favicon.url=/favicon.ico ######## Route list properties ################ routes.title=Routes - +######## Legacy Timetable support ################ # # Copyright (C) 2011 Brian Ferris # diff --git a/onebusaway-enterprise-webapp/pom.xml b/onebusaway-enterprise-webapp/pom.xml index b3711a6d88..98c91a86d8 100644 --- a/onebusaway-enterprise-webapp/pom.xml +++ b/onebusaway-enterprise-webapp/pom.xml @@ -5,7 +5,7 @@ org.onebusaway onebusaway-application-modules - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-enterprise-webapp war @@ -157,7 +157,6 @@ mysql mysql-connector-java - 5.1.17 @@ -225,10 +224,10 @@ local-multi-port - http://localhost:8081/onebusaway-nyc-vehicle-tracking-webapp - http://localhost:8081/onebusaway-nyc-vehicle-tracking-webapp - http://localhost:8081/onebusaway-nyc-vehicle-tracking-webapp - http://localhost:8081/onebusaway-nyc-report-archive + http://localhost:8080/onebusaway-nyc-vehicle-tracking-webapp + http://localhost:8080/onebusaway-nyc-vehicle-tracking-webapp + http://localhost:8080/onebusaway-nyc-vehicle-tracking-webapp + http://localhost:8080/onebusaway-nyc-report-archive stdout true false diff --git a/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/api/ReleaseAction.java b/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/api/ReleaseAction.java index 56538a53e5..9b07db36eb 100644 --- a/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/api/ReleaseAction.java +++ b/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/api/ReleaseAction.java @@ -18,7 +18,7 @@ import java.io.IOException; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.onebusaway.util.git.GitRepositoryHelper; import org.onebusaway.util.git.GitRepositoryState; diff --git a/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/api/StopForIdAction.java b/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/api/StopForIdAction.java index 742e4dd37b..ff989d6bae 100644 --- a/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/api/StopForIdAction.java +++ b/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/api/StopForIdAction.java @@ -21,7 +21,7 @@ import java.util.GregorianCalendar; import java.util.List; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.onebusaway.gtfs.model.AgencyAndId; import org.onebusaway.gtfs.model.calendar.ServiceDate; import org.onebusaway.presentation.impl.service_alerts.ServiceAlertsHelper; diff --git a/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/status/model/IcingaItem.java b/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/status/model/IcingaItem.java index 24e22252c0..ecb49a7404 100644 --- a/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/status/model/IcingaItem.java +++ b/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/status/model/IcingaItem.java @@ -15,7 +15,7 @@ */ package org.onebusaway.enterprise.webapp.actions.status.model; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.annotations.AccessType; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; diff --git a/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/status/service/StatusProviderImpl.java b/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/status/service/StatusProviderImpl.java index db892dfd83..77e0a468f8 100644 --- a/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/status/service/StatusProviderImpl.java +++ b/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/actions/status/service/StatusProviderImpl.java @@ -17,8 +17,6 @@ import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -27,11 +25,10 @@ import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.lang.StringUtils; -import org.codehaus.jackson.JsonNode; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.onebusaway.agency_metadata.model.AgencyMetadata; import org.onebusaway.enterprise.webapp.actions.status.model.IcingaItem; -import org.onebusaway.enterprise.webapp.actions.status.model.IcingaResponse; import org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup; import org.onebusaway.enterprise.webapp.actions.status.model.StatusItem; import org.onebusaway.transit_data.model.AgencyWithCoverageBean; @@ -164,7 +161,7 @@ public StatusGroup getAgencyMetadataStatus() { ObjectMapper mapper = new ObjectMapper(); JsonNode tree = mapper.readTree(result); JsonNode value = tree.findValue("data"); - response = mapper.readValue(value, AgencyMetadata[].class); + response = mapper.readValue(value.asText(), AgencyMetadata[].class); } catch (IOException e) { _log.error("Exception getting AgencyMetadata" + e); group.addItem(exceptionStatus(e)); diff --git a/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/api/ApiKeyInterceptor.java b/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/api/ApiKeyInterceptor.java index 8bf98b077e..4dcc7b6553 100644 --- a/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/api/ApiKeyInterceptor.java +++ b/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/api/ApiKeyInterceptor.java @@ -16,7 +16,6 @@ package org.onebusaway.enterprise.webapp.api; import java.util.Date; -import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -96,8 +95,10 @@ private void determineResponseType() { // package private for unit tests int isAllowed(ActionInvocation invocation) { ActionContext context = invocation.getInvocationContext(); - Map parameters = context.getParameters(); - String[] keys = (String[]) parameters.get("key"); + String[] keys = null; + if (context.getParameters().containsKey("key")) { + keys = (String[]) context.getParameters().get("key").getMultipleValues(); + } if (keys == null || keys.length == 0) { // 401: we couldn't find the api key diff --git a/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/api/LoadApiKeysOnInitAction.java b/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/api/LoadApiKeysOnInitAction.java new file mode 100644 index 0000000000..83e0090aea --- /dev/null +++ b/onebusaway-enterprise-webapp/src/main/java/org/onebusaway/enterprise/webapp/api/LoadApiKeysOnInitAction.java @@ -0,0 +1,253 @@ +/** + * Copyright (C) 2021 Cambridge Systematics, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onebusaway.enterprise.webapp.api; + +import org.onebusaway.users.services.UserPropertiesService; +import org.onebusaway.users.services.UserService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.annotation.PostConstruct; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Load API keys from csv file created from WriteUserPropertiesToDisk + */ +public class LoadApiKeysOnInitAction { + + public static int KEY = 0; + public static int NAME = 1; + public static int COMPANY = 2; + public static int EMAIL = 3; + public static int DETAILS = 4; + public static int LIMIT = 5; + + private static Logger _log = LoggerFactory.getLogger(LoadApiKeysOnInitAction.class); + private String filename = System.getProperty("java.io.tmpdir") + File.separator + "user_properties.csv"; + + private UserService _userService; + + private UserPropertiesService _userPropertiesService; + + public void setFilename(String filename) { + this.filename = filename; + } + + @Autowired + public void setUserService(UserService userService) { + _userService = userService; + } + + @Autowired + public void setUserPropertiesService( + UserPropertiesService userPropertiesService) { + _userPropertiesService = userPropertiesService; + } + + private BufferedReader csvReader; + + @PostConstruct + public void execute() { + _log.info("LoadApiKeysOnInitAction start"); + String line = null; + try { + _log.info("reading users from " + filename); + open(); + line = readLine(); // discard header + int count = 0; + while (line != null) { + line = readLine(); + List records = parseLine(line); + if (records != null) { + for (Record record : records) { + createUser(record); + } + } + if (count % 100 == 0) { + _log.info("wrote " + count + " users"); + } + count++; + } + } catch (Exception any) { + _log.error("load users failed on line + |" + line + "| with " + any, any); + } finally { + _log.info("LoadApiKeysOnInitAction complete"); + try { + close(); + } catch (Exception any) { + // bury + } + } + } + + + private void createUser(Record record) { + CreateAPIKeyOnInitAction action = new CreateAPIKeyOnInitAction(); + action.setUserService(_userService); + action.setUserPropertiesService(_userPropertiesService); + copyToAction(action, record); + } + + private void copyToAction(CreateAPIKeyOnInitAction action, Record record) { + action.setKey(record.getKey()); + action.setContactName(record.getContactName()); + action.setContactCompany(record.getContactCompany()); + action.setContactEmail(record.getContactEmail()); + action.setContactDetails(record.getContactDetails()); + action.setLimit(record.getLimit()); + action.setCreateAPIKey(true); + try { + action.execute(); + } catch (Exception any) { + _log.error("record " + record.getKey() + " insertion failed: " + any.toString()); + } + } + + + private void open() throws IOException { + csvReader = new BufferedReader(new FileReader(filename)); + } + + private void close() throws IOException { + if (csvReader != null) { + csvReader.close(); + } + } + + private String readLine() throws IOException { + return csvReader.readLine(); + } + + private List parseLine(String line) { + List records = new ArrayList<>(); + List keys = parseKeys(line); + for (String key : keys) { + Record user = new Record(); + user.setKey(key); + user.setContactName(getSafeColumn(line, NAME)); + user.setContactCompany(getSafeColumn(line, COMPANY)); + user.setContactEmail(getSafeColumn(line, EMAIL)); + user.setContactDetails(getSafeColumn(line, DETAILS)); + user.setLimit(getSafeColumn(line, LIMIT)); + records.add(user); + } + return records; + } + + private List parseKeys(String line) { + return getColumn(line, KEY, true); + } + + String getSafeColumn(String line, int columnIndex) { + List columns = getColumn(line, columnIndex, false); + if (columns.isEmpty()) return null; + return columns.get(0); + } + + List getColumn(String line, int requestedColumn, boolean splitOnComma) { + List elements = new ArrayList<>(); + if (line == null) + return elements; + + int currentColumn = 0; + int start = 0; + int end = 0; + while (currentColumn <= requestedColumn) { + + if (start >= line.length()) return elements; + if (line.charAt(start) == '"') { + start++; + end = line.indexOf('"', start); + } else { + end = line.indexOf(',', start); + } + if (end < 0 || end > line.length()) { + end = line.length(); + } + + if (currentColumn == requestedColumn) { + String columnStr = line.substring(start, end); + if (splitOnComma) { + for (String s : columnStr.split(",")) { + if (s != null && s.trim() != null && s.trim().length() > 0) { + elements.add(s.trim()); + } + } + } else { + if (columnStr != null && columnStr.trim() != null && columnStr.trim().length() > 0) { + elements.add(columnStr.trim()); + } + } + } + + if (start -1 >= 0 && line.charAt(start-1) == '"') { + start = end + 2; // consume comma as well + } else { + start = end + 1; + } + currentColumn++; + } + return elements; + + } + + private static class Record { + private String key; + private String contactName; + private String contactCompany; + private String contactEmail; + private String contactDetails; + private String limit; + public String getKey() { + return key; + } + public void setKey(String key) { + this.key = key; + } + public String getContactName() { + return contactName; + } + public void setContactName(String contactName) { + this.contactName = contactName; + } + public String getContactCompany() { + return contactCompany; + } + public void setContactCompany(String contactCompany) { + this.contactCompany = contactCompany; + } + public String getContactEmail() { + return contactEmail; + } + public void setContactEmail(String contactEmail) { + this.contactEmail = contactEmail; + } + public String getContactDetails() { + return contactDetails; + } + public void setContactDetails(String contactDetails) { + this.contactDetails = contactDetails; + } + public String getLimit() { return limit; } + public void setLimit(String limit) { this.limit = limit; } + } +} diff --git a/onebusaway-enterprise-webapp/src/main/resources/data-sources.xml b/onebusaway-enterprise-webapp/src/main/resources/data-sources.xml index e1891fad13..4e4507291a 100644 --- a/onebusaway-enterprise-webapp/src/main/resources/data-sources.xml +++ b/onebusaway-enterprise-webapp/src/main/resources/data-sources.xml @@ -64,16 +64,6 @@ class="org.onebusaway.geocoder.enterprise.impl.EnterpriseGoogleGeocoderImpl" depends-on="serviceAreaServiceImpl"> - - - - - ${git.commit.id} - - - - diff --git a/onebusaway-enterprise-webapp/src/main/resources/org/onebusaway/enterprise/webapp/application-context-webapp.xml b/onebusaway-enterprise-webapp/src/main/resources/org/onebusaway/enterprise/webapp/application-context-webapp.xml index 6910725975..5ef2e16ffe 100644 --- a/onebusaway-enterprise-webapp/src/main/resources/org/onebusaway/enterprise/webapp/application-context-webapp.xml +++ b/onebusaway-enterprise-webapp/src/main/resources/org/onebusaway/enterprise/webapp/application-context-webapp.xml @@ -21,7 +21,7 @@ xmlns:sec="http://www.springframework.org/schema/security" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> @@ -62,7 +62,11 @@ - + diff --git a/onebusaway-enterprise-webapp/src/main/resources/struts.xml b/onebusaway-enterprise-webapp/src/main/resources/struts.xml index a3c50ae228..af7a709cc1 100644 --- a/onebusaway-enterprise-webapp/src/main/resources/struts.xml +++ b/onebusaway-enterprise-webapp/src/main/resources/struts.xml @@ -19,7 +19,7 @@ --> + "http://struts.apache.org/dtds/struts-2.5.dtd"> @@ -30,8 +30,9 @@ + - + @@ -112,16 +113,17 @@ - - - - - - - - - - + + + + + + + + + + + diff --git a/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/m/includes/route-list.jspx b/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/m/includes/route-list.jspx index 5aadb47a28..964465afeb 100644 --- a/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/m/includes/route-list.jspx +++ b/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/m/includes/route-list.jspx @@ -22,9 +22,9 @@ xmlns:s="/struts-tags" xmlns:wiki="/oba-wiki-tags" id="content"> - - - + + +

Routes:

diff --git a/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/m/wiki/index.jspx b/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/m/wiki/index.jspx index 7e9d7a3fe5..176ca1effc 100644 --- a/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/m/wiki/index.jspx +++ b/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/m/wiki/index.jspx @@ -22,7 +22,7 @@

- +

diff --git a/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/iphone/stop-redirect.jspx b/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/iphone/stop-redirect.jspx index a30f152da7..c8469848d8 100644 --- a/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/iphone/stop-redirect.jspx +++ b/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/iphone/stop-redirect.jspx @@ -24,7 +24,7 @@ Refresh - 10;url= + 10;url= diff --git a/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/iphone/stop.jspx b/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/iphone/stop.jspx index ab0b4f016e..c2b6ee3e35 100644 --- a/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/iphone/stop.jspx +++ b/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/iphone/stop.jspx @@ -21,7 +21,7 @@ xmlns:s="/struts-tags" xmlns:oba="/oba-tags"> - + @@ -56,8 +56,8 @@ minutes - - + + arrivalsRouteEntry arrivalsRouteLongNameEntry diff --git a/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/schedule.jspx b/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/schedule.jspx index 3c06ea8b7b..c9e7fd2daf 100644 --- a/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/schedule.jspx +++ b/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/schedule.jspx @@ -19,7 +19,7 @@ - + @@ -262,7 +262,7 @@ stopScheduleMinutes - + diff --git a/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/trip.jspx b/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/trip.jspx index 2718bd53e5..ef1a1cac14 100644 --- a/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/trip.jspx +++ b/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/content/where/trip.jspx @@ -23,8 +23,8 @@ Route <s:property value="result.trip.route.shortName" /> - <s:property value="result.trip.tripHeadsign" /> - Trip # <s:property value="result.trip.id" /> - - + + diff --git a/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/web.xml b/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/web.xml index 22e3937226..b196bdd87c 100644 --- a/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/web.xml +++ b/onebusaway-enterprise-webapp/src/main/webapp/WEB-INF/web.xml @@ -59,7 +59,7 @@ action2-cleanup - org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter + org.apache.struts2.dispatcher.filter.StrutsPrepareFilter sitemesh @@ -67,7 +67,7 @@ action2 - org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter + org.apache.struts2.dispatcher.filter.StrutsExecuteFilter CorsFilter @@ -84,6 +84,19 @@ httpHeaderSecurity org.apache.catalina.filters.HttpHeaderSecurityFilter + true + + hstsEnabled + true + + + hstsMaxAgeSeconds + 31536000 + + + hstsIncludeSubDomains + true + antiClickJackingOption SAMEORIGIN diff --git a/onebusaway-enterprise-webapp/src/main/webapp/js/oba/sign/Sign.js b/onebusaway-enterprise-webapp/src/main/webapp/js/oba/sign/Sign.js index 2ca50e13ae..d7a7655ec9 100644 --- a/onebusaway-enterprise-webapp/src/main/webapp/js/oba/sign/Sign.js +++ b/onebusaway-enterprise-webapp/src/main/webapp/js/oba/sign/Sign.js @@ -224,8 +224,7 @@ OBA.Sign = function() { function initStop(stopId, initMonitor) { var stopIdStr = stopId.agency + "_" + stopId.id; - var params = { stopId: stopIdStr }; - + var params = { stopId: stopIdStr, "type": "json", "key": "OBAKEY" }; jQuery.getJSON(baseUrl + "/" + OBA.Config.stopForId, params, function(json) { stopInfo[stopIdStr] = json.stop; jQuery.each(json.stop.routesAvailable, function(_, route) { @@ -612,12 +611,15 @@ OBA.Sign = function() { headsignToDistanceAways[routeIdAndHeadsign] = []; r++; } - - jQuery.each(journey.SituationRef, function(_, situationRef) { - if(typeof situationsById[situationRef.SituationSimpleRef] !== 'undefined') { - applicableSituations[situationRef.SituationSimpleRef] = situationsById[situationRef.SituationSimpleRef]; - } - }); + if (typeof journey.SituationRef === 'undefined') { + console.log("issue with journey"); + } else { + jQuery.each(journey.SituationRef, function (_, situationRef) { + if (typeof situationsById[situationRef.SituationSimpleRef] !== 'undefined') { + applicableSituations[situationRef.SituationSimpleRef] = situationsById[situationRef.SituationSimpleRef]; + } + }); + } var vehicleInfo = {}; vehicleInfo.distanceAway = journey.MonitoredCall.Extensions.Distances.PresentableDistance; diff --git a/onebusaway-enterprise-webapp/src/main/webapp/template/xhtml/arrival-and-departure-table-row-snippet.jspx b/onebusaway-enterprise-webapp/src/main/webapp/template/xhtml/arrival-and-departure-table-row-snippet.jspx index c4ff89151c..a25a7429a4 100644 --- a/onebusaway-enterprise-webapp/src/main/webapp/template/xhtml/arrival-and-departure-table-row-snippet.jspx +++ b/onebusaway-enterprise-webapp/src/main/webapp/template/xhtml/arrival-and-departure-table-row-snippet.jspx @@ -30,8 +30,8 @@ - - + diff --git a/onebusaway-enterprise-webapp/src/main/webapp/template/xhtml/stops-title-head-snippet.jspx b/onebusaway-enterprise-webapp/src/main/webapp/template/xhtml/stops-title-head-snippet.jspx index 0ad7ab2daa..5a395eece1 100644 --- a/onebusaway-enterprise-webapp/src/main/webapp/template/xhtml/stops-title-head-snippet.jspx +++ b/onebusaway-enterprise-webapp/src/main/webapp/template/xhtml/stops-title-head-snippet.jspx @@ -31,7 +31,7 @@ - bound - Stop # - + \ No newline at end of file diff --git a/onebusaway-enterprise-webapp/src/main/webapp/template/xhtml/stops-title-snippet.jspx b/onebusaway-enterprise-webapp/src/main/webapp/template/xhtml/stops-title-snippet.jspx index e376bc7319..4dc13da67d 100644 --- a/onebusaway-enterprise-webapp/src/main/webapp/template/xhtml/stops-title-snippet.jspx +++ b/onebusaway-enterprise-webapp/src/main/webapp/template/xhtml/stops-title-snippet.jspx @@ -33,7 +33,7 @@ - + index.action#p(index)m(location)lat()lon()accuracy(8)stop()

diff --git a/onebusaway-enterprise-webapp/src/test/java/org/onebusaway/enterprise/webapp/api/ApiKeyInterceptorTest.java b/onebusaway-enterprise-webapp/src/test/java/org/onebusaway/enterprise/webapp/api/ApiKeyInterceptorTest.java index ad6f9ce107..24f4caaad7 100644 --- a/onebusaway-enterprise-webapp/src/test/java/org/onebusaway/enterprise/webapp/api/ApiKeyInterceptorTest.java +++ b/onebusaway-enterprise-webapp/src/test/java/org/onebusaway/enterprise/webapp/api/ApiKeyInterceptorTest.java @@ -23,6 +23,8 @@ import java.util.HashMap; import java.util.Map; +import org.apache.struts2.dispatcher.HttpParameters; +import org.apache.struts2.dispatcher.Parameter; import org.junit.Before; import org.junit.Test; import org.onebusaway.users.services.ApiKeyPermissionService; @@ -43,6 +45,7 @@ public class ApiKeyInterceptorTest { private ActionContext _ac; private ActionInvocation _ai; private ApiKeyPermissionService _ks; + private HttpParameters _httpParams; private Map _params = new HashMap(); @Before @@ -52,20 +55,27 @@ public void setUp() throws Exception { _ai = mock(ActionInvocation.class); _ks = mock(ApiKeyPermissionService.class); _aki.setKeyService(_ks); - + _httpParams = mock(HttpParameters.class); + Parameter key = mock(Parameter.class); + _params = new HashMap(); String[] keys = {"akey"}; _params.put("key", keys); + when(_ai.getInvocationContext()).thenReturn(_ac); - when(_ac.getParameters()).thenReturn(_params); + when(_ac.getParameters()).thenReturn(_httpParams); + when(_httpParams.get("key")).thenReturn(key); + when(_httpParams.containsKey("key")).thenReturn(true); + when(key.getMultipleValues()).thenReturn((String[]) _params.get("key")); } @Test public void testIsAllowedNoUser() { // try it with now valid API key assertNotNull(_params.remove("key")); + when(_httpParams.containsKey("key")).thenReturn(false); // here we return 401 as the authentication failed/key not found assertEquals(401, _aki.isAllowed(_ai)); } @@ -73,6 +83,11 @@ public void testIsAllowedNoUser() { @Test public void testIsAllowedValidUser() { when(_ks.getPermission((String)anyObject(), (String)anyObject())).thenReturn(Status.AUTHORIZED); + assertNotNull(_params.get("key")); + assertNotNull(_httpParams.get("key")); + assertNotNull(_httpParams.get("key").getMultipleValues()); + assertNotNull(_ac.getParameters()); + assertTrue(_ac.getParameters().containsKey("key")); assertEquals(200, _aki.isAllowed(_ai)); } diff --git a/onebusaway-enterprise-webapp/src/test/java/org/onebusaway/enterprise/webapp/api/LoadApiKeysOnInitActionTest.java b/onebusaway-enterprise-webapp/src/test/java/org/onebusaway/enterprise/webapp/api/LoadApiKeysOnInitActionTest.java new file mode 100644 index 0000000000..23dbb58f89 --- /dev/null +++ b/onebusaway-enterprise-webapp/src/test/java/org/onebusaway/enterprise/webapp/api/LoadApiKeysOnInitActionTest.java @@ -0,0 +1,74 @@ +/** + * Copyright (C) 2021 Cambridge Systematics, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onebusaway.enterprise.webapp.api; + +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.*; +import static org.onebusaway.enterprise.webapp.api.LoadApiKeysOnInitAction.*; + +/** + * test various combinations of API key data entry. + */ +public class LoadApiKeysOnInitActionTest { + + String R1 = "aaaaaaaa-1111-1111-1111-aaaaaaaaaaaa,,,,,0"; + String R2 = "\"aaaaaaaa-1111-1111-1111-aaaaaaaaaaa1, aaaaaaaa-1111-1111-1111-aaaaaaaaaaa2\",,,,,0"; + String R3 = ",,,,,"; + String R4 = ", ,,,,"; + String R5 = "aaaaaaaa-1111-1111-1111-aaaaaaaaaaaa,First Last,Com Pany,user@example.com,key for Trip Planner Maps,0"; + String R6 = "aaaaaaaa-1111-1111-1111-aaaaaaaaaaaa,First Last,\"Three Word Company, LLC\",user@example.com,,0"; + String R7 = "\"aaaaaaaa-1111-1111-1111-aaaaaaaaaaa1, aaaaaaaa-1111-1111-1111-aaaaaaaaaaa2\",First Last,,user@example.com,,0"; + String R8 = "795d483d-514e-4eac-8acc-0cb86754363f,Drew Dara-Abrams,Interline Technologies,drew@interline.io,\"Interline's Transitland platform\",100"; + @Test + public void testGetColumn() { + LoadApiKeysOnInitAction action = new LoadApiKeysOnInitAction(); + List values = action.getColumn(R1, 0, true); + assertNotNull(values); + assertEquals(1, values.size()); + assertEquals("aaaaaaaa-1111-1111-1111-aaaaaaaaaaaa", values.get(0)); + + values = action.getColumn(R2, 0, true); + assertNotNull(values); + assertEquals(2, values.size()); + assertEquals("aaaaaaaa-1111-1111-1111-aaaaaaaaaaa1", values.get(0)); + assertEquals("aaaaaaaa-1111-1111-1111-aaaaaaaaaaa2", values.get(1)); + + values = action.getColumn(R3, 0, true); + assertNotNull(values); + assertEquals(0, values.size()); + + values = action.getColumn(R4, 0, true); + assertNotNull(values); + assertEquals(0, values.size()); + + compareApiKey(action, R5, "aaaaaaaa-1111-1111-1111-aaaaaaaaaaaa", "First Last", "Com Pany", "user@example.com", "key for Trip Planner Maps", "0"); + compareApiKey(action, R6, "aaaaaaaa-1111-1111-1111-aaaaaaaaaaaa", "First Last", "Three Word Company, LLC", "user@example.com", null, "0"); + compareApiKey(action, R7, "aaaaaaaa-1111-1111-1111-aaaaaaaaaaa1", "First Last", null, "user@example.com", null, "0"); + compareApiKey(action, R8, "795d483d-514e-4eac-8acc-0cb86754363f", "Drew Dara-Abrams", "Interline Technologies", "drew@interline.io", "Interline's Transitland platform", "100"); + } + + private void compareApiKey(LoadApiKeysOnInitAction action, String line, String key, String name, String company, String email, String details, String limit) { +// assertEquals(key, action.getColumn(line, KEY, true).get(0)); +// assertEquals(name, action.getSafeColumn(line, NAME)); +// assertEquals(company, action.getSafeColumn(line, COMPANY)); +// assertEquals(email, action.getSafeColumn(line, EMAIL)); +// assertEquals(details, action.getSafeColumn(line, DETAILS)); + assertEquals(limit, action.getSafeColumn(line, LIMIT)); + } +} \ No newline at end of file diff --git a/onebusaway-federations-webapp/pom.xml b/onebusaway-federations-webapp/pom.xml index 960077fd9d..ba8e162817 100644 --- a/onebusaway-federations-webapp/pom.xml +++ b/onebusaway-federations-webapp/pom.xml @@ -3,7 +3,7 @@ onebusaway-application-modules org.onebusaway - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-federations-webapp war @@ -73,6 +73,7 @@ org.apache.maven.plugins maven-surefire-plugin + 3.0.0-M3 integration-tests diff --git a/onebusaway-federations-webapp/src/main/webapp/WEB-INF/remoting-servlet.xml b/onebusaway-federations-webapp/src/main/webapp/WEB-INF/remoting-servlet.xml index 759d7880cb..ed21e44d62 100644 --- a/onebusaway-federations-webapp/src/main/webapp/WEB-INF/remoting-servlet.xml +++ b/onebusaway-federations-webapp/src/main/webapp/WEB-INF/remoting-servlet.xml @@ -19,19 +19,33 @@ + xmlns:mvc="http://www.springframework.org/schema/mvc" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd + http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd + http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> - - - - + + + + + + + + + + + + + + + + diff --git a/onebusaway-federations/pom.xml b/onebusaway-federations/pom.xml index cd20fca8e4..5064bb6c13 100644 --- a/onebusaway-federations/pom.xml +++ b/onebusaway-federations/pom.xml @@ -3,7 +3,7 @@ org.onebusaway onebusaway-application-modules - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-federations jar diff --git a/onebusaway-federations/src/main/java/org/onebusaway/federations/impl/FederatedServiceCollectionImpl.java b/onebusaway-federations/src/main/java/org/onebusaway/federations/impl/FederatedServiceCollectionImpl.java index 1b4df4b9c4..cd6ed45061 100644 --- a/onebusaway-federations/src/main/java/org/onebusaway/federations/impl/FederatedServiceCollectionImpl.java +++ b/onebusaway-federations/src/main/java/org/onebusaway/federations/impl/FederatedServiceCollectionImpl.java @@ -22,6 +22,9 @@ import java.util.Map; import java.util.Set; +import org.locationtech.jts.geom.Envelope; +import org.locationtech.jts.index.ItemVisitor; +import org.locationtech.jts.index.strtree.STRtree; import org.onebusaway.exceptions.MultipleServiceAreasServiceException; import org.onebusaway.exceptions.NoSuchAgencyServiceException; import org.onebusaway.exceptions.OutOfServiceAreaServiceException; @@ -31,9 +34,6 @@ import org.onebusaway.geospatial.model.CoordinateBounds; import org.onebusaway.geospatial.model.CoordinatePoint; -import com.vividsolutions.jts.geom.Envelope; -import com.vividsolutions.jts.index.ItemVisitor; -import com.vividsolutions.jts.index.strtree.STRtree; /** * A basic {@link FederatedServiceCollection} implementation that provides diff --git a/onebusaway-federations/src/test/java/org/onebusaway/federations/impl/DynamicFederatedServiceCollectionImplTest.java b/onebusaway-federations/src/test/java/org/onebusaway/federations/impl/DynamicFederatedServiceCollectionImplTest.java index caa073a2b0..eced29941a 100644 --- a/onebusaway-federations/src/test/java/org/onebusaway/federations/impl/DynamicFederatedServiceCollectionImplTest.java +++ b/onebusaway-federations/src/test/java/org/onebusaway/federations/impl/DynamicFederatedServiceCollectionImplTest.java @@ -40,7 +40,7 @@ public class DynamicFederatedServiceCollectionImplTest { private static final int TIMEOUT = 10000; - private static final int PORT = 9999; + private static final int PORT = 9991; private FederatedServiceRegistryImpl _registry; diff --git a/onebusaway-frontend-webapp/pom.xml b/onebusaway-frontend-webapp/pom.xml index 0052273f45..cc746a23d1 100644 --- a/onebusaway-frontend-webapp/pom.xml +++ b/onebusaway-frontend-webapp/pom.xml @@ -3,7 +3,7 @@ onebusaway-application-modules org.onebusaway - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT 4.0.0 diff --git a/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/content/api/stop-for-id.jspx b/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/content/api/stop-for-id.jspx index 3a7a608ff6..2c2cc01879 100644 --- a/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/content/api/stop-for-id.jspx +++ b/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/content/api/stop-for-id.jspx @@ -18,5 +18,5 @@ -{"siri": ,"stop": } +{"siri": ,"stop": } \ No newline at end of file diff --git a/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/content/routes/index.jspx b/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/content/routes/index.jspx index d31d6be54e..cc18c5de83 100644 --- a/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/content/routes/index.jspx +++ b/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/content/routes/index.jspx @@ -20,8 +20,8 @@ xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:s="/struts-tags" xmlns:wiki="/oba-wiki-tags"> - - + + diff --git a/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/content/wiki/index.jspx b/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/content/wiki/index.jspx index b0d2fc678a..9a99a4d4a3 100644 --- a/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/content/wiki/index.jspx +++ b/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/content/wiki/index.jspx @@ -39,13 +39,13 @@ Table of Contents

- +
- +

@@ -58,7 +58,7 @@

- +

diff --git a/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/web.xml b/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/web.xml index c01b63d3a9..13947ec826 100644 --- a/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/web.xml +++ b/onebusaway-frontend-webapp/src/main/webapp/WEB-INF/web.xml @@ -69,7 +69,7 @@ action2-cleanup - org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter + org.apache.struts2.dispatcher.filter.StrutsPrepareFilter sitemesh @@ -77,7 +77,7 @@ action2 - org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter + org.apache.struts2.dispatcher.filter.StrutsExecuteFilter CorsFilter diff --git a/onebusaway-frontend-webapp/src/main/webapp/js/oba/map/Popups.js b/onebusaway-frontend-webapp/src/main/webapp/js/oba/map/Popups.js index 85f299025c..780c251d4d 100644 --- a/onebusaway-frontend-webapp/src/main/webapp/js/oba/map/Popups.js +++ b/onebusaway-frontend-webapp/src/main/webapp/js/oba/map/Popups.js @@ -474,7 +474,13 @@ OBA.Popups = (function() { // update time across all arrivals var updateTimestampReference = OBA.Util.ISO8601StringToDate(siri.Siri.ServiceDelivery.ResponseTimestamp).getTime(); var maxUpdateTimestamp = null; - jQuery.each(siri.Siri.ServiceDelivery.StopMonitoringDelivery[0].MonitoredStopVisit, function(_, monitoredJourney) { + + var monitoredStopVisit = []; + if(siri.Siri.ServiceDelivery.StopMonitoringDelivery[0].MonitoredStopVisit){ + monitoredStopVisit = siri.Siri.ServiceDelivery.StopMonitoringDelivery[0].MonitoredStopVisit; + } + + jQuery.each(monitoredStopVisit, function(_, monitoredJourney) { var updateTimestamp = OBA.Util.ISO8601StringToDate(monitoredJourney.RecordedAtTime).getTime(); if(updateTimestamp > maxUpdateTimestamp) { maxUpdateTimestamp = updateTimestamp; @@ -591,7 +597,10 @@ OBA.Popups = (function() { }); // ...now those with and without arrivals - var visits = siri.Siri.ServiceDelivery.StopMonitoringDelivery[0].MonitoredStopVisit; + var visits = []; + if(siri.Siri.ServiceDelivery.StopMonitoringDelivery[0].MonitoredStopVisit){ + var visits = siri.Siri.ServiceDelivery.StopMonitoringDelivery[0].MonitoredStopVisit; + } jQuery.each(visits, function(_, monitoredJourney) { var routeId = monitoredJourney.MonitoredVehicleJourney.LineRef; var routeShortName = monitoredJourney.MonitoredVehicleJourney.PublishedLineName; diff --git a/onebusaway-frontend-webapp/src/main/webapp/js/oba/map/RouteMap.js b/onebusaway-frontend-webapp/src/main/webapp/js/oba/map/RouteMap.js index 3a1b4ecee5..798ff0523f 100644 --- a/onebusaway-frontend-webapp/src/main/webapp/js/oba/map/RouteMap.js +++ b/onebusaway-frontend-webapp/src/main/webapp/js/oba/map/RouteMap.js @@ -236,7 +236,9 @@ OBA.RouteMap = function(mapNode, initCallbackFn, serviceAlertCallbackFn) { function(json) { // service alerts if(typeof serviceAlertCallbackFn === 'function') { - if(typeof json.Siri.ServiceDelivery.SituationExchangeDelivery !== 'undefined' && json.Siri.ServiceDelivery.SituationExchangeDelivery.length > 0) { + if(typeof json.Siri !== 'undefined' + && typeof json.Siri.ServiceDelivery.SituationExchangeDelivery !== 'undefined' + && json.Siri.ServiceDelivery.SituationExchangeDelivery.length > 0) { serviceAlertCallbackFn(routeId, json.Siri.ServiceDelivery.SituationExchangeDelivery[0].Situations.PtSituationElement); } diff --git a/onebusaway-geocoder/pom.xml b/onebusaway-geocoder/pom.xml index 6ff6467216..fdf31dce7c 100644 --- a/onebusaway-geocoder/pom.xml +++ b/onebusaway-geocoder/pom.xml @@ -3,16 +3,24 @@ onebusaway-application-modules org.onebusaway - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-geocoder onebusaway-geocoder - 11-beta + 20.5 + + + osgeo + Open Source Geospatial Foundation Repository + https://repo.osgeo.org/repository/release/ + + + org.onebusaway @@ -67,6 +75,12 @@ org.geotools gt-main ${geotools.version} + + + com.fasterxml.jackson.core + jackson-core + + commons-codec @@ -74,6 +88,17 @@ 1.4 provided + + + jakarta.xml.bind + jakarta.xml.bind-api + 2.3.3 + + + org.glassfish.jaxb + jaxb-runtime + 2.3.3 + diff --git a/onebusaway-geocoder/src/main/java/org/onebusaway/geocoder/enterprise/impl/EnterpriseFilteredGeocoderBase.java b/onebusaway-geocoder/src/main/java/org/onebusaway/geocoder/enterprise/impl/EnterpriseFilteredGeocoderBase.java index e931a0abd2..826153ec35 100644 --- a/onebusaway-geocoder/src/main/java/org/onebusaway/geocoder/enterprise/impl/EnterpriseFilteredGeocoderBase.java +++ b/onebusaway-geocoder/src/main/java/org/onebusaway/geocoder/enterprise/impl/EnterpriseFilteredGeocoderBase.java @@ -15,19 +15,18 @@ */ package org.onebusaway.geocoder.enterprise.impl; +import org.geotools.geometry.jts.JTSFactoryFinder; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.Polygon; +import org.locationtech.jts.io.ParseException; +import org.locationtech.jts.io.WKTReader; import org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderResult; import org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderService; import org.onebusaway.geocoder.model.GeocoderResults; import org.onebusaway.geocoder.services.GeocoderService; -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.Geometry; -import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.geom.Polygon; -import com.vividsolutions.jts.io.ParseException; -import com.vividsolutions.jts.io.WKTReader; - -import org.geotools.geometry.jts.JTSFactoryFinder; import java.util.ArrayList; import java.util.List; diff --git a/onebusaway-geocoder/src/main/resources/org/onebusaway/geocoder/application-context.xml b/onebusaway-geocoder/src/main/resources/org/onebusaway/geocoder/application-context.xml index 6eb796f7ff..abb51682a2 100644 --- a/onebusaway-geocoder/src/main/resources/org/onebusaway/geocoder/application-context.xml +++ b/onebusaway-geocoder/src/main/resources/org/onebusaway/geocoder/application-context.xml @@ -23,7 +23,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> diff --git a/onebusaway-geocoder/src/test/java/org/onebusaway/geocoder/impl/DatabaseCachingGeocoderImplTest.java b/onebusaway-geocoder/src/test/java/org/onebusaway/geocoder/impl/DatabaseCachingGeocoderImplTest.java index 6eab6624a1..8f75454942 100644 --- a/onebusaway-geocoder/src/test/java/org/onebusaway/geocoder/impl/DatabaseCachingGeocoderImplTest.java +++ b/onebusaway-geocoder/src/test/java/org/onebusaway/geocoder/impl/DatabaseCachingGeocoderImplTest.java @@ -20,11 +20,6 @@ import java.util.List; import org.hibernate.SessionFactory; -import org.hibernate.cfg.AnnotationConfiguration; -import org.hibernate.cfg.Configuration; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; @@ -34,11 +29,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.transaction.TransactionConfiguration; import org.springframework.transaction.annotation.Transactional; @ContextConfiguration(locations = "classpath:org/onebusaway/geocoder/impl/application-context-test.xml") -@TransactionConfiguration(transactionManager="transactionManager", defaultRollback=true) @RunWith(SpringJUnit4ClassRunner.class) public class DatabaseCachingGeocoderImplTest { diff --git a/onebusaway-geocoder/src/test/resources/org/onebusaway/geocoder/impl/application-context-hibernate-test.xml b/onebusaway-geocoder/src/test/resources/org/onebusaway/geocoder/impl/application-context-hibernate-test.xml index 51a4d4121e..037755002c 100644 --- a/onebusaway-geocoder/src/test/resources/org/onebusaway/geocoder/impl/application-context-hibernate-test.xml +++ b/onebusaway-geocoder/src/test/resources/org/onebusaway/geocoder/impl/application-context-hibernate-test.xml @@ -78,7 +78,7 @@ - @@ -88,7 +88,7 @@ - + diff --git a/onebusaway-geospatial/pom.xml b/onebusaway-geospatial/pom.xml index 150c630f79..2461418bbc 100644 --- a/onebusaway-geospatial/pom.xml +++ b/onebusaway-geospatial/pom.xml @@ -4,7 +4,7 @@ onebusaway-application-modules org.onebusaway - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-geospatial @@ -17,8 +17,8 @@ ${project.version} - com.vividsolutions - jts + org.locationtech.jts + jts-core edu.washington.cs.rse diff --git a/onebusaway-geospatial/src/main/java/org/onebusaway/geospatial/HierarchicalSTRtree.java b/onebusaway-geospatial/src/main/java/org/onebusaway/geospatial/HierarchicalSTRtree.java index 83e0339f78..8e81f7d532 100644 --- a/onebusaway-geospatial/src/main/java/org/onebusaway/geospatial/HierarchicalSTRtree.java +++ b/onebusaway-geospatial/src/main/java/org/onebusaway/geospatial/HierarchicalSTRtree.java @@ -18,11 +18,10 @@ import java.util.ArrayList; import java.util.List; +import org.locationtech.jts.geom.Envelope; +import org.locationtech.jts.index.strtree.STRtree; import org.onebusaway.geospatial.model.CoordinateBounds; -import com.vividsolutions.jts.geom.Envelope; -import com.vividsolutions.jts.index.strtree.STRtree; - public class HierarchicalSTRtree { private STRtree _parentTree; diff --git a/onebusaway-geospatial/src/main/java/org/onebusaway/geospatial/HierarchicalSTRtreeFactory.java b/onebusaway-geospatial/src/main/java/org/onebusaway/geospatial/HierarchicalSTRtreeFactory.java index 23d0d2fa42..7111fb67ee 100644 --- a/onebusaway-geospatial/src/main/java/org/onebusaway/geospatial/HierarchicalSTRtreeFactory.java +++ b/onebusaway-geospatial/src/main/java/org/onebusaway/geospatial/HierarchicalSTRtreeFactory.java @@ -18,11 +18,11 @@ import java.util.HashMap; import java.util.Map; +import org.locationtech.jts.geom.Envelope; +import org.locationtech.jts.index.strtree.STRtree; import org.onebusaway.geospatial.model.CoordinateBounds; import org.onebusaway.geospatial.services.SphericalGeometryLibrary; -import com.vividsolutions.jts.geom.Envelope; -import com.vividsolutions.jts.index.strtree.STRtree; public class HierarchicalSTRtreeFactory { diff --git a/onebusaway-geospatial/src/main/java/org/onebusaway/geospatial/model/CoordinateBounds.java b/onebusaway-geospatial/src/main/java/org/onebusaway/geospatial/model/CoordinateBounds.java index cb01bb3a24..eb1c156874 100644 --- a/onebusaway-geospatial/src/main/java/org/onebusaway/geospatial/model/CoordinateBounds.java +++ b/onebusaway-geospatial/src/main/java/org/onebusaway/geospatial/model/CoordinateBounds.java @@ -159,10 +159,10 @@ public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (_empty ? 1231 : 1237); - result = prime * result + new Double(_maxLat).hashCode(); - result = prime * result + new Double(_maxLon).hashCode(); - result = prime * result + new Double(_minLat).hashCode(); - result = prime * result + new Double(_minLon).hashCode(); + result = prime * result + Double.valueOf(_maxLat).hashCode(); + result = prime * result + Double.valueOf(_maxLon).hashCode(); + result = prime * result + Double.valueOf(_minLat).hashCode(); + result = prime * result + Double.valueOf(_minLon).hashCode(); return result; } diff --git a/onebusaway-gtfs-hibernate-spring/pom.xml b/onebusaway-gtfs-hibernate-spring/pom.xml index 81dd41e485..bae505c557 100644 --- a/onebusaway-gtfs-hibernate-spring/pom.xml +++ b/onebusaway-gtfs-hibernate-spring/pom.xml @@ -6,7 +6,7 @@ onebusaway-application-modules org.onebusaway - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT diff --git a/onebusaway-gtfs-hibernate-spring/src/main/resources/org/onebusaway/gtfs/application-context.xml b/onebusaway-gtfs-hibernate-spring/src/main/resources/org/onebusaway/gtfs/application-context.xml index 0a1100b9af..ff7e16ed39 100644 --- a/onebusaway-gtfs-hibernate-spring/src/main/resources/org/onebusaway/gtfs/application-context.xml +++ b/onebusaway-gtfs-hibernate-spring/src/main/resources/org/onebusaway/gtfs/application-context.xml @@ -23,7 +23,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> diff --git a/onebusaway-gtfs-realtime-archiver/pom.xml b/onebusaway-gtfs-realtime-archiver/pom.xml index 29e87f3216..4a542c31da 100644 --- a/onebusaway-gtfs-realtime-archiver/pom.xml +++ b/onebusaway-gtfs-realtime-archiver/pom.xml @@ -3,7 +3,7 @@ org.onebusaway onebusaway-application-modules - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-gtfs-realtime-archiver war @@ -35,7 +35,6 @@ onebusaway-gtfs-realtime-model ${project.version} - org.slf4j slf4j-log4j12 @@ -61,7 +60,7 @@ org.apache.commons commons-lang3 - 3.1 + 3.8.1 junit @@ -71,7 +70,7 @@ org.mockito mockito-core - 1.9.0-rc1 + 3.3.3 test @@ -83,7 +82,6 @@ mysql mysql-connector-java - 5.1.17 @@ -92,13 +90,6 @@ spring-webmvc - - - com.fasterxml.jackson.core - jackson-core - 2.6.3 - - diff --git a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/listener/LinkAvlRealtimeArchiverTask.java b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/listener/LinkAvlRealtimeArchiverTask.java index 615acb31e3..4b68319f7b 100644 --- a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/listener/LinkAvlRealtimeArchiverTask.java +++ b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/listener/LinkAvlRealtimeArchiverTask.java @@ -34,11 +34,11 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.SerializationConfig; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.MapperFeature; import org.onebusaway.gtfs_realtime.archiver.model.LinkAVLData; import org.onebusaway.gtfs_realtime.archiver.model.StopUpdate; import org.onebusaway.gtfs_realtime.archiver.model.TripInfo; @@ -155,9 +155,8 @@ public void run() { private LinkAVLData deserializeAvlJson(String avlJson) { LinkAVLData avlData = new LinkAVLData(); - ObjectMapper mapper = new ObjectMapper().enable(DeserializationConfig - .Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); - mapper.configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS, true); + ObjectMapper mapper = new ObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + mapper.configure(MapperFeature.AUTO_DETECT_FIELDS, true); try { avlData = mapper.readValue(avlJson, LinkAVLData.class); } diff --git a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/ArrivalTime.java b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/ArrivalTime.java index bbc62208cf..e335bc26fd 100644 --- a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/ArrivalTime.java +++ b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/ArrivalTime.java @@ -15,7 +15,7 @@ */ package org.onebusaway.gtfs_realtime.archiver.model; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; public class ArrivalTime { diff --git a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/LinkAVLData.java b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/LinkAVLData.java index a463a2d7cb..fbd58434cc 100644 --- a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/LinkAVLData.java +++ b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/LinkAVLData.java @@ -28,8 +28,8 @@ import javax.persistence.OneToMany; import javax.persistence.Table; -import org.codehaus.jackson.annotate.JsonIgnore; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.annotations.GenericGenerator; @Entity diff --git a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/StopUpdate.java b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/StopUpdate.java index f6a893efee..60fdae36ee 100644 --- a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/StopUpdate.java +++ b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/StopUpdate.java @@ -23,8 +23,8 @@ import javax.persistence.ManyToOne; import javax.persistence.Table; -import org.codehaus.jackson.annotate.JsonIgnore; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.annotations.GenericGenerator; @Entity diff --git a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/StopUpdatesList.java b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/StopUpdatesList.java index d992712889..2ef84dc890 100644 --- a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/StopUpdatesList.java +++ b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/StopUpdatesList.java @@ -17,7 +17,7 @@ import java.util.List; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; public class StopUpdatesList { diff --git a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/TripInfo.java b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/TripInfo.java index 952d33f9d9..c3a35f41b0 100644 --- a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/TripInfo.java +++ b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/TripInfo.java @@ -29,8 +29,8 @@ import javax.persistence.OneToMany; import javax.persistence.Table; -import org.codehaus.jackson.annotate.JsonIgnore; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.GenericGenerator; diff --git a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/TripInfoList.java b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/TripInfoList.java index acba6d38b5..e4490bdb8e 100644 --- a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/TripInfoList.java +++ b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/model/TripInfoList.java @@ -17,7 +17,7 @@ import java.util.List; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; public class TripInfoList { diff --git a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/AlertDaoImpl.java b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/AlertDaoImpl.java index 67b9612d55..9aa5a9dd09 100644 --- a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/AlertDaoImpl.java +++ b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/AlertDaoImpl.java @@ -38,7 +38,7 @@ public class AlertDaoImpl implements AlertDao { private SessionFactory _sessionFactory; @Autowired - @Qualifier("gtfsRealtimeArchiveSessionFactory") +// @Qualifier("gtfsRealtimeArchiveSessionFactory") public void setSessionFactory(SessionFactory sessionFactory) { _sessionFactory = sessionFactory; } diff --git a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/LinkAvlDaoImpl.java b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/LinkAvlDaoImpl.java index 8dfcacc74c..9d7d27fae8 100644 --- a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/LinkAvlDaoImpl.java +++ b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/LinkAvlDaoImpl.java @@ -39,7 +39,7 @@ public class LinkAvlDaoImpl implements LinkAvlDao { private SessionFactory _sessionFactory; @Autowired - @Qualifier("gtfsRealtimeArchiveSessionFactory") +// @Qualifier("gtfsRealtimeArchiveSessionFactory") public void setSessionFactory(SessionFactory sessionFactory) { _sessionFactory = sessionFactory; } diff --git a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/TripUpdateDaoImpl.java b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/TripUpdateDaoImpl.java index e6a41b427c..c1a5a5feb3 100644 --- a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/TripUpdateDaoImpl.java +++ b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/TripUpdateDaoImpl.java @@ -44,7 +44,7 @@ public class TripUpdateDaoImpl implements TripUpdateDao { private SessionFactory _sessionFactory; @Autowired - @Qualifier("gtfsRealtimeArchiveSessionFactory") +// @Qualifier("gtfsRealtimeArchiveSessionFactory") public void setSessionFactory(SessionFactory sessionFactory) { _sessionFactory = sessionFactory; } diff --git a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/VehiclePositionDaoImpl.java b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/VehiclePositionDaoImpl.java index 535a4374f2..8d5eb2f54a 100644 --- a/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/VehiclePositionDaoImpl.java +++ b/onebusaway-gtfs-realtime-archiver/src/main/java/org/onebusaway/gtfs_realtime/archiver/service/VehiclePositionDaoImpl.java @@ -46,7 +46,7 @@ private Session getSession(){ } @Autowired - @Qualifier("gtfsRealtimeArchiveSessionFactory") +// @Qualifier("gtfsRealtimeArchiveSessionFactory") public void setSessionFactory(SessionFactory sessionFactory) { _sessionFactory = sessionFactory; } diff --git a/onebusaway-gtfs-realtime-archiver/src/main/resources/data-sources.xml b/onebusaway-gtfs-realtime-archiver/src/main/resources/data-sources.xml index 53f51aebcc..24c56cb8a9 100644 --- a/onebusaway-gtfs-realtime-archiver/src/main/resources/data-sources.xml +++ b/onebusaway-gtfs-realtime-archiver/src/main/resources/data-sources.xml @@ -89,7 +89,7 @@ - + @@ -147,7 +147,7 @@ - @@ -93,7 +93,7 @@ - + diff --git a/onebusaway-gtfs-realtime-archiver/src/main/resources/org/onebusaway/archiver/application-context-testing.xml b/onebusaway-gtfs-realtime-archiver/src/main/resources/org/onebusaway/archiver/application-context-testing.xml index af05014545..508c233291 100644 --- a/onebusaway-gtfs-realtime-archiver/src/main/resources/org/onebusaway/archiver/application-context-testing.xml +++ b/onebusaway-gtfs-realtime-archiver/src/main/resources/org/onebusaway/archiver/application-context-testing.xml @@ -23,7 +23,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> @@ -59,7 +59,7 @@ - + diff --git a/onebusaway-gtfs-realtime-archiver/src/main/resources/org/onebusaway/archiver/application-context-webapp.xml b/onebusaway-gtfs-realtime-archiver/src/main/resources/org/onebusaway/archiver/application-context-webapp.xml index 2b9b6b2436..b8d5ed37f1 100644 --- a/onebusaway-gtfs-realtime-archiver/src/main/resources/org/onebusaway/archiver/application-context-webapp.xml +++ b/onebusaway-gtfs-realtime-archiver/src/main/resources/org/onebusaway/archiver/application-context-webapp.xml @@ -23,7 +23,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> @@ -51,7 +51,7 @@ - + diff --git a/onebusaway-gtfs-realtime-archiver/src/test/java/org/onebusaway/gtfs_realtime/archiver/service/FeedServiceImplTest.java b/onebusaway-gtfs-realtime-archiver/src/test/java/org/onebusaway/gtfs_realtime/archiver/service/FeedServiceImplTest.java index 529c545ed9..8521f2b22c 100644 --- a/onebusaway-gtfs-realtime-archiver/src/test/java/org/onebusaway/gtfs_realtime/archiver/service/FeedServiceImplTest.java +++ b/onebusaway-gtfs-realtime-archiver/src/test/java/org/onebusaway/gtfs_realtime/archiver/service/FeedServiceImplTest.java @@ -102,7 +102,7 @@ public class FeedServiceImplTest { private FeedService _feedService; @Autowired - @Qualifier("gtfsRealtimeArchiveSessionFactory") +// @Qualifier("gtfsRealtimeArchiveSessionFactory") private SessionFactory _sessionFactory; private Session getSession() { diff --git a/onebusaway-gtfs-realtime-archiver/src/test/resources/service-alerts-data-sources.xml b/onebusaway-gtfs-realtime-archiver/src/test/resources/service-alerts-data-sources.xml index 4456113f76..dd00dc2dc7 100644 --- a/onebusaway-gtfs-realtime-archiver/src/test/resources/service-alerts-data-sources.xml +++ b/onebusaway-gtfs-realtime-archiver/src/test/resources/service-alerts-data-sources.xml @@ -40,7 +40,7 @@ - + diff --git a/onebusaway-gtfs-realtime-model/pom.xml b/onebusaway-gtfs-realtime-model/pom.xml index ff3e527bba..ce00fcfaa6 100644 --- a/onebusaway-gtfs-realtime-model/pom.xml +++ b/onebusaway-gtfs-realtime-model/pom.xml @@ -3,7 +3,7 @@ org.onebusaway onebusaway-application-modules - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-gtfs-realtime-model onebusaway-gtfs-realtime-model @@ -24,7 +24,7 @@ org.onebusaway onebusaway-container - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT @@ -36,7 +36,7 @@ org.apache.commons commons-lang3 - 3.1 + 3.8.1 diff --git a/onebusaway-gwt-common/pom.xml b/onebusaway-gwt-common/pom.xml index ba3f3af106..db309f6158 100644 --- a/onebusaway-gwt-common/pom.xml +++ b/onebusaway-gwt-common/pom.xml @@ -2,7 +2,7 @@ org.onebusaway onebusaway-application-modules - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT 4.0.0 onebusaway-gwt-common diff --git a/onebusaway-nextbus-api-webapp/pom.xml b/onebusaway-nextbus-api-webapp/pom.xml index 41c7c94b0b..eb02494dca 100644 --- a/onebusaway-nextbus-api-webapp/pom.xml +++ b/onebusaway-nextbus-api-webapp/pom.xml @@ -3,7 +3,7 @@ org.onebusaway onebusaway-application-modules - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-nextbus-api-webapp war @@ -82,6 +82,13 @@ org.apache.struts struts2-rest-plugin + + + net.sf.json-lib + json-lib + 2.4 + jdk15 + @@ -116,14 +123,9 @@ com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider - 2.6.3 + ${jackson-version} - - - - - junit junit @@ -134,7 +136,6 @@ mysql mysql-connector-java - 5.1.17 org.mockito @@ -166,6 +167,17 @@ comparators 1.0.0 + + + jakarta.xml.bind + jakarta.xml.bind-api + 2.3.3 + + + org.glassfish.jaxb + jaxb-runtime + 2.3.3 + diff --git a/onebusaway-nextbus-api-webapp/src/main/resources/org/onebusaway/nextbus/application-context-webapp.xml b/onebusaway-nextbus-api-webapp/src/main/resources/org/onebusaway/nextbus/application-context-webapp.xml index 1fb835a21c..e86eb14be1 100644 --- a/onebusaway-nextbus-api-webapp/src/main/resources/org/onebusaway/nextbus/application-context-webapp.xml +++ b/onebusaway-nextbus-api-webapp/src/main/resources/org/onebusaway/nextbus/application-context-webapp.xml @@ -24,7 +24,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> diff --git a/onebusaway-nextbus-api-webapp/src/main/resources/struts-onebusaway-api-webapp.xml b/onebusaway-nextbus-api-webapp/src/main/resources/struts-onebusaway-api-webapp.xml index f9c353e62f..90054a3093 100644 --- a/onebusaway-nextbus-api-webapp/src/main/resources/struts-onebusaway-api-webapp.xml +++ b/onebusaway-nextbus-api-webapp/src/main/resources/struts-onebusaway-api-webapp.xml @@ -18,7 +18,7 @@ --> + "http://struts.apache.org/dtds/struts-2.5.dtd"> diff --git a/onebusaway-nextbus-api-webapp/src/main/resources/struts.xml b/onebusaway-nextbus-api-webapp/src/main/resources/struts.xml index 66a51505a1..355d3b50b6 100644 --- a/onebusaway-nextbus-api-webapp/src/main/resources/struts.xml +++ b/onebusaway-nextbus-api-webapp/src/main/resources/struts.xml @@ -18,7 +18,7 @@ --> + "http://struts.apache.org/dtds/struts-2.5.dtd"> diff --git a/onebusaway-nextbus-api-webapp/src/main/webapp/WEB-INF/web.xml b/onebusaway-nextbus-api-webapp/src/main/webapp/WEB-INF/web.xml index f2fbf88e61..5d0fa55e3f 100644 --- a/onebusaway-nextbus-api-webapp/src/main/webapp/WEB-INF/web.xml +++ b/onebusaway-nextbus-api-webapp/src/main/webapp/WEB-INF/web.xml @@ -59,7 +59,7 @@ struts-prepare-and-execute - org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter + org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter UrlRewriteFilter diff --git a/onebusaway-phone-webapp/pom.xml b/onebusaway-phone-webapp/pom.xml index 5cfcaa9b5a..02884b1f10 100644 --- a/onebusaway-phone-webapp/pom.xml +++ b/onebusaway-phone-webapp/pom.xml @@ -4,7 +4,7 @@ onebusaway-application-modules org.onebusaway - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-phone-webapp war diff --git a/onebusaway-phone-webapp/src/main/resources/org/onebusaway/phone/application-context-webapp.xml b/onebusaway-phone-webapp/src/main/resources/org/onebusaway/phone/application-context-webapp.xml index fb6a796551..edc79ca4ab 100644 --- a/onebusaway-phone-webapp/src/main/resources/org/onebusaway/phone/application-context-webapp.xml +++ b/onebusaway-phone-webapp/src/main/resources/org/onebusaway/phone/application-context-webapp.xml @@ -23,7 +23,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> diff --git a/onebusaway-phone/pom.xml b/onebusaway-phone/pom.xml index 9c5363d43f..8ede04b08c 100644 --- a/onebusaway-phone/pom.xml +++ b/onebusaway-phone/pom.xml @@ -3,7 +3,7 @@ org.onebusaway onebusaway-application-modules - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-phone jar diff --git a/onebusaway-phone/src/main/java/org/onebusaway/phone/SpringContainer.java b/onebusaway-phone/src/main/java/org/onebusaway/phone/SpringContainer.java index 16488300cb..d69db1340f 100644 --- a/onebusaway-phone/src/main/java/org/onebusaway/phone/SpringContainer.java +++ b/onebusaway-phone/src/main/java/org/onebusaway/phone/SpringContainer.java @@ -59,6 +59,11 @@ public ObjectFactory create(Context xworkContext) throws Exception { return f; } + + @Override + public Class type() { + return ObjectFactory.class; + } }); } } diff --git a/onebusaway-phone/src/main/java/org/onebusaway/phone/XWorkConfigurationFactoryBean.java b/onebusaway-phone/src/main/java/org/onebusaway/phone/XWorkConfigurationFactoryBean.java index 74cd07cdda..4692bfdd2c 100644 --- a/onebusaway-phone/src/main/java/org/onebusaway/phone/XWorkConfigurationFactoryBean.java +++ b/onebusaway-phone/src/main/java/org/onebusaway/phone/XWorkConfigurationFactoryBean.java @@ -52,7 +52,7 @@ public void setXmlConfigurationSources(List xmlConfigurationSources) { public Configuration getObject() throws Exception { - ConfigurationManager confManager = new ConfigurationManager(); + ConfigurationManager confManager = new ConfigurationManager("XWorkConfigurationFactoryBean"); confManager.addContainerProvider(new XWorkConfigurationProvider()); diff --git a/onebusaway-phone/src/main/java/org/onebusaway/phone/impl/IntegrationTestingInterceptor.java b/onebusaway-phone/src/main/java/org/onebusaway/phone/impl/IntegrationTestingInterceptor.java index 5d0346adae..ab4d4f006e 100644 --- a/onebusaway-phone/src/main/java/org/onebusaway/phone/impl/IntegrationTestingInterceptor.java +++ b/onebusaway-phone/src/main/java/org/onebusaway/phone/impl/IntegrationTestingInterceptor.java @@ -15,6 +15,7 @@ */ package org.onebusaway.phone.impl; +import java.util.HashMap; import java.util.Map; import org.asteriskjava.fastagi.AgiRequest; @@ -44,9 +45,12 @@ public String intercept(ActionInvocation invocation) throws Exception { */ Object value = r.remove(RESET_USER); - if (value != null && value.equals("true")) - context.getParameters().put(PhoneNumberLoginInterceptor.RESET_USER, - Boolean.TRUE); + if (value != null && value.equals("true")) { + Map resetMap = new HashMap(); + resetMap.put(PhoneNumberLoginInterceptor.RESET_USER, + Boolean.TRUE); + context.getParameters().appendAll(resetMap); + } return invocation.invoke(); } diff --git a/onebusaway-phone/src/main/resources/org/onebusaway/phone/application-context.xml b/onebusaway-phone/src/main/resources/org/onebusaway/phone/application-context.xml index 9f8763cda9..a74281da5c 100644 --- a/onebusaway-phone/src/main/resources/org/onebusaway/phone/application-context.xml +++ b/onebusaway-phone/src/main/resources/org/onebusaway/phone/application-context.xml @@ -23,7 +23,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> diff --git a/onebusaway-presentation/pom.xml b/onebusaway-presentation/pom.xml index 39b1b43bc2..d7741a88ab 100644 --- a/onebusaway-presentation/pom.xml +++ b/onebusaway-presentation/pom.xml @@ -3,7 +3,7 @@ org.onebusaway onebusaway-application-modules - 2.0.79-cs-SNAPSHOT + 2.1.12-cs-SNAPSHOT onebusaway-presentation jar @@ -68,6 +68,16 @@ org.apache.struts struts2-convention-plugin + + org.ow2.asm + asm + ${asm-version} + + + org.ow2.asm + asm-commons + ${asm-version} + org.apache.struts struts2-json-plugin @@ -137,6 +147,10 @@ comparators 1.0.0 + + commons-collections + commons-collections + diff --git a/onebusaway-presentation/src/main/java/org/onebusaway/presentation/bundles/ResourceBundleSupport.java b/onebusaway-presentation/src/main/java/org/onebusaway/presentation/bundles/ResourceBundleSupport.java index 154b1e3106..f8d22d9c51 100644 --- a/onebusaway-presentation/src/main/java/org/onebusaway/presentation/bundles/ResourceBundleSupport.java +++ b/onebusaway-presentation/src/main/java/org/onebusaway/presentation/bundles/ResourceBundleSupport.java @@ -17,18 +17,17 @@ import java.util.Enumeration; import java.util.LinkedHashMap; +import java.util.Locale; import java.util.Map; import java.util.ResourceBundle; import com.opensymphony.xwork2.LocaleProvider; -import com.opensymphony.xwork2.TextProvider; -import com.opensymphony.xwork2.TextProviderFactory; +import com.opensymphony.xwork2.util.StrutsLocalizedTextProvider; public class ResourceBundleSupport { public static Map getLocaleMap(LocaleProvider localeProvider, Class resourceType) { - TextProviderFactory factory = new TextProviderFactory(); - TextProvider provider = factory.createInstance(resourceType, localeProvider); - ResourceBundle bundle = provider.getTexts(); + StrutsLocalizedTextProvider localizedTextProvider = new StrutsLocalizedTextProvider(); + ResourceBundle bundle = localizedTextProvider.findResourceBundle(resourceType.getName(), Locale.getDefault()); Map m = new LinkedHashMap(); for (Enumeration en = bundle.getKeys(); en.hasMoreElements();) { String key = en.nextElement(); diff --git a/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/NextActionSupport.java b/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/NextActionSupport.java index 85aa31accd..a14a696b76 100644 --- a/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/NextActionSupport.java +++ b/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/NextActionSupport.java @@ -16,9 +16,11 @@ package org.onebusaway.presentation.impl; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.struts2.dispatcher.HttpParameters; import org.apache.struts2.interceptor.SessionAware; import org.onebusaway.presentation.model.NextAction; @@ -60,8 +62,11 @@ protected String getNextActionOrSuccess() { Map params = next.getParameters(); if (params != null && !params.isEmpty()) { ActionContext context = ActionContext.getContext(); - Map contextParameters = context.getParameters(); - contextParameters.putAll(params); + HttpParameters parameters = context.getParameters(); + Map contextParameters = new HashMap<>(); + for (String key : parameters.keySet()) { + contextParameters.put(key, parameters.get(key).getValue()); + } } return next.getAction(); diff --git a/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/resources/ResourceServiceImpl.java b/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/resources/ResourceServiceImpl.java index 718e347f95..c4835b15dc 100644 --- a/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/resources/ResourceServiceImpl.java +++ b/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/resources/ResourceServiceImpl.java @@ -43,6 +43,7 @@ import javax.annotation.PostConstruct; import javax.servlet.ServletContext; +import com.opensymphony.xwork2.StrutsTextProviderFactory; import org.json.JSONObject; import org.onebusaway.presentation.impl.ServletLibrary; import org.onebusaway.presentation.services.resources.Resource; @@ -80,7 +81,7 @@ public class ResourceServiceImpl implements ResourceService { private static Logger _log = LoggerFactory.getLogger(ResourceServiceImpl.class); - private static TextProviderFactory _textProviderFactory = new TextProviderFactory(); + private static StrutsTextProviderFactory _textProviderFactory = new StrutsTextProviderFactory(); private ConcurrentMap _resourceEntriesByResourcePath = new ConcurrentHashMap(); @@ -403,7 +404,7 @@ private URL getMessagesResourceAsSourceUrl(String resourceName, } TextProvider provider = _textProviderFactory.createInstance( - messagesResourceClass, localeProvider); + messagesResourceClass); ResourceBundle bundle = provider.getTexts(); Map resourceMapping = new HashMap(); @@ -855,6 +856,21 @@ public LocaleProviderImpl(Locale locale) { public Locale getLocale() { return _locale; } + + @Override + public boolean isValidLocaleString(String s) { + if ("en".equalsIgnoreCase(s)) + return true; + return false; + } + + @Override + public boolean isValidLocale(Locale locale) { + if (locale.getDisplayName().equalsIgnoreCase("en")) + return true; + return false; + } + } } diff --git a/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/users/PhoneNumberLoginInterceptor.java b/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/users/PhoneNumberLoginInterceptor.java index 908cfb42a6..a3641326e8 100644 --- a/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/users/PhoneNumberLoginInterceptor.java +++ b/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/users/PhoneNumberLoginInterceptor.java @@ -15,6 +15,7 @@ */ package org.onebusaway.presentation.impl.users; +import java.util.HashMap; import java.util.Map; import org.onebusaway.users.impl.PhoneNumberLibrary; @@ -55,7 +56,11 @@ public void setPhoneNumberParameterName(String phoneNumberParameterName) { public String intercept(ActionInvocation invocation) throws Exception { ActionContext context = invocation.getInvocationContext(); - Map params = context.getParameters(); + Map params = new HashMap<>(); + for (String key : context.getParameters().keySet()) { + params.put(key, context.getParameters().get(key).getValue()); + } + String phoneNumber = getPhoneNumber(params); phoneNumber = PhoneNumberLibrary.normalizePhoneNumber(phoneNumber); diff --git a/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/users/XWorkRequestAttributes.java b/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/users/XWorkRequestAttributes.java index e4bc607d2c..ab4e4e75f8 100644 --- a/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/users/XWorkRequestAttributes.java +++ b/onebusaway-presentation/src/main/java/org/onebusaway/presentation/impl/users/XWorkRequestAttributes.java @@ -15,6 +15,7 @@ */ package org.onebusaway.presentation.impl.users; +import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -98,11 +99,13 @@ protected void updateAccessedSessionAttributes() { private Map getScopedMap(int scope) { switch (scope) { case SCOPE_REQUEST: - return _context.getParameters(); + Map map = new HashMap<>(); + for (String key : _context.getParameters().keySet()) { + map.put(key, _context.getParameters().get(key).getValue()); + } + return map; case SCOPE_SESSION: return _context.getSession(); - case SCOPE_GLOBAL_SESSION: - return _context.getApplication(); default: throw new IllegalStateException("unknown scope=" + scope); } diff --git a/onebusaway-presentation/src/main/java/org/onebusaway/presentation/rss/RomeResult.java b/onebusaway-presentation/src/main/java/org/onebusaway/presentation/rss/RomeResult.java index fcf054a3b6..6b9d65e1ce 100644 --- a/onebusaway-presentation/src/main/java/org/onebusaway/presentation/rss/RomeResult.java +++ b/onebusaway-presentation/src/main/java/org/onebusaway/presentation/rss/RomeResult.java @@ -20,7 +20,7 @@ import com.rometools.rome.feed.synd.SyndFeed; import com.rometools.rome.io.SyndFeedOutput; import org.apache.struts2.ServletActionContext; -import org.apache.struts2.dispatcher.StrutsResultSupport; +import org.apache.struts2.result.StrutsResultSupport; import java.io.Writer; @@ -66,7 +66,7 @@ public void setEncoding(String encoding) { /** * Implementation of - * {@link org.apache.struts2.dispatcher.StrutsResultSupport#doExecute(String, com.opensymphony.xwork2.ActionInvocation)} + * {@link org.apache.struts2.result.StrutsResultSupport#doExecute(String, com.opensymphony.xwork2.ActionInvocation)} * * @param location final location (jsp page, action, etc) * @param actionInvocation the ActionInvocation diff --git a/onebusaway-presentation/src/main/java/org/onebusaway/presentation/tags/JsonComponent.java b/onebusaway-presentation/src/main/java/org/onebusaway/presentation/tags/JsonComponent.java index 383c13f208..610df8cb40 100644 --- a/onebusaway-presentation/src/main/java/org/onebusaway/presentation/tags/JsonComponent.java +++ b/onebusaway-presentation/src/main/java/org/onebusaway/presentation/tags/JsonComponent.java @@ -23,6 +23,7 @@ import org.apache.commons.lang3.StringEscapeUtils; import org.apache.struts2.components.ContextBean; +import org.apache.struts2.json.DefaultJSONWriter; import org.apache.struts2.json.JSONException; import org.apache.struts2.json.JSONUtil; @@ -72,12 +73,6 @@ public boolean end(Writer writer, String body) { String json = null; - try { - Collection empty = Collections.emptyList(); - json = JSONUtil.serialize(value, empty, empty, _ignoreHierarchy, _excludeNullProperties); - } catch (JSONException ex) { - LOG.error("Could not generate json from value", ex); - } if (json != null) { @@ -89,14 +84,22 @@ public boolean end(Writer writer, String body) { /** * We either write the url out to a variable */ + Collection empty = Collections.emptyList(); + try { + json = new DefaultJSONWriter().write(value, empty, empty, _excludeNullProperties); + } catch (JSONException e) { + LOG.error("Could not write out json value", e); + } putInContext(json); } else { /** * Or otherwise print out the url directly */ try { - writer.write(json); - } catch (IOException e) { + Collection empty = Collections.emptyList(); + new JSONUtil().serialize(writer, value, empty, empty,_ignoreHierarchy, _excludeNullProperties); + + } catch (IOException | JSONException e) { LOG.error("Could not write out json value", e); } } diff --git a/onebusaway-presentation/src/main/resources/org/onebusaway/presentation/application-context.xml b/onebusaway-presentation/src/main/resources/org/onebusaway/presentation/application-context.xml index 66b669fa88..3df60fb624 100644 --- a/onebusaway-presentation/src/main/resources/org/onebusaway/presentation/application-context.xml +++ b/onebusaway-presentation/src/main/resources/org/onebusaway/presentation/application-context.xml @@ -17,13 +17,13 @@ --> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-5.3.xsd"> diff --git a/onebusaway-presentation/src/main/resources/template/xhtml/oba-stop-info-window-template.ftl b/onebusaway-presentation/src/main/resources/template/xhtml/oba-stop-info-window-template.ftl index f4d324ae0f..31b90cb2bf 100644 --- a/onebusaway-presentation/src/main/resources/template/xhtml/oba-stop-info-window-template.ftl +++ b/onebusaway-presentation/src/main/resources/template/xhtml/oba-stop-info-window-template.ftl @@ -18,7 +18,7 @@