Stocks rose on Friday after government data showed the economy contracted less than expected in the second quarter, indicating the recession may be moderating.

But the mood was cautious as the report showed the U.S. consumer reined in spending during the period, which may bode ill for hopes of a speedy recovery.

Oil and copper prices moved higher after the data, but the price of safe-haven U.S. Treasury debt also rose in a sign of underlying caution.

Trading was volatile as investors digested the mixed news from the government's first estimate of gross domestic product. Consumer spending, part of the GDP report, is considered a crucial driver of corporate profits and economic activity..

GDP fell at a 1.0 percent annual rate after tumbling 6.4 percent in the January-March period. Economists had expected a 1.5 percent decline in the second quarter.

The GDP number came in better than expected but was masked by a lot of government spending and the consumer pulled back, said Jack Ablin, chief investment officer at Harris Private Bank in Chicago. When you're fueling economic growth on government spending, clearly that is not a sustainable situation.

The GDP report showed consumer spending, which accounts for about two-thirds of U.S. economic activity, fell in the second quarter after rising in the previous quarter.

But overall my take is that we still are going to enjoy a cyclical recovery and the third quarter will likely come in positive territory, Ablin said.

The Dow Jones industrial average <.DJI> rose 28.87 points, or 0.32 percent, at 9,183.33. The Standard & Poor's 500 Index <.SPX> gained 2.76 points, or 0.28 percent, at 989.51. The Nasdaq Composite Index <.IXIC> added 6.09 points, or 0.31 percent, at 1,990.39.

If the benchmark S&P 500 Index finishes higher, it would mark its fifth straight monthly advance.

Another report showing that business activity in the U.S. Midwest was the strongest in July in 10 months also lifted stocks.

What you're seeing is numbers that are an improvement, but a lackluster improvement. They're less bad, but not great, said Chad Morganlander a portfolio manager at Stifel, Nicolaus & Co in Florham Park, New Jersey.

Travelers Cos Inc , one of the largest U.S. home, auto and commercial insurers, was one of the standouts following positive broker comments, a day after the company raised its forecast for the year. Its stock jumped 2.5 percent to $43.

On the downside, Walt Disney Co shed 3.6 percent to $25.29. The media and entertainment powerhouse reported a 26 percent slide in quarterly earnings late Thursday as the recession continued to hurt advertising and consumer spending.

Even though Disney beat expectations by a hair, its shares were the Dow's top drag. JPMorgan downgraded the stock to underweight from neutral on Friday.

(Reporting by Edward Krudy; Editing by Kenneth Barry)