-
Notifications
You must be signed in to change notification settings - Fork 114
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
Ftr: catch exceptions that user defined #208
Merged
+192
−4
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fb239fa
optimize exception bug: when user defined exception, it can use unkno…
cvictory 9dddad8
optimize exception bug: when user defined exception, it can use unkno…
cvictory 60679ef
remove version
cvictory 285a2e2
fix review issue and add more test
cvictory 3098181
format import
cvictory ae5f639
remove go version from go.mod
cvictory 5e16508
remove decode byte file and support unknowexception decode
cvictory a179d0b
split imports
cvictory 370fb91
split imports
cvictory File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 hessian | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
) | ||
|
||
import ( | ||
"github.com/apache/dubbo-go-hessian2/java_exception" | ||
) | ||
|
||
var mutex sync.Mutex | ||
|
||
func checkAndGetException(cls classInfo) (structInfo, bool) { | ||
|
||
if len(cls.fieldNameList) < 4 { | ||
return structInfo{}, false | ||
} | ||
var ( | ||
throwable structInfo | ||
ok bool | ||
) | ||
var count = 0 | ||
for _, item := range cls.fieldNameList { | ||
if item == "detailMessage" || item == "suppressedExceptions" || item == "stackTrace" || item == "cause" { | ||
count++ | ||
} | ||
} | ||
// if have these 4 fields, it is throwable struct | ||
if count == 4 { | ||
mutex.Lock() | ||
defer mutex.Unlock() | ||
if throwable, ok = getStructInfo(cls.javaName); ok { | ||
wongoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return throwable, true | ||
} | ||
RegisterPOJO(newBizException(cls.javaName)) | ||
if throwable, ok = getStructInfo(cls.javaName); ok { | ||
return throwable, true | ||
} | ||
} | ||
return throwable, count == 4 | ||
} | ||
|
||
type UnknownException struct { | ||
SerialVersionUID int64 | ||
DetailMessage string | ||
SuppressedExceptions []java_exception.Throwabler | ||
StackTrace []java_exception.StackTraceElement | ||
Cause java_exception.Throwabler | ||
name string | ||
} | ||
|
||
// NewThrowable is the constructor | ||
func newBizException(name string) *UnknownException { | ||
return &UnknownException{name: name, StackTrace: []java_exception.StackTraceElement{}} | ||
} | ||
|
||
// Error output error message | ||
func (e UnknownException) Error() string { | ||
return fmt.Sprintf("throw %v : %v", e.name, e.DetailMessage) | ||
} | ||
|
||
//JavaClassName java fully qualified path | ||
func (e UnknownException) JavaClassName() string { | ||
return e.name | ||
} | ||
|
||
// equals to getStackTrace in java | ||
func (e UnknownException) GetStackTrace() []java_exception.StackTraceElement { | ||
return e.StackTrace | ||
} |
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,45 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 hessian | ||
|
||
import ( | ||
"testing" | ||
) | ||
import ( | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCheckAndGetException(t *testing.T) { | ||
clazzInfo1 := classInfo{ | ||
javaName: "com.test.UserDefinedException", | ||
fieldNameList: []string{"detailMessage", "code", "suppressedExceptions", "stackTrace", "cause"}, | ||
} | ||
s, b := checkAndGetException(clazzInfo1) | ||
assert.True(t, b) | ||
|
||
assert.Equal(t, s.javaName, "com.test.UserDefinedException") | ||
assert.Equal(t, s.goName, "hessian.UnknownException") | ||
|
||
clazzInfo2 := classInfo{ | ||
javaName: "com.test.UserDefinedException", | ||
fieldNameList: []string{"detailMessage", "code", "suppressedExceptions", "cause"}, | ||
} | ||
s, b = checkAndGetException(clazzInfo2) | ||
assert.False(t, b) | ||
assert.Equal(t, s, structInfo{}) | ||
} |
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
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,5 @@ | ||
Cjava.lang.RuntimeException�detailMessagecause | ||
stackTracesuppressedExceptions`test exceptQ�V[java.lang.StackTraceElement�?Cjava.lang.StackTraceElement�declaringClass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why display not normal ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 存储在里面是以byte数组形式。 |
||
methodNamefileName | ||
lineNumbera04com.alibaba.middleware.hsf.provider.HelloServiceImpl | ||
throwExcepHelloServiceImpl.java�0a0&sun.reflect.GeneratedMethodAccessor158invokeN�a0(sun.reflect.DelegatingMethodAccessorImplinvoke0!DelegatingMethodAccessorImpl.java�ajava.lang.reflect.MethodinvokeMethod.java��a09com.taobao.hsf.remoting.provider.ReflectInvocationHandlerhandleRequest0ReflectInvocationHandler.java�Sa09com.taobao.hsf.remoting.provider.ReflectInvocationHandlerinvokeReflectInvocationHandler.javaȣa0Gcom.taobao.hsf2dubbo.DubboServerFilterAsyncInvocationHandlerInterceptorinvoke07DubboServerFilterAsyncInvocationHandlerInterceptor.java�6a0-com.taobao.hsf.filter.FilterInvocationHandlerinvokeFilterInvocationHandler.java�a0:com.taobao.hsf.invocation.filter.RPCFilterBuilder$TailNodeinvokeRPCFilterBuilder.javaȥa0&com.taobao.hsf.debug.DebugServerFilterinvokeDebugServerFilter.java�a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0<com.taobao.hsf.common.filter.BidirectionServerResponseFilterinvoke0$BidirectionServerResponseFilter.java�a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga01com.taobao.hsf.unit.service.impl.UnitServerFilterinvokeUnitServerFilter.java�Ba0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga05com.taobao.hsf.region.service.impl.RegionServerFilterinvokeRegionServerFilter.java�a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga02com.taobao.hsf.plugins.octopus.OctopusServerFilterinvokeOctopusServerFilter.java�Ha0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0,com.taobao.hsf.plugins.spas.SpasServerFilterinvokeSpasServerFilter.java�La0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0*com.taobao.hsf.plugins.txc.TXCServerFilterinvokeTXCServerFilter.java�a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0,com.taobao.hsf.tps.component.TPSServerFilterinvokeTPSServerFilter.java�Da0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0;com.taobao.hsf.invocation.stats.InvocationStatsServerFilterinvoke0 InvocationStatsServerFilter.java�a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga08com.taobao.hsf.monitor.log.filter.MonitorLogServerFilterinvokeMonitorLogServerFilter.java�a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0,com.taobao.hsf.profiler.ProfilerServerFilterinvokeProfilerServerFilter.java�a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga04com.taobao.hsf.plugins.eagleeye.EagleEyeServerFilterinvokeEagleEyeServerFilter.java�Da0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0%com.taobao.hsf.filter.QosServerFilterinvokeQosServerFilter.java�6a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0-com.taobao.hsf.rpc.server.MethodAbsenceFilterinvokeMethodAbsenceFilter.java�0a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0$com.taobao.hsf.rpc.server.EchoFilterinvokeEchoFilter.java�a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga08com.taobao.hsf.rpc.generic.GenericInvocationServerFilterinvoke0"GenericInvocationServerFilter.java�ka0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0-com.taobao.hsf2dubbo.DubboGenericServerFilterinvokeDubboGenericServerFilter.java�a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0"com.taobao.hsf.top.TopServerFilterinvokeTopServerFilter.java�Wa0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0.com.taobao.hsf.rpc.server.ServiceAbsenceFilterinvokeServiceAbsenceFilter.java�a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0/com.taobao.hsf.common.filter.CommonServerFilterinvokeCommonServerFilter.java�a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0;com.taobao.hsf.common.filter.BidirectionServerRequestFilterinvoke0#BidirectionServerRequestFilter.java�a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga08com.taobao.hsf2dubbo.context.DubboRPCContextServerFilterinvoke0 DubboRPCContextServerFilter.java�0a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0-com.taobao.hsf.context.RPCContextServerFilterinvokeRPCContextServerFilter.java�a0.com.taobao.hsf.invocation.filter.RPCFilterNodeinvokeRPCFilterNode.java�Ga0:com.taobao.hsf.invocation.filter.RPCFilterBuilder$HeadNodeinvokeRPCFilterBuilder.javaȆa08com.taobao.hsf.invocation.filter.FilterInvocationHandlerinvokeFilterInvocationHandler.java�a0?com.taobao.hsf.remoting.provider.ServerContextInvocationHandlerinvoke0#ServerContextInvocationHandler.java�a02com.taobao.hsf.remoting.provider.ProviderProcessorhandleRequestProviderProcessor.java�Fa09com.taobao.hsf.io.remoting.hsf.message.HSFServerHandler$1runHSFServerHandler.javaȽa0'java.util.concurrent.ThreadPoolExecutor runWorkerThreadPoolExecutor.javàa0.java.util.concurrent.ThreadPoolExecutor$WorkerrunThreadPoolExecutor.java�sajava.lang.ThreadrunThread.java�Tp0&java.util.Collections$UnmodifiableList | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think should make this variable name more meaningful, like
getExceptionMutex
,checkExceptionMutex
etc?