forked from eclipse-ee4j/krazo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run ViewResponseFilter only if controller was executed successfully
This PR should fix eclipse-ee4j#34 and eclipse-ee4j#91
- Loading branch information
Showing
10 changed files
with
350 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
testsuite/src/main/java/org/eclipse/krazo/test/mapper/FailingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright © 2019 Eclipse Krazo committers and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.eclipse.krazo.test.mapper; | ||
|
||
import javax.inject.Inject; | ||
import javax.mvc.Controller; | ||
import javax.mvc.Models; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
@Controller | ||
@Path("/mappers") | ||
public class FailingController { | ||
|
||
@Inject | ||
private Models models; | ||
|
||
@GET | ||
@Path("/success") | ||
public String success() { | ||
models.put("message", "Controller was executed without errors!"); | ||
return "success.jsp"; | ||
} | ||
|
||
@GET | ||
@Path("/fail-plain-text") | ||
public String failPlainText() { | ||
throw new PlainTextException("Error thrown by controller"); | ||
} | ||
|
||
@GET | ||
@Path("/fail-mvc-view") | ||
public String failMvcView() { | ||
throw new MvcViewException("Error thrown by controller"); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
testsuite/src/main/java/org/eclipse/krazo/test/mapper/MvcViewException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright © 2019 Eclipse Krazo committers and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.eclipse.krazo.test.mapper; | ||
|
||
public class MvcViewException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = 5452675105452096791L; | ||
|
||
public MvcViewException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
testsuite/src/main/java/org/eclipse/krazo/test/mapper/MvcViewExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright © 2019 Eclipse Krazo committers and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.eclipse.krazo.test.mapper; | ||
|
||
import org.eclipse.krazo.core.ModelsImpl; | ||
import org.eclipse.krazo.engine.Viewable; | ||
|
||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
@Provider | ||
public class MvcViewExceptionMapper implements ExceptionMapper<MvcViewException> { | ||
|
||
@Override | ||
public Response toResponse(MvcViewException exception) { | ||
|
||
ModelsImpl models = new ModelsImpl(); | ||
models.put("error", exception.getMessage()); | ||
Viewable viewable = new Viewable("mvc-error.jsp", models); | ||
|
||
return Response.status(492) | ||
.entity(viewable) | ||
.build(); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
testsuite/src/main/java/org/eclipse/krazo/test/mapper/MyApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright © 2019 Eclipse Krazo committers and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.eclipse.krazo.test.mapper; | ||
|
||
import javax.ws.rs.ApplicationPath; | ||
import javax.ws.rs.core.Application; | ||
|
||
@ApplicationPath("mvc") | ||
public class MyApplication extends Application { | ||
|
||
// nothing | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
testsuite/src/main/java/org/eclipse/krazo/test/mapper/PlainTextException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright © 2019 Eclipse Krazo committers and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.eclipse.krazo.test.mapper; | ||
|
||
public class PlainTextException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = 5452675105452096791L; | ||
|
||
public PlainTextException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
testsuite/src/main/java/org/eclipse/krazo/test/mapper/PlainTextExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright © 2019 Eclipse Krazo committers and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.eclipse.krazo.test.mapper; | ||
|
||
|
||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
@Provider | ||
public class PlainTextExceptionMapper implements ExceptionMapper<PlainTextException> { | ||
|
||
@Override | ||
public Response toResponse(PlainTextException exception) { | ||
return Response.status(491) | ||
.type(MediaType.TEXT_PLAIN_TYPE) | ||
.entity("Exception caught: " + exception.getMessage()) | ||
.build(); | ||
} | ||
|
||
} |
Oops, something went wrong.