how to retreive the value of a custom header into a WSF_REQUEST - eiffel

I'm looking how to get a custom header value from a received WSF_REQUEST. I read the docs quickly and didn't find the answer.
'Authorization': 'Bearer my_long_token'

Use http_authorization from the WSF_REQUEST interface.
(all the request header values are available using the CGI convention, mostly prefixing with HTTP_ , all in uppercase, and using _ as separator.

My complete solution was
last_request: detachable WSF_REQUEST
find_it
do
if attached header_item ("HTTP_AUTHORIZATION") as l_bearer then
do_something (l_bearer)
end
end
meta_variable, header_item (a_key: STRING): detachable STRING
require
attached last_request -- {WSF_REQUEST}
do
check
attached last_request as l_last_request
then
across
l_last_request.meta_variables as l_item_cursor
until
attached Result
loop
--logger.write_debug ("header_item->key:" + l_item_cursor.item.name + " val:" + l_item_cursor.item.value)
if l_item_cursor.item.name.is_equal (a_key) then
Result := l_item_cursor.item.value
end
end
end
end

Related

Gatling .sign issue

I am trying to build a Get request as follows and I would like CaseReference value to be populated via feeder .feed(CaseProviderSeq) but for some reason it's not picking CaseReference value and printing following for my println statement in .sign statement bellow
PATH KJ: /caseworkers/554355/jurisdictions/EMPLOYMENT/case-types/Manchester_Multiples/cases/$%7BCaseReference%7D/event-triggers/updateBulkAction_v2/token
My feeder CSV got following rows currently
1574761472170530
1574622770056940
so I am expecting this amended URL would be like
/caseworkers/554355/jurisdictions/EMPLOYMENT/case-types/Manchester_Multiples/cases/1574761472170530/event-triggers/updateBulkAction_v2/token
any idea what wrong I am doing here ??
.get(session => SaveEventUrl.replace(":case_reference","${CaseReference}").replaceAll("events", "") + s"event-triggers/${EventId}/token")
.header("ServiceAuthorization", s2sToken)
.header("Authorization", userToken)
.header("Content-Type","application/json")
.sign(new SignatureCalculator {
override def sign(request: Request): Unit = {
val path = request.getUri.getPath
println("PATH KJ: " + path)
request.getHeaders.add("uri", path)
}
})
This is not related to .sign, but your session attribute CaseReference not being interpreted. If you look closely you can see the braces %-encoded in $%7BCaseReference%7D.
Interpretation of the Gatling Expression Language strings happens only when a String is present when an Expression[Something] is needed1.
This bug you wrote is shown exactly in the warning in the documentation above.
I believe you can simply remove session => in your .get, so you are passing in a String rather than a Session => String2. That string will be implicitly converted to Expression[String]. That way Gatling will put the session attribute into the URL.
This happens because of the Scala implicit conversion.
In fact it is Session => Validation[String], because, again, of implicit conversions.

How to set a context variable with dot in name?

I am trying to add a context data variable (CDV), which has a dot in its name. According to Adobe site this is correct:
s.contextData['myco.rsid'] = 'value'
Unfortunately, after calling s.t() the variable is split into two or more:
Context Variables
myco.:
rsid: value
.myco:
How can I set the variable and prevent splitting it into pieces?
You are setting it properly already. If you are referring to what you see in the request URL, that's how the Adobe library sends it. In your example, "myco" is a namespace, and "rsid" is a variable in that namespace. And you can have other variables in that namespace. For example if you have
s.contextData['myco.rsid1'] = 'value';
s.contextData['myco.rsid2'] = 'value';
You would see in the AA request URL (just showing the relevant part):
c.&myco.&rsid1=value&rsid2=value&.myco&.c
I assume you are asking because you want to more easily parse/qa AA collection request URLs from the browser network tab, extension, or some unit tester? There is no way to force AA to not behave like this when using dot syntax (namespaces) in your variables.
But, there isn't anything particularly special about using namespaces for your contextData variables; it's just there for your own organization if you choose. So if you want all variables to be "top level" and show full names in the request URL, then do not use dot syntax.
If you want to still have some measure of organization/hierarchy, I suggest you instead use an underscore _ :
s.contextData['myco_rsid1'] = 'value';
s.contextData['myco_rsid2'] = 'value';
Which will give you:
c.&myco_rsid1=value&myco_rsid2=value&.c
Side Note: You cannot do full object/dot notation syntax with s.contextData, e.g.
s.contextData = {
foo:'bar', // <--- this will properly parse
myco:{ // this will not properly parse
rsid:'value' //
} //
};
AA library does not parse this correctly; it just loops through top level properties of contextData when building the request URL. So if you do full object syntax like above, you will end up with:
c.&foo=bar&myco=%5Bobject%20Object%5D&&.c
foo would be okay, but you end up with just myco with "[object Object]" as the recorded value. Why Adobe didn't allow for full object syntax and just JSON.stringify(s.contextData) ? ¯\_(ツ)_/¯

Safest way to handle null database items in VB.net

For an object such as a DataGridView item or a data set item is the .tostring method safe to use against possible DBnull's?
The application is a mysqlconnector fed DB application which pretty much uses standard query's, but I do come across DBNull quite a bit. Keeping coding efficiency in mind, is the following safe?
Module DataCheck
Public Function SafeDataSTR(DBItem As Object) As String
If Not (IsDBNull(DBItem)) Or Not (IsNothing(DBItem)) Then
Return DBItem.ToString
Else
Return ""
End If
End Function
End Module
'Elsewhere in the galaxy....'
With tempDS.Rows.Item(0) 'tempDS is a standard dataset'
Textbox1.Text = SafeDataSTR(.Item("SupplierDetails")) 'Not necessarily a text box, just an example'
The original solution was:
If Not IsDBNull(.Item("JobDescription")) Then _
jobinfo.Job_Description = .Item("JobDescription")
Which has worked in the past but is there a better safer way to protect yourself from these?
EDIT: Sorry, would DataRow.item("Column").tostring be just as safe?
EDIT: Final Version:
Public Function SafeData_Rowfeed(row As DataRow, ItemName As String) As String
Try
If Not (IsDBNull(row.Item(ItemName))) Then
Return row.Item(ItemName).ToString
ElseIf IsNothing(ItemName) Then
Throw New IndexOutOfRangeException("Supplied Column " & ItemName & "Not found or is Nothing")
Else
Return ""
End If
Catch ex As System.ArgumentException
Console.WriteLine(ex.Message)
Return "Column Does Not Exist"
End Try
End Function
You could 'simplify' it a bit to
Public Function SafeDataSTR(DBItem As Object) As String
Return If(IsDBNull(DBItem), "", If(DBItem.ToString, ""))
End Function
If(DBItem.ToString, "") checks if DBItem.ToString is Nothing.
https://msdn.microsoft.com/en-us/library/bb513985.aspx
Your use of it makes it not the safest method, because the item "SupplierDetails" might not exist.
would DataRow.item("Column").tostring
No it wouldn't as if DataRow.item("Column") is null then calling ToString will cause a null reference exception.
What you have is the safest way of doing this.
In C# 6 and VB 14 there's the ?. syntax, but that basically compiles to the same thing you have, though it will take up one less line of code:
stringValue = DataRow.item("Column")?.ToString
Though this will always set stringValue, so if you want it to retain its current value when the column is null your existing code is still the best way to do this.

extracting multiple values from a string VB.NET

I am dealing with http URLs, all the URLs are correct but some are like:
http://site.com/abgAz1nBs.jpg%20http://site.com/adtEh96Wj.jpg%20http://site.com/acum1N6qN.jpg
so basically these are 3 URLS. I need them to be separated. But it is not the only problem, I need to use "IF" statement to confirm that there is a string that contains multiple "http://" because other URLs are correct
Try this:
Dim strURLToEvaluate As String = "http://site.com/abgAz1nBs.jpg%20http://site.com/adtEh96Wj.jpg%20http://site.com/acum1N6qN.jpg"
Dim strURLs As String() = Strings.Split(strURLToEvaluate, "%20http://")
If strURLs.Length > 1 Then MsgBox("More than one URL!")
For Each strURL In strURLs
If Strings.Left(strURL, Len("http://")) <> "http://" Then strURL = "http://" & strURL
MsgBox(strURL)
Next strURL
You can use the following algorithm:
Check if the string contains "%20http" (using String.Contains).
If yes, split at "%20http" (using String.Split).
Add "http" at each of the split strings except the first one (using normal string concatenation).
Implementing these steps should be easy and will be (deliberately) left as an exercise to the reader. In fact, after you have implemented them correctly, you might realize that you can skip the first step altogether.

MS Access - open a form taking a field value from a previous form

I have a form in an MS Access database which lists all the landowners consulted with for a new electricity line. At the end of each row is a button which opens another form, showing the details of all consultation, offers made etc.
I am trying to use vb in MS Access to take the contactID and automatically put it in a field in the details form, so that landowner's consultation details will pop up automatically. I am not a vb programmer at all (I have a comp sci degree mostly in Java and I'm currently working as a GIS analyst but it's a small company so I've been asked to get an Access database working).
I want to say
[detailsForm]![contactID] = [landownerlist]![ID]
in a way that vb and access will be happy with. Then I can see if I'm on the right track and if it will actually work! What I have above does not actually work. It won't compile.
From Kaliana
If you wish to open a form to a new record and to set the ID there, you can use Openargs, an argument of Openform:
DoCmd.OpenForm "FormName",,,,acFormAdd,,Me.ID
The opened form would also need some code:
If Me.Openargs<>vbNullstring Then
Me.Id = Me.Openargs
End If
It is also possible to find:
Forms!LandownersList.Recordset.FindFirst "ID=" & Me.ID
or fill in a value:
Forms!LandownersList!Id = Me.ID
on the form being opened from the calling form.
You may want to look into the code that is behind these buttons. If you are using a docmd.openform you can set the 4th Setting to a where clause on openning the next form.
DoCmd.OpenForm "OpenFormName", acNormal, , "[contactID] = " _
& [detailsForm]![contactID] , acFormEdit, acWindowNormal
This assumes contact ID is numeric and doesn't require any quotes.
Using open args is the generally accepted solution, as alluded to by others. This just falls under the category of "For you edification":) One of the problems with using open args is that unless you are careful with your comments it's easy to forget what they were supposed to mean. Were you passing more than one? Which is which? How did I do it here? How did I do it there etc. For my own money, I standardized to this (below) so I can always pass more than one argument without fear, and when I review my code a year from now, I can still see what's what without a huge hassle:
Option Explicit
'Example use: DoCmd.OpenForm "Example", OpenArgs:="Some Filter|True"
Public Enum eForm1Args
eFilter = 0
eIsSpecial = 1
End Enum
Private m_strArgs() As String
Public Property Get Args(ByVal eForm1Args As eForm1Args) As String
Args = m_strArgs(eForm1Args)
End Property
Private Sub Form_Open(Cancel As Integer)
m_strArgs = Split(Nz(Me.OpenArgs, vbNullString), "|")
If LenB(Me.Args(eFilter)) Then Me.Filter = Me.Args(eFilter)
End Sub
Private Sub Command1_Click()
If LCase$(Me.Args(eIsSpecial)) = "true" Then
'Do something special
End If
End Sub
As previously posted OpenArgs is great for this. One trick I have learned is that it is easy to pass in multiple parameters if required as a delimited string (comma for example), the target form can then access these values using the Split() function thus:
StringArrayVariable()= Split(me.OpenArgs,",")
Me.textbox= StringArrayVariable(0)
Me.textbox1= StringArrayVariable(1)
etc.
This is air code so check out the helpfile for Split().
It is also possible to pass objects in OpenArgs as well, it requires some manual memory pointer manipulation and I don't have the code to hand but I'm sure a Google search will find some examples. This technique can cause some random crashes though. Be Warned!

Resources