If you use a SpatialRelator, with your lines as the requestor and the polygons as the supplier, you can use the related candidates-parameter (should be 2).
If there is a risk of intersections other points of the line too, use a snipper with (5%,95%) and perform the same process on the first and last snippet of the line. Then aggregate and sum the related candidates.
Alternatively you can extract the start and end points of each line using a coordinate extractor (0 for start of line -1 for end of line), create points and perform a spatial test using spatial relator to see if the point touches a polygon. Aggregate the results based on an id for the line feature summing the related candidates and only those lines that have related candidates of 2 touch a polygon at both ends
I tried the SpatialRelator and it works. Thanks for the answers.