Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.

Commit 3e47951

Browse files
Moved the examples to the default package.
Changed the error handling code to use the new setErrorResponse method where needed.
1 parent a05203a commit 3e47951

File tree

8 files changed

+24
-26
lines changed

8 files changed

+24
-26
lines changed

build-src/build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<property name="datasource" value="java/com/google/visualization/datasource"/>
1313
<property name="src.datasource" location="${src}/main/${datasource}"/>
1414
<property name="src.test.datasource" location="${src}/test/${datasource}"/>
15-
<property name="src.example" location="../examples/src/${datasource}/example"/>
15+
<property name="src.example" location="../examples/src/java"/>
1616

1717
<!-- User properties -->
1818
<property file="build.properties"/>

examples/src/java/com/google/visualization/datasource/example/AdvancedExampleServlet.java renamed to examples/src/java/AdvancedExampleServlet.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
package com.google.visualization.datasource.example;
1514

1615
import com.google.common.collect.Lists;
1716
import com.google.visualization.datasource.Capabilities;

examples/src/java/com/google/visualization/datasource/example/AdvancedExampleServlet2.java renamed to examples/src/java/AdvancedExampleServlet2.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
package com.google.visualization.datasource.example;
1514

1615
import com.google.common.collect.Lists;
1716
import com.google.visualization.datasource.Capabilities;
@@ -20,6 +19,8 @@
2019
import com.google.visualization.datasource.QueryPair;
2120
import com.google.visualization.datasource.base.DataSourceException;
2221
import com.google.visualization.datasource.base.ReasonType;
22+
import com.google.visualization.datasource.base.ResponseStatus;
23+
import com.google.visualization.datasource.base.StatusType;
2324
import com.google.visualization.datasource.base.TypeMismatchException;
2425
import com.google.visualization.datasource.datatable.ColumnDescription;
2526
import com.google.visualization.datasource.datatable.DataTable;
@@ -166,13 +167,12 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO
166167
DataSourceHelper.setServletResponse(newData, dsRequest, resp);
167168
} catch (RuntimeException rte) {
168169
log.error("A runtime exception has occured", rte);
169-
DataSourceException dataSourceException = new DataSourceException(
170-
ReasonType.INTERNAL_ERROR, rte.getMessage());
171-
if (dsRequest != null) {
172-
DataSourceHelper.setServletErrorResponse(dataSourceException, dsRequest, resp);
173-
} else {
174-
DataSourceHelper.setServletErrorResponse(dataSourceException, req, resp);
170+
ResponseStatus status = new ResponseStatus(StatusType.ERROR, ReasonType.INTERNAL_ERROR,
171+
rte.getMessage());
172+
if (dsRequest == null) {
173+
dsRequest = DataSourceRequest.getDefaultDataSourceRequest(req);
175174
}
175+
DataSourceHelper.setServletErrorResponse(status, dsRequest, resp);
176176
} catch (DataSourceException e) {
177177
if (dsRequest != null) {
178178
DataSourceHelper.setServletErrorResponse(e, dsRequest, resp);

examples/src/java/com/google/visualization/datasource/example/CsvDataSourceServlet.java renamed to examples/src/java/CsvDataSourceServlet.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
package com.google.visualization.datasource.example;
1514

1615
import com.google.visualization.datasource.DataSourceHelper;
1716
import com.google.visualization.datasource.DataSourceServlet;
@@ -84,6 +83,10 @@ public DataTable generateDataTable(Query query, HttpServletRequest request)
8483
DataTable dataTable = null;
8584
ULocale requestLocale = DataSourceHelper.getLocaleFromRequest(request);
8685
try {
86+
// Note: We assumes that all the columns in the CSV file are TEXT columns. In cases where the
87+
// column types are known in advance, this behavior can be overridden by passing a list of
88+
// ColumnDescription objects specifying the column types. See CsvDataSourceHelper.read() for
89+
// more details.
8790
dataTable = CsvDataSourceHelper.read(reader, null, true, requestLocale);
8891
} catch (IOException e) {
8992
log.error("Couldn't read from url: " + url, e);

examples/src/java/com/google/visualization/datasource/example/SimpleExampleServlet.java renamed to examples/src/java/SimpleExampleServlet.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
package com.google.visualization.datasource.example;
1514

1615
import com.google.visualization.datasource.DataSourceServlet;
1716
import com.google.visualization.datasource.base.TypeMismatchException;

examples/src/java/com/google/visualization/datasource/example/SimpleExampleServlet2.java renamed to examples/src/java/SimpleExampleServlet2.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
package com.google.visualization.datasource.example;
1514

1615
import com.google.visualization.datasource.DataSourceHelper;
1716
import com.google.visualization.datasource.DataSourceRequest;
1817
import com.google.visualization.datasource.base.DataSourceException;
1918
import com.google.visualization.datasource.base.ReasonType;
19+
import com.google.visualization.datasource.base.ResponseStatus;
20+
import com.google.visualization.datasource.base.StatusType;
2021
import com.google.visualization.datasource.base.TypeMismatchException;
2122
import com.google.visualization.datasource.datatable.ColumnDescription;
2223
import com.google.visualization.datasource.datatable.DataTable;
@@ -74,13 +75,12 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
7475
DataSourceHelper.setServletResponse(newData, dsRequest, resp);
7576
} catch (RuntimeException rte) {
7677
log.error("A runtime exception has occured", rte);
77-
DataSourceException dataSourceException = new DataSourceException(
78-
ReasonType.INTERNAL_ERROR, rte.getMessage());
79-
if (dsRequest != null) {
80-
DataSourceHelper.setServletErrorResponse(dataSourceException, dsRequest, resp);
81-
} else {
82-
DataSourceHelper.setServletErrorResponse(dataSourceException, req, resp);
78+
ResponseStatus status = new ResponseStatus(StatusType.ERROR, ReasonType.INTERNAL_ERROR,
79+
rte.getMessage());
80+
if (dsRequest == null) {
81+
dsRequest = DataSourceRequest.getDefaultDataSourceRequest(req);
8382
}
83+
DataSourceHelper.setServletErrorResponse(status, dsRequest, resp);
8484
} catch (DataSourceException e) {
8585
if (dsRequest != null) {
8686
DataSourceHelper.setServletErrorResponse(e, dsRequest, resp);

examples/src/java/com/google/visualization/datasource/example/SqlDataSourceServlet.java renamed to examples/src/java/SqlDataSourceServlet.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.visualization.datasource.example;
16-
1715
import com.google.visualization.datasource.Capabilities;
1816
import com.google.visualization.datasource.DataSourceServlet;
1917
import com.google.visualization.datasource.base.DataSourceException;

src/main/java/com/google/visualization/datasource/DataSourceHelper.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,12 @@ public static void executeDataSourceServletFlow(HttpServletRequest req, HttpServ
146146
}
147147
} catch (RuntimeException e) {
148148
log.error("A runtime exception has occured", e);
149-
DataSourceException dsException =
150-
new DataSourceException(ReasonType.INTERNAL_ERROR, e.getMessage());
151-
if (dsRequest != null) {
152-
DataSourceHelper.setServletErrorResponse(dsException, dsRequest, resp);
153-
} else {
154-
DataSourceHelper.setServletErrorResponse(dsException, req, resp);
149+
ResponseStatus status = new ResponseStatus(StatusType.ERROR, ReasonType.INTERNAL_ERROR,
150+
e.getMessage());
151+
if (dsRequest == null) {
152+
dsRequest = DataSourceRequest.getDefaultDataSourceRequest(req);
155153
}
154+
DataSourceHelper.setServletErrorResponse(status, dsRequest, resp);
156155
}
157156
}
158157

0 commit comments

Comments
 (0)