Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom ActionException subclasses are not rethrown as new ActionException #340

Merged
merged 4 commits into from
Nov 15, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions gwtp-core/gwtp-dispatch-server-guice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<groupId>com.gwtplatform</groupId>
<artifactId>gwtp-dispatch-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
</dependency>
<dependency>
<groupId>org.jukito</groupId>
<artifactId>jukito</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright 2011 ArcBees Inc.
*
* 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.
*/

package com.gwtplatform.dispatch.server;

import com.gwtplatform.dispatch.shared.ActionException;

public class ActionExceptionThrownByHandler extends ActionException {
public ActionExceptionThrownByHandler(Throwable cause) {
super("", cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright 2011 ArcBees Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright 2013

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvermind, what Christian said prolly work better. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update all copyrights of all all files to 2013 in another PR

On Thu, Nov 14, 2013 at 10:33 AM, Brandon Donnelson <
[email protected]> wrote:

In
gwtp-core/gwtp-dispatch-server-guice/src/test/java/com/gwtplatform/dispatch/server/ActionExceptionThrownByValidator.java:

@@ -0,0 +1,25 @@
+/**

  • * Copyright 2011 ArcBees Inc.

copyright 2013


Reply to this email directly or view it on GitHubhttps://github.com//pull/340/files#r7662155
.

Simon-Pierre Gingras | *Developer
M: 418.929.0230 *|
T: @spgingras | *G+: SP Gingras
ArcBees http://www.arcbees.com/ *|
Blog http://blog.arcbees.com/ |
Facebook http://facebook.com/QueenOfTheBees |
LinkedInhttp://www.linkedin.com/company/arcbees

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the open source copy right header, is that automatic?

*
* 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.
*/

package com.gwtplatform.dispatch.server;

import com.gwtplatform.dispatch.shared.ActionException;

public class ActionExceptionThrownByValidator extends ActionException {
public ActionExceptionThrownByValidator(Throwable cause) {
super("", cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright 2011 ArcBees Inc.
*
* 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.
*/

package com.gwtplatform.dispatch.server;

import javax.inject.Inject;

import org.jukito.JukitoModule;
import org.jukito.JukitoRunner;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.gwtplatform.dispatch.server.guice.DispatchServiceImpl;
import com.gwtplatform.dispatch.server.guice.actionvalidator.DefaultActionValidator;
import com.gwtplatform.dispatch.shared.ActionException;
import com.gwtplatform.dispatch.shared.ServiceException;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

@RunWith(JukitoRunner.class)
public class ActionThrownByHandlerTest {
public static class MyModule extends JukitoModule {
@Override
protected void configureTest() {
install(new ServiceModule(DefaultActionValidator.class));
}
}

@Inject
DispatchServiceImpl service;

@Test
public void exceptionThrownByHandlerIsNotWrappedInActionException() throws ServiceException {
try {
service.execute("", new SomeAction());
fail();
} catch (ActionException e) {
assertThat(e, instanceOf(ActionExceptionThrownByHandler.class));
assertEquals(0, e.getStackTrace().length);
assertEquals(0, e.getCause().getStackTrace().length);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright 2011 ArcBees Inc.
*
* 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.
*/

package com.gwtplatform.dispatch.server;

import javax.inject.Inject;

import org.jukito.JukitoModule;
import org.jukito.JukitoRunner;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.gwtplatform.dispatch.server.guice.DispatchServiceImpl;
import com.gwtplatform.dispatch.shared.ActionException;
import com.gwtplatform.dispatch.shared.ServiceException;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

@RunWith(JukitoRunner.class)
public class ActionThrownByValidatorTest {
public static class MyModule extends JukitoModule {
@Override
protected void configureTest() {
install(new ServiceModule(ActionValidatorThatThrows.class));
}
}

@Inject
DispatchServiceImpl service;

@Test
public void exceptionThrownByValidatorIsNotWrappedInActionException() throws ServiceException {
try {
service.execute("", new SomeAction());
fail();
} catch (ActionException e) {
assertThat(e, instanceOf(ActionExceptionThrownByValidator.class));
assertEquals(0, e.getStackTrace().length);
assertEquals(0, e.getCause().getStackTrace().length);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright 2011 ArcBees Inc.
*
* 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.
*/

package com.gwtplatform.dispatch.server;

import com.gwtplatform.dispatch.server.actionvalidator.ActionValidator;
import com.gwtplatform.dispatch.shared.Action;
import com.gwtplatform.dispatch.shared.ActionException;
import com.gwtplatform.dispatch.shared.Result;

public class ActionValidatorThatThrows implements ActionValidator {
@Override
public boolean isValid(Action<? extends Result> action) throws ActionException {
throw new ActionExceptionThrownByValidator(new Exception());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright 2011 ArcBees Inc.
*
* 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.
*/

package com.gwtplatform.dispatch.server;

import javax.inject.Inject;

import com.gwtplatform.dispatch.server.actionhandler.AbstractActionHandler;
import com.gwtplatform.dispatch.shared.ActionException;
import com.gwtplatform.dispatch.shared.NoResult;

public class HandlerThatThrowsActionException extends AbstractActionHandler<SomeAction, NoResult> {
@Inject
HandlerThatThrowsActionException() {
super(SomeAction.class);
}

@Override
public NoResult execute(SomeAction action, ExecutionContext context) throws ActionException {
throw new ActionExceptionThrownByHandler(new Exception());
}

@Override
public void undo(SomeAction action, NoResult result, ExecutionContext context) throws ActionException {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright 2011 ArcBees Inc.
*
* 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.
*/

package com.gwtplatform.dispatch.server;

import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorClass;
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorMap;
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorMapImpl;
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorRegistry;
import com.gwtplatform.dispatch.server.actionvalidator.ActionValidator;
import com.gwtplatform.dispatch.server.guice.DispatchImpl;
import com.gwtplatform.dispatch.server.guice.actionhandlervalidator.ActionHandlerValidatorLinker;
import com.gwtplatform.dispatch.server.guice.actionhandlervalidator.LazyActionHandlerValidatorRegistryImpl;
import com.gwtplatform.dispatch.shared.Action;
import com.gwtplatform.dispatch.shared.Result;

public class ServiceModule extends AbstractModule {
private final Class<? extends ActionValidator> actionValidator;

public ServiceModule(Class<? extends ActionValidator> actionValidator) {
this.actionValidator = actionValidator;
}

@Override
protected void configure() {
bind(Dispatch.class).to(DispatchImpl.class);
bind(ActionHandlerValidatorRegistry.class).to(
LazyActionHandlerValidatorRegistryImpl.class).in(Singleton.class);

bindHandler(SomeAction.class, HandlerThatThrowsActionException.class, actionValidator);
requestStaticInjection(ActionHandlerValidatorLinker.class);
}

protected <A extends Action<R>, R extends Result> void bindHandler(
Class<A> actionClass, Class<? extends ActionHandler<A, R>> handlerClass,
Class<? extends ActionValidator> actionValidator) {

bind(ActionHandlerValidatorMap.class).toInstance(
new ActionHandlerValidatorMapImpl<A, R>(actionClass,
new ActionHandlerValidatorClass<A, R>(handlerClass, actionValidator)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2011 ArcBees Inc.
*
* 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.
*/

package com.gwtplatform.dispatch.server;

import com.gwtplatform.dispatch.shared.Action;
import com.gwtplatform.dispatch.shared.NoResult;

public class SomeAction implements Action<NoResult> {
@Override
public String getServiceName() {
return null;
}

@Override
public boolean isSecured() {
return false;
}
}
Loading