-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New approach: use RemoteThrowable in order to avoid any kind of deser…
…ialized Exception 2 issues could happens with previous implementation: - InvalidDefinitionException: when you try to deserialize a Class that doesn't have a default constructor - InvalidTypeIdException: when you try to deserialize a Class that is not accessible (not in the classpath) by server side The new approach is to convert your original Throwable to a RemoteThrowable.
- Loading branch information
1 parent
0efbe64
commit b3d5e34
Showing
9 changed files
with
215 additions
and
55 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
55 changes: 55 additions & 0 deletions
55
...ging/src/main/java/com/github/nmorel/gwtjackson/remotelogging/shared/RemoteThrowable.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,55 @@ | ||
/* | ||
* Copyright 2018 Nicolas Morel | ||
* | ||
* 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.github.nmorel.gwtjackson.remotelogging.shared; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
@JsonIgnoreProperties( {"localizedMessage", "suppressed"} ) | ||
public final class RemoteThrowable extends Throwable { | ||
|
||
private final String remoteClassName; | ||
|
||
public RemoteThrowable( Throwable throwable ) { | ||
super( throwable.getMessage(), throwable.getCause() != null ? new RemoteThrowable( throwable.getCause() ) : null ); | ||
setStackTrace( throwable.getStackTrace() ); | ||
remoteClassName = throwable.getClass().getName(); | ||
} | ||
|
||
@JsonCreator | ||
public RemoteThrowable( @JsonProperty( "message" ) String message, @JsonProperty( "cause" ) RemoteThrowable cause, @JsonProperty( | ||
"remoteClassName" ) String remoteClassName ) { | ||
super( message, cause ); | ||
this.remoteClassName = remoteClassName; | ||
} | ||
|
||
public String getRemoteClassName() { | ||
return remoteClassName; | ||
} | ||
|
||
@Override | ||
public synchronized RemoteThrowable getCause() { | ||
return (RemoteThrowable) super.getCause(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String message = getMessage(); | ||
return (message != null) ? (remoteClassName + ": " + message) : remoteClassName; | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
...ging/src/test/java/com/github/nmorel/gwtjackson/remotelogging/shared/CustomException.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,31 @@ | ||
/* | ||
* Copyright 2018 Nicolas Morel | ||
* | ||
* 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.github.nmorel.gwtjackson.remotelogging.shared; | ||
|
||
public class CustomException extends Exception { | ||
|
||
private final Object object; | ||
|
||
public CustomException( String message, Throwable cause, Object object ) { | ||
super( message, cause ); | ||
this.object = object; | ||
} | ||
|
||
public Object getObject() { | ||
return object; | ||
} | ||
} |
Oops, something went wrong.