Search in sources :

Example 6 with FeedMessage

use of com.google.transit.realtime.GtfsRealtime.FeedMessage in project onebusaway-application-modules by camsys.

the class GtfsRtProxyAction method getFeedMessage.

private FeedMessage getFeedMessage(String url) {
    try {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpGet request = new HttpGet(url);
        CloseableHttpResponse response = httpclient.execute(request);
        InputStream is = response.getEntity().getContent();
        FeedMessage message = FeedMessage.parseFrom(is, _registry);
        httpclient.close();
        return message;
    } catch (Exception e) {
        _log.error("Error retrieving trip updates: " + e);
    }
    return null;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 7 with FeedMessage

use of com.google.transit.realtime.GtfsRealtime.FeedMessage in project onebusaway-application-modules by camsys.

the class AlertsFromRssResource method getAll.

@Path("/service-alerts")
@GET
@Produces("application/x-google-protobuff")
public Response getAll() {
    final FeedMessage serviceAlertFeed = _alertsService.getServlceAlertFeed();
    if (serviceAlertFeed == null) {
        return Response.ok().build();
    }
    StreamingOutput stream = new StreamingOutput() {

        @Override
        public void write(OutputStream os) throws IOException, WebApplicationException {
            // Service Alerts know how to write themselves as protocol buffers
            serviceAlertFeed.writeTo(os);
        }
    };
    Response response = Response.ok(stream).build();
    return response;
}
Also used : Response(javax.ws.rs.core.Response) FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) OutputStream(java.io.OutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with FeedMessage

use of com.google.transit.realtime.GtfsRealtime.FeedMessage in project onebusaway-application-modules by camsys.

the class GtfsRealtimeArchiverTask method update.

public void update() throws IOException {
    FeedMessage tripUpdates = readOrReturnDefault(_tripUpdatesUrl);
    FeedMessage vehiclePositions = readOrReturnDefault(_vehiclePositionsUrl);
    FeedMessage alerts = readOrReturnDefault(_alertsUrl);
    _feedService.readTripUpdates(tripUpdates, _entitySource);
    _feedService.readVehiclePositions(vehiclePositions, _entitySource);
    _feedService.readAlerts(alerts, _entitySource);
}
Also used : FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage)

Example 9 with FeedMessage

use of com.google.transit.realtime.GtfsRealtime.FeedMessage in project onebusaway-application-modules by camsys.

the class GtfsRealtimeController method vehiclePositions.

@RequestMapping(value = "/gtfs-realtime/vehicle-positions.action")
public void vehiclePositions(ServletRequest request, HttpServletResponse response) throws IOException {
    FeedMessage vehiclePositions = _gtfsRealtimeService.getVehiclePositions();
    render(request, response, vehiclePositions);
}
Also used : FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with FeedMessage

use of com.google.transit.realtime.GtfsRealtime.FeedMessage in project OpenTripPlanner by opentripplanner.

the class GtfsTest method setUp.

protected void setUp() {
    File gtfs = new File("src/test/resources/" + getFeedName());
    File gtfsRealTime = new File("src/test/resources/" + getFeedName() + ".pb");
    GtfsBundle gtfsBundle = new GtfsBundle(gtfs);
    feedId = new GtfsFeedId.Builder().id("FEED").build();
    gtfsBundle.setFeedId(feedId);
    List<GtfsBundle> gtfsBundleList = Collections.singletonList(gtfsBundle);
    GtfsModule gtfsGraphBuilderImpl = new GtfsModule(gtfsBundleList);
    alertsUpdateHandler = new AlertsUpdateHandler();
    graph = new Graph();
    router = new Router("TEST", graph);
    gtfsBundle.setTransfersTxtDefinesStationPaths(true);
    gtfsGraphBuilderImpl.buildGraph(graph, null);
    // Set the agency ID to be used for tests to the first one in the feed.
    agencyId = graph.getAgencies(feedId.getId()).iterator().next().getId();
    System.out.printf("Set the agency ID for this test to %s\n", agencyId);
    graph.index(new DefaultStreetVertexIndexFactory());
    timetableSnapshotSource = new TimetableSnapshotSource(graph);
    timetableSnapshotSource.purgeExpiredData = (false);
    graph.timetableSnapshotSource = (timetableSnapshotSource);
    alertPatchServiceImpl = new AlertPatchServiceImpl(graph);
    alertsUpdateHandler.setAlertPatchService(alertPatchServiceImpl);
    alertsUpdateHandler.setFeedId(feedId.getId());
    try {
        final boolean fullDataset = false;
        InputStream inputStream = new FileInputStream(gtfsRealTime);
        FeedMessage feedMessage = FeedMessage.PARSER.parseFrom(inputStream);
        List<FeedEntity> feedEntityList = feedMessage.getEntityList();
        List<TripUpdate> updates = new ArrayList<TripUpdate>(feedEntityList.size());
        for (FeedEntity feedEntity : feedEntityList) {
            updates.add(feedEntity.getTripUpdate());
        }
        timetableSnapshotSource.applyTripUpdates(graph, fullDataset, updates, feedId.getId());
        alertsUpdateHandler.update(feedMessage);
    } catch (Exception exception) {
    }
}
Also used : TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) GtfsFeedId(org.opentripplanner.graph_builder.module.GtfsFeedId) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Router(org.opentripplanner.standalone.Router) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) AlertPatchServiceImpl(org.opentripplanner.routing.impl.AlertPatchServiceImpl) FileInputStream(java.io.FileInputStream) FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) GtfsModule(org.opentripplanner.graph_builder.module.GtfsModule) Graph(org.opentripplanner.routing.graph.Graph) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) File(java.io.File) TimetableSnapshotSource(org.opentripplanner.updater.stoptime.TimetableSnapshotSource) AlertsUpdateHandler(org.opentripplanner.updater.alerts.AlertsUpdateHandler)

Aggregations

FeedMessage (com.google.transit.realtime.GtfsRealtime.FeedMessage)24 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)8 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)4 Date (java.util.Date)4 Test (org.junit.Test)4 ResponseBean (org.onebusaway.api.model.ResponseBean)3 ListBean (org.onebusaway.transit_data.model.ListBean)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 TranslatedString (com.google.transit.realtime.GtfsRealtime.TranslatedString)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 List (java.util.List)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 RouteBean (org.onebusaway.transit_data.model.RouteBean)2