# Java FlightXML Program Print Altitudes

**URL:** <https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129>\
**Category:** AeroAPI\
**Created:** [August 3, 2015, 5:51pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129 "2015-08-03T17:51:48Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![RSonecha](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@RSonecha](https://discussions.flightaware.com/u/RSonecha)\
**Post date:** [August 3, 2015, 5:51pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/1 "2015-08-03T17:51:48Z")

</div>

I am using the Netbeans version of the Flight XML Java code. I was wondering if there is a way to print out all the altitudes and timings for a flight, given the airline and flight number. Does anyone have any code that does this, or any tips on what methods and classes to use?  
Thanks for the help!

---

<div class="post-metadata">

**Author:** ![RSonecha](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@RSonecha](https://discussions.flightaware.com/u/RSonecha)\
**Post date:** [August 4, 2015, 9:39pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/2 "2015-08-04T21:39:57Z")

</div>

I found this: [http://flightxml.flightaware.com/soap/FlightXML2/doc#op\_GetFlightID](http://flightxml.flightaware.com/soap/FlightXML2/doc#op_GetFlightID) (the getHistoricalTrackInformation operator)

Now the problem is that I don’t know where to find the faFlightID. I would use the getFlightID operation, but I don’t have an enterprise membership, thus I do not have access to the ident. Is there a workaround for this?

Thanks!

---

<div class="post-metadata">

**Author:** ![bovineone](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/bovineone/32/117631_2.png) [@bovineone](https://discussions.flightaware.com/u/bovineone)\
**Post date:** [August 5, 2015, 7:24pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/3 "2015-08-05T19:24:48Z")

</div>

FlightInfoEx includes the faFlightID of each flight that it returned.

---

<div class="post-metadata">

**Author:** ![RSonecha](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@RSonecha](https://discussions.flightaware.com/u/RSonecha)\
**Post date:** [August 5, 2015, 10:32pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/4 "2015-08-05T22:32:33Z")

</div>

Can you show me an example of how to use that to get the data I need?

Given a specific flight I’m looking for something along the lines of:

Time Alt  
3:34 1000 ft  
3:40 15,000 ft  
etc.

---

<div class="post-metadata">

**Author:** ![bovineone](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/bovineone/32/117631_2.png) [@bovineone](https://discussions.flightaware.com/u/bovineone)\
**Post date:** [August 5, 2015, 11:00pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/5 "2015-08-05T23:00:48Z")

</div>

Call FlightInfoEx with the ident of the flight you are interested in (such as the most recent one that has arrived), then call GetHistoricalTrack to get the position data for it. Here’s some pseudocode:

```auto

flights = FlightInfoEx(ident => "UAL5", howMany => 10, offset => 0);
foreach (flight in flights) {
   if (flight.actualdeparturetime > 0 && flight.actualarrivaltime > 0) {
       track = GetHistoricalTrack(faFlightID => flight.faFlightId);
       foreach (pos in track.data) {
          println EpochToHuman(pos.timestamp), pos.altitude
       }
       break
   }
}

```

---

<div class="post-metadata">

**Author:** ![RSonecha](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@RSonecha](https://discussions.flightaware.com/u/RSonecha)\
**Post date:** [August 6, 2015, 4:59pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/6 "2015-08-06T16:59:35Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![RSonecha](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@RSonecha](https://discussions.flightaware.com/u/RSonecha)\
**Post date:** [August 6, 2015, 9:21pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/7 "2015-08-06T21:21:33Z")

</div>

FlightInfoExRequest flight\_req = new FlightInfoExRequest();  
flight\_req.setHowMany(1);  
flight\_req.setIdent(“UAL468”);  
flight\_req.setOffset(0);  
**FlightInfoExResult** flight = df.\*\*FlightInfoEx(\*\*flight\_req);  
if (flight.actualDepartureTime \> 0 && flight.actualarrivaltime \> 0){  
GetHistoricalTrackRequest track = new GetHistoricalTrackRequest();  
track.setFaFlightID(flight.faFlightID);  
**for(pos:track.data){  
System.out.println(EpochToHuman(pos.timestamp) " " pos.altitude);**

```
    }
}

```

Here is my code so far. The parts in red are where I am getting errors. Can you tell me what is wrong?

---

<div class="post-metadata">

**Author:** ![RSonecha](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@RSonecha](https://discussions.flightaware.com/u/RSonecha)\
**Post date:** [August 6, 2015, 9:31pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/8 "2015-08-06T21:31:41Z")

</div>

Also, how can I tweak the code to give me the altitude data for a specific flight. For example the UAL468 flight on April 9th from SEA to SFO at 7:41am ([http://flightaware.com/live/flight/UAL468/history/20150409/1425Z/KSEA/KSFO](http://flightaware.com/live/flight/UAL468/history/20150409/1425Z/KSEA/KSFO)). Is there an ID for that specific flight, and if so, where do I find it and how do I incorporate it into my code?

---

<div class="post-metadata">

**Author:** ![bovineone](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/bovineone/32/117631_2.png) [@bovineone](https://discussions.flightaware.com/u/bovineone)\
**Post date:** [August 7, 2015, 5:04pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/9 "2015-08-07T17:04:22Z")

</div>

> [@RSonecha](#):
>
> FlightInfoExRequest flight\_req = new FlightInfoExRequest();  
> flight\_req.setHowMany(1);  
> flight\_req.setIdent(“UAL468”);  
> flight\_req.setOffset(0);  
> **FlightInfoExResult** flight = df.\*\*FlightInfoEx(\*\*flight\_req);  
> if (flight.actualDepartureTime \> 0 && flight.actualarrivaltime \> 0){  
> GetHistoricalTrackRequest track = new GetHistoricalTrackRequest();  
> track.setFaFlightID(flight.faFlightID);  
> **for(pos:track.data){  
> System.out.println(EpochToHuman(pos.timestamp) " " pos.altitude);**
> 
> ```
> }
> }
> 
> ```
> 
> Here is my code so far. The parts in red are where I am getting errors. Can you tell me what is wrong?

Do not use howMany of 1. You will only get one flight (and that is probably not the one flight you want, since it is likely to be a future flight that hasn’t occurred yet). FlightInfoEx will be returning an array of flights, even if it is an array of 1 element.

For the Java, you will need to actually look at the auto-generated interface bindings that were produced by the Axis command-line program, in order to figure out the names of the classes and methods. Most of the structure members are accessed using accessors, rather than directly, I think. (For example actualDepartureTime and actualarrivaltime)

The function “EpochToHuman” does not actually exist, since my example was pseudo-code. You will need to find the appropriate conversion for Java, or implement your own. Additionally, I think Java will require you to combine those strings using “+” at least.

---

<div class="post-metadata">

**Author:** ![RSonecha](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@RSonecha](https://discussions.flightaware.com/u/RSonecha)\
**Post date:** [August 7, 2015, 5:19pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/10 "2015-08-07T17:19:01Z")

</div>

I’m sorry, I’m not sure I understand what you mean by “Most of the structure members are accessed using accessors”. How would you suggest I change my code? I’m pretty new to Java, so I need a little more help, please. Thanks!

---

<div class="post-metadata">

**Author:** ![bovineone](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/bovineone/32/117631_2.png) [@bovineone](https://discussions.flightaware.com/u/bovineone)\
**Post date:** [August 7, 2015, 6:18pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/11 "2015-08-07T18:18:14Z")

</div>

Did you run the wsdl2java.sh utility yet, as shown in the example? You need to do that before attempting to develop against any of these interfaces. Once you’ve done that, you will be able to explore the generated java interface file and see what the automatically generated names of the structures and methods are, and how they are nested.

In Java, an “accessor” is a method to get or set a member variable. For example, “setHowMany()” is a setter method for the “howMany” variable, which you would not simply access directly.

If you are unfamiliar with Java development and encountering syntax errors during compilation, you may want to seek other programming books/references first, as I am not prepared to teach programming fundamentals.

---

<div class="post-metadata">

**Author:** ![Staf12](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/staf12/32/52732_2.png) [@Staf12](https://discussions.flightaware.com/u/Staf12)\
**Post date:** [February 23, 2017, 4:35pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/12 "2017-02-23T16:35:56Z")

</div>

> [@bovineone](#):
>
> Call FlightInfoEx with the ident of the flight you are interested in (such as the most recent one that has arrived), then call GetHistoricalTrack to get the position data for it. Here’s some pseudocode:
> 
> ```auto
> 
> flights = FlightInfoEx(ident => "UAL5", howMany => 10, offset => 0);
> foreach (flight in flights) {
> if (flight.actualdeparturetime > 0 && flight.actualarrivaltime > 0) {
> track = GetHistoricalTrack(faFlightID => flight.faFlightId);
> foreach (pos in track.data) {
> println EpochToHuman(pos.timestamp), pos.altitude
> }
> break
> }
> }
> 
> ```

is there any other condition (except departure and arrival times) which can filter out useless flight IDs? for example, I am trying to get tracks of BAW2653, so I called

```auto

https://flightxml.flightaware.com/json/FlightXML2/FlightInfoEx?ident=baw2653&howmany=1&offset=0

```

to get flight IDs for future use with GetHistoricalTrack. it returned 15 (I dont know why when I set howMany to 1) results, including

```auto

{"faFlightID":"BAW2653-1487571930-airline-0283:0","ident":"BAW2653","aircrafttype":"A320","filed_ete":"01:54:00","filed_time":1487681960,"filed_departuretime":1487757900,"filed_airspeed_kts":332,"filed_airspeed_mach":"","filed_altitude":0,"route":"","actualdeparturetime":1487758080,"estimatedarrivaltime":1487764500,"actualarrivaltime":1487764511,"diverted":"","origin":"LOWS","destination":"EGKK","originName":"Salzburg (W. A. Mozart)","originCity":"Salzburg, Salzburg","destinationName":"London Gatwick","destinationCity":"London, England"}

```

and when I use this one in a call

```auto

https://flightxml.flightaware.com/json/FlightXML2/GetHistoricalTrack?faFlightID=BAW2653-1487571930-airline-0283:0

```

the result is “{“error”:“no data available”}”

---

<div class="post-metadata">

**Author:** ![bovineone](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/bovineone/32/117631_2.png) [@bovineone](https://discussions.flightaware.com/u/bovineone)\
**Post date:** [February 28, 2017, 4:30pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/13 "2017-02-28T16:30:02Z")

</div>

You are calling it with “howmany” not “howMany” (case sensitive), so the argument was ignored.

In any case, you do not want to pass 1 for howMany… You definitely want more than one so that your application can pick which flight it wants. The first one is almost always not the one most people actually want, since that is one furthest in the future that we are tracking.

That also explains why GetHistoricalTrack is failing for that flight. It is so far in the future that it has not occurred yet and we do not have a track for it yet.

---

<div class="post-metadata">

**Author:** ![Staf12](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/staf12/32/52732_2.png) [@Staf12](https://discussions.flightaware.com/u/Staf12)\
**Post date:** [March 1, 2017, 2:12pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/14 "2017-03-01T14:12:29Z")

</div>

thanks! it was my mistake with the case sensitivity 😒

the second explanation, maybe my calculator is wrong, but I think it wasn’t about future. based on the timestamp that flight occurred before my call/post (flightID: 1487571930 = Monday, February 20, actual duration of the flight: Feb 22 from 11:09AM to 12:54 PM, my call: Thu Feb 23, 2017). Now, with the same call I get a valid result.

---

<div class="post-metadata">

**Author:** ![obj](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/obj/32/118984_2.png) [@obj](https://discussions.flightaware.com/u/obj)\
**Post date:** [March 1, 2017, 3:49pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/15 "2017-03-01T15:49:24Z")

</div>

> [@Staf12](#):
>
> flightID: 1487571930 = Monday, February 20

The number in the flight ID has nothing to do with the time of the flight. Flight IDs are opaque identifiers, you shouldn’t try to interpret them.

---

<div class="post-metadata">

**Author:** ![Staf12](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/staf12/32/52732_2.png) [@Staf12](https://discussions.flightaware.com/u/Staf12)\
**Post date:** [March 2, 2017, 8:31am UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/16 "2017-03-02T08:31:31Z")

</div>

that’s exactly why I emphasized also that the flight itself occurred a day before my query

---

<div class="post-metadata">

**Author:** ![bovineone](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/bovineone/32/117631_2.png) [@bovineone](https://discussions.flightaware.com/u/bovineone)\
**Post date:** [March 2, 2017, 5:23pm UTC](https://discussions.flightaware.com/t/java-flightxml-program-print-altitudes/17129/17 "2017-03-02T17:23:51Z")

</div>

GetHistoricalTrack is generally intended only for past flights that have already arrived. (There may also be a slight database replication delay of a few minutes between when a flight arrives and when it is available from GetHistoricalTrack.)

If the flight is still the most recent flight then GetLastTrack can still be used.
