-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #653 from i-Cell-Mobilsoft-Open-Source/feature/652…
…-enhanced-grpc-server-exception-listener Feature/652 enhanced grpc server exception listener
- Loading branch information
Showing
15 changed files
with
601 additions
and
20 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...coffee-grpc-api/src/main/java/hu/icellmobilsoft/coffee/grpc/api/metadata/IGrpcHeader.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 @@ | ||
/*- | ||
* #%L | ||
* Coffee | ||
* %% | ||
* Copyright (C) 2020 - 2024 i-Cell Mobilsoft Zrt. | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
package hu.icellmobilsoft.coffee.grpc.api.metadata; | ||
|
||
import io.grpc.Metadata; | ||
import io.grpc.Metadata.Key; | ||
|
||
/** | ||
* Grpc Header metadata constants | ||
* | ||
* @author Imre Scheffer | ||
* @since 2.7.0 | ||
*/ | ||
public interface IGrpcHeader { | ||
|
||
/** | ||
* Language Metadata header key | ||
*/ | ||
Metadata.Key<String> HEADER_LANGUAGE = Key.of("X-LANGUAGE", Metadata.ASCII_STRING_MARSHALLER); | ||
|
||
/** | ||
* Logging, global transaction session id header key | ||
*/ | ||
Metadata.Key<String> HEADER_SID = Metadata.Key.of("X-SID", Metadata.ASCII_STRING_MARSHALLER); | ||
|
||
} |
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
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
68 changes: 68 additions & 0 deletions
68
...main/java/hu/icellmobilsoft/coffee/grpc/server/mapper/DefaultGrpcExceptionTranslator.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,68 @@ | ||
/*- | ||
* #%L | ||
* Coffee | ||
* %% | ||
* Copyright (C) 2020 - 2024 i-Cell Mobilsoft Zrt. | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
package hu.icellmobilsoft.coffee.grpc.server.mapper; | ||
|
||
import java.io.Serializable; | ||
import java.util.Locale; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import com.google.rpc.LocalizedMessage; | ||
import com.google.rpc.LocalizedMessage.Builder; | ||
|
||
/** | ||
* Default implementation for translating exceptions to status. | ||
* | ||
* @author Imre Scheffer | ||
* @since 2.7.0 | ||
*/ | ||
@ApplicationScoped | ||
public class DefaultGrpcExceptionTranslator implements IGrpcExceptionTranslator { | ||
|
||
/** | ||
* Default Locale for Grpc message translation | ||
*/ | ||
public static final Locale DEFAULT_LOCALE = Locale.ENGLISH; | ||
|
||
@Inject | ||
private hu.icellmobilsoft.coffee.module.localization.LocalizedMessage localizedMessage; | ||
|
||
/** | ||
* Default constructor, constructs a new object. | ||
*/ | ||
public DefaultGrpcExceptionTranslator() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public Builder toLocalizedMessage(Locale locale, Enum<?> faultType, Serializable... messageArguments) { | ||
LocalizedMessage.Builder lmBuilder = LocalizedMessage.newBuilder(); | ||
if (faultType != null) { | ||
Locale returnLocale = locale == null ? DEFAULT_LOCALE : locale; | ||
// localizedMessage.message(faultType, messageArguments) jelenleg nem megfelelo, | ||
// mert REST headerbol olvassa a nyelvesito kulcsot es itt most nincs request scope sem | ||
String translatedMessage = localizedMessage.messageByLanguage(returnLocale.getLanguage(), | ||
"{" + faultType.getClass().getName() + "." + faultType.name() + "}", messageArguments); | ||
lmBuilder.setLocale(returnLocale.toString()).setMessage(translatedMessage); | ||
} | ||
return lmBuilder; | ||
} | ||
} |
Oops, something went wrong.