How to troubleshoot issues related to requests and responses from ws loaded in SM - microfocus

I am working on an integration between Microfocus Service Manager and Remedy. In order to troubleshoot issues related to requests and responses from SM to Remedy is needed to print or send that information to a log. I have tried using a debug -RTM:3 flag in my testing port configuration, but unfortunately there is a lot of information in my log since it writes every step performed by the tool. After that, I set the -debughttp flag in my port, but it only writes inputs/outputs from external resources.
Here is what I have done:
Load Remedy customer's endpoint with WSDL2JS utility.
Invoke the endpoint with a SL.
Perform a request to the endpoint.
Get an undefined response.
Check logs written by -RTM and -debughttp without success.
Is there any way to check what’s happening with my requests or with my customer’s reponses?

You can get the content of your requests and responses using the sl created by WSDL2JS only adding a piece of code within it.
For your requests, look for this part of the code (about line 129):
this.resultXML = doSOAPRequest( this.location, soapOp.SOAPAction, result.xml,
this.user, this.password,
this.connectTimeOut, this.sendTimeOut, this.recvTimeOut,
this.attachments, this.acceptfastinfoset );
Add the following code below:
//Print your request
print(result.xml)
//Send your xml request to a internal log called integration_debug.log in your app server
writeFile("../logs/integration_debug.log","a","\n");
writeFile("../logs/integration_debug.log","a","######### REQUEST INFO XML######\n");
writeFile("../logs/integration_debug.log","a",system.functions.tod()
+ "\n"
+ result.xml
+ "\n"
+ "\n");
For your customer’s responses, look for this part of the code:
if ( soapOp.responseObj == "null" ) // one-way MEP ?
{
return null;
}
var resultObj = new Object();
resultObj.responseObj = soapOp.responseObj;
Add the following code below:
//Print your customer response
print(this.resultXML.getDocumentElement())
//Send your xml response to a internal log called integration_debug.log in your app server
writeFile("../logs/integration_debug.log","a","\n");
writeFile("../logs/integration_debug.log","a","######### RESPONSE INFO XML#######\n");
writeFile("../logs/integration_debug.log","a",system.functions.tod()
+ "\n"
+ this.resultXML.getDocumentElement()
+ "\n"
+ "\n");
As a reference you can check the following picture to identify where inserting your code:
Hopefully, that can be helpful for your troubleshooting.

Related

Google Sheet API batchUpdateByDataFilter PHP Function

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchUpdateByDataFilter
We have used above function in our code, while we are passing the more than 50 or 100 records within the array records then given 400 bad request array in response.
Can anyone describe the limit of the total values that we are going to pass within the above function?
Here is my code:
$batchupdate = array("valueInputOption" => "RAW", "data" => $dataarray);
try {
$requestBody = new Google_Service_Sheets_BatchUpdateValuesByDataFilterRequest($batchupdate);
$response = $service->spreadsheets_values->BatchUpdateByDataFilter($spreadsheetId, $requestBody);
}
catch(Exception $e) {
echo 'Message: ' . $e->getMessage();
}
Troubleshooting:
Problems with the Request
Until you attach a sanitized version of your Request body we cannot be sure about the root-cause of the problem you are facing.
However, an error 400 means that the request you did is invalid. So, most likely, the problem is in that.
Check if your request object is formatted as detailed on the documentation.
Problems with the Client
If you are able to use the Try this API sidebar with the same Request Body then it could be related to the PHP client.
Note: This is language independent. Create a JSON Object that has the same structure as your request body.
If that's the case, we will need to see more of your code to verify that you are not using your valid Request body in an invalid way (eg. sending it encapsulated in another object).
By referencing the PHP Library documentation you can see the properties of the objects you can use.

Login to yammer through axapta

I have an assignment to develop a functionality for the Microsoft Dynamics AX (2012) i.e. in the SalesTable form I need to open a browser with automatically authentication to Yammer.
By analyzing the http webRequests (with Fiddler tool ) I have discovered that for this purpose there several web request are sending (with specific parameters and cookies) in certain sequence, such as:
1. https://www.yammer.com/oauth2/authorize?client_id=VALUE&redirect_uri=https://www.yammer.com
2. https://www.yammer.com/dialog/authenticate?client_id=VALUE
3. https://www.yammer.com/images/public-site-spacer.gif
4. https://persona.yammer.com/login_provider.json?email=VALUE&state=VALUE
5. https://login.microsoftonline.com/common/oauth2/authorize?client_id=VALUE&domain_hint=VALUE&login_hint=&nonce=2VALUE&redirect_uri=VALUE&response_mode=query&response_type=id_token&scope=open_id&site_id=VALUE&state=VALUE
6. https://login.microsoftonline.com/common/userrealm/?user=VALUE&api-version=VALUE&stsRequest=VALUE&checkForMicrosoftAccount=VALUE
7. https://login.microsoftonline.com/common/login
All these request I sending programmatically and can catch the web Response object from such web request, except request #7. With Fiddler tool I can see than additional request has been send automatically to the:
1. https://persona.yammer.com/office_sessions?id_token=VALUE&state=&session_state=VALUE
and to the URI above just after #8
2. https://www.yammer.com/?persona_token=VALUE&state=
When I try to create requests #8 and #9 programmatically (let’s say #8My and #9My) I have an error.
My final goal is to get some mandatory parameters such as: ("browser_token", "oauth_token" and "code") from the webResponses on the #8 and #9 requests.
Can you please help me to define how to get them? Maybe I should skip some request listed above or add some additional requests (which one?)?
Thank you
Commented as of 16.06.2016
I will try to localize the problem (because there are quite a lot of gaps and for the sake of clarity I will ask questions one by one), thank you for understanding.
Below there is a screenshot of my requests
enter image description here
On the step #7 I’m sending the following request:
GET https://persona.yammer.com/login_provider.json?email=myEmail#myDomain.com&state=41a563bc24e263ed5b35fbe63e7c5c556a0477024d88b28fb012ed6de48b1d39 HTTP/1.1
Host: persona.yammer.com
Cookie: yamtrak_id=2b9ea0d1-55c4-4368-b893-d9b7e3b1da32
Fiddler shows me, that in response of this request (#7), there is parameter “_session_id=” (value is showed below and in red rectangular on the screenshot)
_session_id=Zlk2YjlkcFZPdTZlOHAwVHl4L0lodC85K1VvaUFkbWxNZU5LZzNLcWR6SU1JWEI4c0l1aFpjMmhGNlllcEFVQ1VtNVN6R1lwTGxoZFNIYW5zb3pKSlE9PS0tdWxIVXEzR3JIN0RQcUsvU2svOVY4QT09--6fc208ae3d6d939e3e2e7eecfffd1d23d3051f39;
This parameter (_session_id) will be used in request #12.
But when I grab (programmatically) the cookies in response of the request #7, the value of this parameter is absolutely different from mentioned above (and the name of the parameter is “_session=” (instead of “_session_id=”).
_session=BAh7CUkiD3Nlc3Npb25faWQGOgZFRkkiJTU0OGYyOTQ0YTAxNzYyNjUzZmJlMGI2ZmZjOTU3ZWI4BjsAVEkiC21vYmlsZQY7AEZGSSIQX2NzcmZfdG9rZW4GOwBGSSIxTlZRZkFJRTZHeHdJWUtxcUtVNHEzWXNKeDZ2Z2FiQUZ6NXJIalM0Nk0zTT0GOwBGSSIKZmxhc2gGOwBGbzolQWN0aW9uRGlzcGF0Y2g6OkZsYXNoOjpGbGFzaEhhc2gJOgxAY2xvc2VkRjoNQGZsYXNoZXN7CToKZXJyb3IwOgl0cmZlMDoLbm90aWNlMDoJdHJmbjA6CUBub3cwOgpAdXNlZG86CFNldAY6CkBoYXNoewk7CVQ7ClQ7C1Q7DFQ%3D--ea5007eba2efabc2627f2e5af66c4c57f22d53bb
Here is the code of how I’m getting the Cookies string from the HttpWebResponse
public string getStringCookies(System.Net.HttpWebResponse _response)
{
string cookies = string.Empty;
try
{
cookies = _response.Headers["Set-Cookie"];
}
catch (Exception ex)
{
Console.WriteLine("Error in SetCookies: " + ex.Message);
}
return cookies;
}
So the question is: what should I do in order to catch the _session_id parameter in the response of the request #7?

XmlHttpRequest not reporting server side progress

I have a client server application. The server side is completely in java. The client side has a few lines of html and the rest in plain javascript (I don't use ajax or jquery etc).
The client receives user inputs through an input box and when the user clicks a button, the client sends a POST request to the server using XmlHtpRequest. The server then runs a process that can take several minutes. The server periodically (every 5 seconds) sends a progress update message with HTTP status code 202 and with content "Processing.... completed 5 / 100". The numbers 5 and 100 are a sample. Instead of 100, it is the actual final counter of the process and instead of 5 it is the current counter indicating the progress. When the server finishes the processing it sends a 200 OK with the final output as the content. I have an output text area where I want to display the progress message during the processing and later the final output is also placed in the same output text area.
My client side javascript code is:
<script>
var xhr = new XmlHttpRequest();
function sendCommandToServer() {
window.xhr.onreadystatechange = getServerResponse;
window.xhr.open("POST", (document.domain + "/" + "executeCommand"), true);
window.xhr.send("arguments and data for the command");
}
</script>
<script>
function getServerResponse() {
if(window.xhr.status === 202) {
myTextArea.value = window.xhr.responseText;
window.xhr.onreadystatechange = getServerResponse;
return;
}
if(window.xhr.status === 200) {
myTextArea.value = window.xhr.responseText;
return;
}
alert("processing error");
}
</script>
The server correctly gets the command and runs the process and finishes and produces the output. It also correctly sends the progress messages. But my client side javascript does not get all of them. I am able to get the 1st progress message from the server - something like - "Processing .... 5 / 100" - but after that I am not able to get further calls to getServerResponse() to continue updating the progress as and when the server sends messages. If I modify the server side to avoid sending progress and send only the final output result, it works correctly and I get the final output result displayed at the client. I run this on IE10 and Chrome, with the same behavior. Can xmlHttpRequest() be used for this use-case? Am I doing something wrong? Any help will be appreciated. Thanks.
I'm new to this myself and trying to work out a method of achieving something similar.
I think the 202 status code is the only response you will get, ie the server will send a single response when it has accepted the job (202), or a 200 response when it has completed.
Source:
http://100pulse.com/http-statuscode/202.jsp

Problems Connecting to MtGox API 2 with Python

I am writing a trading program that I need to connect to MtGox (a bitcoin exchange) through the API v2. But I keep getting the following error:
URL: 1 https://data.mtgox.com/api/2/BTCUSD/money/bitcoin/address
HTTP Error 403: Forbidden.
Most of my script is a direct copy from here (that is a pastebin link). I just had to change it to work with Python 3.3.
I suspect that it has to do with the part of script where I use base64.b64encode. In my code, I have to encode my strings to utf-8 to use base64.b64encode:
url = self.__url_parts + '2/' + path
api2postdatatohash = (path + chr(0) + post_data).encode('utf-8') #new way to hash for API 2, includes path + NUL
ahmac = base64.b64encode(str(hmac.new(base64.b64decode(self.secret),api2postdatatohash,hashlib.sha512).digest()).encode('utf-8'))
# Create header for auth-requiring operations
header = {
"User-Agent": 'Arbitrater',
"Rest-Key": self.key,
"Rest-Sign": ahmac
}
However, with the other guy's script, he doesn't have too:
url = self.__url_parts + '2/' + path
api2postdatatohash = path + chr(0) + post_data #new way to hash for API 2, includes path + NUL
ahmac = base64.b64encode(str(hmac.new(base64.b64decode(self.secret),api2postdatatohash,hashlib.sha512).digest()))
# Create header for auth-requiring operations
header = {
"User-Agent": 'genBTC-bot',
"Rest-Key": self.key,
"Rest-Sign": ahmac
}
I'm wondering if that extra encoding is causing my header credentials to be incorrect. I think this is another Python 2 v. Python 3 problem. I don't know how the other guy got away without changing to utf-8, because the script won't run if you try to pass a string to b64encode or hmac. Do you guys see any problems with what I am doing? Is out code equivalent?
This line specifically seems to be the problem -
ahmac = base64.b64encode(str(hmac.new(base64.b64decode(self.secret),api2postdatatohash,hashlib.sha512).digest()).encode('utf-8'))
To clarify, hmac.new() creates an object to which you then call digest(). Digest returns a bytes object such as
b.digest()
b'\x92b\x129\xdf\t\xbaPPZ\x00.\x96\xf8%\xaa'
Now, when you call str on this, it turns to
b'\\x92b\\x129\\xdf\\t\\xbaPPZ\\x00.\\x96\\xf8%\\xaa'
So, see what happens there? The byte indicator is now part of the string itself, which you then call encode() on.
str(b.digest()).encode("utf-8")
b"b'\\x92b\\x129\\xdf\\t\\xbaPPZ\\x00.\\x96\\xf8%\\xaa'"
To fix this, as turning bytes into a string back into bytes was unnecessary anyhow(besides problematic), I believe this will work -
ahmac = base64.b64encode(hmac.new(base64.b64decode(self.secret),api2postdatatohash,hashlib.sha512).digest())
I believe you are likely to find help in a related question of mine although it deals with the WebSocket API:
Authenticated call to MtGox WebSocket API in Python 3
Also, the HTTP 403 error seems to indicate that there is something fundamentally wrong with the request. Even if you threw the wrong authentication info at the API you should have gotten an error message as a response and not a 403. My best guess is that you are using the wrong HTTP method so check if you are using the appropriate one (GET/POST).

Accessing the HTTP headers from a WCF Service

I need to access the HTTP response headers that are to be returned to the client from a WCF Service. Accessing the HTTPContext is easy(through HttpContext.Current.Response), but what is the event/extension/behavior that is executed lastly, when the StatusCode is already set (for ex. if the status is 500)?
EDIT: Message Inspectors don't seem to be a good solution here, because at the time they run, the status code isn't set yet. (At least in my trial that was the case)
You can access all headers on WebOperationContext.Current.IncomingRequest, like this:
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
Console.WriteLine("-------------------------------------------------------");
foreach (string headerName in headers.AllKeys)
{
Console.WriteLine(headerName + ": " + headers[headerName]);
}
Console.WriteLine("-------------------------------------------------------");
See here
Simplest way for having control on the Headers is to use Message contracts.
Use Message Inspectors to monitor the message right after receiving it at the Service end.
In an extreme case, where you are not satisfied with any other standard routes, you can go for POX (Plain Old XML) type operations where you would be dealing with raw XML message.