I want to read the error messages from messages file but I am unable to. What mistake am I making?
The code where I want to read the string from messages file is
Future { Ok(Json.toJson(JsonResultError(messagesApi("error.incorrectBodyType")(langs.availables(0))))) }
The messages file error.incorrectBodyType=Incorrect body type. Body type must be JSON
The messagesApi("error.incorrectBodyType") should return Incorrect body type. Body type must be JSON but it returns error.incorrectBodyType.
If I remove double quotes in messagesApi(error.incorrectBodyType) then the code doesn't compile
Update
I added a couple of debug prints and notice that the keys I am using in MessagesApi are not defined. I don't know why though as I have created them in messages file.
println("langs array"+langs.availables)
println("app.title"+messagesApi.isDefinedAt("app.title")(langs.availables(0)))
println("error"+messagesApi.isDefinedAt("error.incorrectBodyType")(langs.availables(0)))
prints
langs arrayList(Lang(en_GB))
app.titlefalse
errorfalse
Update 2
I might have found the issue but I don't know how to resolve it. Basically, I am running my test case without an instance of the Application. I am mocking messagesApi by calling stubMessagesApi() defined in Helpers.stubControllerComponents, If I run the same code using an Application eg class UserControllerFunctionalSpec extends PlaySpec with OneAppPerSuiteWithComponents then app.title and error are defined. It seems without an instance of Application, MessagesApi is not using the messages file.
I was able to solve the issue by creating a new instance of MessagesApi using DefaultMessagesApi
val messagesApi = new DefaultMessagesApi( //takes map of maps. the first is the language file, the 2nd is the map between message title and description
Map("en" -> //the language file
Map("error.incorrectBodyType" -> "Incorrect body type. Body type must be JSON") //map between message title and description
)
)
val controller = new UserController(mockUserRepository,mockControllerComponents,mockSilhouette,messagesApi,stubLangs())
Related
What is the proper/recommended method to pass data between the callbacks in a C module in FreeRADIUS?
For example, I want to create a unique request_id for the request and use it for all log entries during that request. If I create this value inside mod_authorize, how do I pass it over to mod_authenticate on the same request thread, and how do I retrieve it?
static rlm_rcode_t CC_HINT(nonnull) mod_authorize(void *instance, REQUEST *request)
{
// Generate uuid
uuid_t uuid;
uuid_generate_random(uuid);
// Convert to a string representation
char *request_id = talloc_array(mem_ctx, char, UUID_STR_LEN);
uuid_unparse(uuid, request_id);
// Do stuff and log authorize messages
radlog(L_INFO, "request_id inside mod_authorize: %s", request_id);
// How do I pass request_id to mod_authenticate callback
// ?????????????
return RLM_MODULE_OK;
}
static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(void *instance, REQUEST *request)
{
char *request_id = NULL;
// How do I retrieve the request_id value
// ???????????????????
// Do stuff and log authenticate messages
radlog(L_INFO, "request_id inside mod_authenticate: %s", request_id);
return RLM_MODULE_OK;
}
Attaching the value to the request object seems like a logical thing, but I don't see a way of doing it, other than adding a value pair to the request->reply (and I don't want to return this value to NAS).
Thank you.
Apparently, there is a range of "Temporary attributes, for local storage" (defined in the dictionary.freeradius.internal file) that can be used with one of the requests object's collections (request->config, request->reply->vps and request->packet->vps). You can find the start of this range by searching dictionary.freeradius.internal file in the FreeRADIUS repository for
ATTRIBUTE Tmp-String-0
In this case I found request->packet->vps to be appropriate, and used Tmp-String-3 to add my request_id to it while inside MOD_AUTHORIZE callback:
pair_make_request("Tmp-String-3", request_ctx->request_id, T_OP_EQ);
where pair_make_request is a macro defined as
fr_pair_make(request->packet, &request->packet->vps, _a, _b, _c)
I then retrieved it, while inside MOD_AUTHENTICATE callback:
VALUE_PAIR *vp = fr_pair_find_by_num(request->packet->vps, PW_TMP_STRING_3, 0, TAG_ANY);
The numerical values of these attributes change between the versions, you must use macro definitions instead
The macros for these attributes, such as PW_TMP_STRING_3 in the esample above, are located in the file "attributes.h" which is auto-generated during the build. Here is a quote from Arran Cudbard-Bell, that I found here:
If you really want to know where each one is used, download,
configure, build the source. Then see src/include/attributes.h for the
macro versions, and grep -r through the code. That'll at least tell
you the modules, and if you're familiar with C you should be able to
figure out how/when they're added or checked for. – Arran Cudbard-Bell
Apr 12 '15 at 20:51
In my case, the resulting file is located at /usr/include/freeradius/attributes.h
I must say that it took me unreasonable amount of effort to track this information down. There is no other trace, none whatsoever, of these attribute macros. Not in the code, not in the FreeRADIUS documentation, not in Google search results.
I have tried to use #BindUsing for a property (amt100) of a domain class (TcTransaction). The purpose is to convert a display format to a database format. Out of a dozen variants, here is one:
#BindUsing({tcTransaction, source ->
def result = tcTransaction.amt100
def amt = Amount100.of(source['amt100']) //parse and convert input
if (amt) {
result = amt.cents
} else {
tcTransaction.errors.rejectValue('amt100', 'tcTransaction.invalid.amount')
}
return result
})
Integer amt100
It works beautifully in the absence of errors. The problem is error management. This particular version returns the original value if the new value is invalid. It also adds an error to the domain object.
It seems adding to errors has no effect. The user is not warned.
I also tried to throw an exception. It seems whatever exception you throw you end up with a standard error code saying that the property must not be left empty. A previous post indicated this behaviour. (It has gone unanswered for two years.) I'm on Grails 3.2.8.
So, is there any theory of error management in #BindUsing? It's such a nifty mechanism.
I'm just trying to use android-annotation. When I start another Activity, an empty activity showed up.
I check this to find that the #EActivity generate the subclass of XXActivity named XXActivity_. So I try to code
mIntent = new Intent(this, XXActivity_.class);
But eclipse shows error that XXActivity_ cannot be resolved to a type. I don't know when the XX_ is generated.
I have add the jar, declare the XX_ in the AndroidManifest.xml. How to make eclipse generate the XX_ class?
you could start activity using annotations like this
first you should write your activities on the manifest file with '_' after that you have two activities you want to go from one to another you could use this :
CarDetailActivity_.intent(CarSaleListActivity.this).start();
with this you will go the CarDetailActivity on the other hand if you want to pass message to the other activity you will use this
CarDetailActivity_.intent(CarSaleListActivity.this).myMessage("arrived with android annotations").start();
and in this case you should define this on the CarDetailActivity
#Extra
String myMessage;
and you could use this message on CarDetailActivity like this on
#AfterViews
public void showMessage(){
Toast.makeText(this,myMessage,Toast.LENGTH_SHORT).show();
}
Note : CarDetailActivity should be #EActivity to make this work
Blockquote
In Darts API, the method
element.setCustomValidity(num message)
has a number as the argument. I was expecting the type of the message to be a String. Is this an error?
I created an issue https://github.com/Polymer/core-input/issues/41
The Dart element uses information from JS comments to generate type annotations and the comment in the JavaScript element contains the wrong type information.
As a workaround you can call the JS function directly:
void setCustomValidity(CoreInput inp, String message) {
inp.jsElement.callMethod('setCustomValidity', ["Give me more!"]);
}
see also Taking total control of PaperInput validation
I am learning how to use nHapi. As many have pointed out, there's not much documentation. Following this doc I've been able to parse a message using the library. But I can't figure out how to access that message using an object model (which is what I really want nHapi to do). Essentially, I want to take an HL7 message as a string and access it using the object model, in the same way that LINQ to SQL takes a database record and lets you access it as an object. I found Parsing an HL7 without a priori messageType knowledge, but it seems to be about something else because the code in the post returns a string instead of an HL7 object (like I need). In the documentation I linked to above they seem to access the parts of a message using a "query"--but I can't find the materials to query IMessages in the library.
Here is the code I'm using, with a line showing what I want to do...
Imports NHapi.Base
Imports NHapi.Base.Parser
Imports NHapi.Base.Model
Module Module1
Sub Main()
Dim msg As String = "MSH|^~\&|SENDING|SENDER|RECV|INST|20060228155525||QRY^R02^QRY_R02|1|P|2.3|QRD|20060228155525|R|I||||10^RD&Records&0126|38923^^^^^^^^&INST|||"
Dim myPipeParser As PipeParser = New PipeParser()
Dim myImsg As IMessage = myPipeParser.Parse(msg)
Dim msgType As String = myImsg.GetStructureName
Dim mySendingFacilityName As String = myImsg.getSendingFacility() //this is what I want
End Sub
Remember with HL7 messages that each segment has to end with a line return.
Also, you'll want to parse the message back to its actual type in order for the object model to be fully populated correctly (notice that when I used myPipeParser.Parse it was cast back to a QRY_R02 message type from the NHapi.Model.V23 Library). So the code should look something like this:
Imports NHapi.Model.V23.Message
Imports NHapi.Base.Parser
Imports NHapi.Base
Module Module1
Sub Main()
Dim msg As String = "MSH|^~\&|SENDING|SENDER|RECV|INST|20060228155525||QRY^R02^QRY_R02|1|P|2.3" & vbNewLine & _
"QRD|20060228155525|R|I||||10^RD&Records&0126|38923^^^^^^^^&INST|||"
Dim myPipeParser As PipeParser = New PipeParser()
Dim myImsg As QRY_R02 = myPipeParser.Parse(msg)
Dim msgType As String = myImsg.GetStructureName
Dim mySendingFacilityName As String = myImsg.MSH.SendingFacility.NamespaceID.Value
Console.WriteLine(mySendingFacilityName)
Console.ReadLine()
End Sub
End Module
I know it was a very long time ago, however I was looking for this resource very recently and found that there is nearly no documentation on how to use this API. And excellent source of examples can be found in the test part of source code in the project NHapi.NUnit.
Sources can be found here