Cisco Unified Routing Rules XML Interface

« Back to Routing Rules API Questions

RE: can't make the samplePolicyApp.py work

Combination View Flat View Tree View
Threads [ Previous | Next ]
Hi all,
I tried to run the samplePolicyApp.py, only changing the numbers in the divert response string and in the if construct to match the routing rules with my environment (and of course setting an appropriate translation pattern).
I ran the script on the 8080 port, with http protocol. Everything seems ok, but the call diversion didn't happen.
 
I used wireshark to monitor the http request-response exchange between the UCM and my server, everything looks right.
Why doesn't it work? Is maybe because I need to set some kind of parameter on the UCM, like something about security that rejects the http response? Is there some error in the xml response emerged after the samplePolicyApp was uploaded on the site?
 
Thank you very much,
 
Denis

Have you verified that the sample request works when you submit to it?

curl -k -H "Content-type: text/xml;" -d @sampleXacmlReq.xml http://server:port

I have seen some differences in behavior depending upon the platform python is running on and the python version.

Mark

Hi Mark, thank you for your help.

This is what I get running the suggested command:


length 1634
cucm.testud.locale - - [05/Jun/2012 09:44:59] "HEAD /samplePolicyApp.py HTTP/1.1" 200 -
<?xml version="1.0" encoding="UTF-8"?><Request xmlns="urn:oasis:names:tc:xacml:2.0:context:schema:os"><Subject SubjectCategory="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"><Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:role-id"DataType="http://www.w3.org/2001/XMLSchema#string" Issuer="requestor"><AttributeValue>CISCO:UC:UCMPolicy</AttributeValue></Attribute><Attribute AttributeId="urn:Cisco:uc:1.0:callingnumber"DataType="http://www.w3.org/2001/XMLSchema#string"><AttributeValue>227</AttributeValue></Attribute><Attribute AttributeId="urn:Cisco:uc:1.0:callednumber"DataType="http://www.w3.org/2001/XMLSchema#string"><AttributeValue>4900</AttributeValue></Attribute><Attribute AttributeId="urn:Cisco:uc:1.0:transformedcgpn"DataType="http://www.w3.org/2001/XMLSchema#string"><AttributeValue>227</AttributeValue></Attribute><Attribute AttributeId="urn:Cisco:uc:1.0:transformedcdpn"DataType="http://www.w3.org/2001/XMLSchema#string"><AttributeValue>4900</AttributeValue></Attribute></Subject><Resource><Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id"DataType="http://www.w3.org/2001/XMLSchema#anyURI"><AttributeValue>CISCO:UCemoticonoiceOrVideoCall</AttributeValue></Attribute></Resource><Action><Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id"DataType="http://www.w3.org/2001/XMLSchema#anyURI"><AttributeValue>any</AttributeValue></Attribute></Action><Environment><Attribute AttributeId="urn:Cisco:uc:1.0:triggerpointtype"DataType="http://www.w3.org/2001/XMLSchema#string"><AttributeValue>translationpattern</AttributeValue></Attribute></Environment></Request>
--- Begin Document ---
----------------------------------------
Exception happened during processing of request from ('192.168.169.81', 53737)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 582, in process_request_thread
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 638, in __init__
self.handle()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
self.handle_one_request()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request
method()
File "samplePolicyApp.py", line 102, in do_POST
parser.parse("tempXacmlReq.xml")
File "/usr/lib/python2.7/xml/sax/expatreader.py", line 107, in parse
xmlreader.IncrementalParser.parse(self, source)
File "/usr/lib/python2.7/xml/sax/xmlreader.py", line 123, in parse
self.feed(buffer)
File "/usr/lib/python2.7/xml/sax/expatreader.py", line 211, in feed
self._err_handler.fatalError(exc)
File "/usr/lib/python2.7/xml/sax/handler.py", line 38, in fatalError
raise exception
SAXParseException: tempXacmlReq.xml:1:259: not well-formed (invalid token)
----------------------------------------
curl: (52) Empty reply from server

I'm running the sample application on a Ubuntu Linux (12.04) virtual machine, python version is 2.7.3

When I monitored the http exchange with wireshark i was running the application on Windows 7: the request and the response were well formed.

Thank you again

Denis Roman Fulin

I tried your request and it failed for me on Ubuntu/Python 2.7.2+, so I started taking apart your request syntax...

I notice there is no white space in the <Attribute > tag:

<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:role-id"DataType="http://www.w3.org/2001/XMLSchema#string" Issuer="requestor">

I put a 'space' in front of every DataType to separate it from the AttributeId, and your request worked successfully.

Mark

I tried to run the curl command adding the missing 'spaces' in the sampleXacmlReq.xml and I get no more errors.

But there is a problem: the first time I ran the curl command I used a copy of the tempXacmlReq.xml that the sample application creates everytime it gets a POST request from the CallManager (that's the request visible in my previous post). The sample application reads that file before taking a decision, so it's still not working.

So, if there's a missing 'space', the error is in the xml parser of the sample application which doesn't put the 'space' before the DataType.
The problem is that the parsing operation is quite transparent, so I don't see a way to add the missing 'spaces', unless editing manually the 'postdata' variable (I suppose it's a string) before it's written on the tempXacmlReq.xml file.

Am I right or Am I missing something?

Thank you very much

Denis

Sorry, now I understand what you're doing. What version of Unified CM are you using? I haven't had this be a problem in the past, but I haven't tried every version of Unified CM either.

UCM version is 8.6.2.21900-5

Had to switch my lab back to 8.6.2 to check some things out...

I had never really tried using the 'temp' file created by the sample policy app as a test file for the app itself. It turns out that it will not work. If you look at the file itself, you see something like this (with 'cat -e'):

<?xml version="1.0" encoding="UTF-8"?>$
<Request xmlns="urn:oasis:names:tc:xacml:2.0:context:schema:os">$
<Subject SubjectCategory="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject">$
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:role-id"$
DataType="http://www.w3.org/2001/XMLSchema#string" Issuer="requestor">$
<AttributeValue>CISCO:UC:UCMPolicy</AttributeValue>$
</Attribute>$



The end of line is valid white space for the parser to parse:

parser.parse("tempXacmlReq.xml")



It looks like when you re-post that with curl it removes all the end of line characters (the needed white space), which is what causes the parser to throw an exception:

<?xml version="1.0" encoding="UTF-8"?><Request xmlns="urn:oasis:names:tc:xacml:2.0:context:schema:os"><Subject SubjectCategory="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"><Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:role-id"DataType="http://www.w3.org/2001/XMLSchema#string" Issuer="requestor"><AttributeValue>CISCO:UC:UCMPolicy</AttributeValue></Attribute>



I use this formatted sample request to make it easier to read and modify the test requests that I want to post with curl. Because of all the added white space, curl won't eliminate it all when it removes the end of lines:

 1<?xml version="1.0" encoding="UTF-8"?>
 2<Request xmlns="urn:oasis:names:tc:xacml:2.0:context:schema:os">
 3    <Subject SubjectCategory="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject">
 4        <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:role-id"
 5        DataType="http://www.w3.org/2001/XMLSchema#string" Issuer="requestor">
 6            <AttributeValue>
 7                CISCO:UC:UCMPolicy
 8            </AttributeValue>
 9        </Attribute>
10        <Attribute AttributeId="urn:Cisco:uc:1.0:callingnumber"
11        DataType="http://www.w3.org/2001/XMLSchema#string">
12            <AttributeValue>
13                2010
14            </AttributeValue>
15        </Attribute>
16        <Attribute AttributeId="urn:Cisco:uc:1.0:callednumber"
17        DataType="http://www.w3.org/2001/XMLSchema#string">
18            <AttributeValue>
19                2011
20            </AttributeValue>
21        </Attribute>
22        <Attribute AttributeId="urn:Cisco:uc:1.0:transformedcgpn"
23        DataType="http://www.w3.org/2001/XMLSchema#string">
24            <AttributeValue>
25                +19728132010
26            </AttributeValue>
27        </Attribute>
28        <Attribute AttributeId="urn:Cisco:uc:1.0:transformedcdpn"
29        DataType="http://www.w3.org/2001/XMLSchema#string">
30            <AttributeValue>
31                +19728132011
32            </AttributeValue>
33        </Attribute>
34    </Subject>
35    <Resource>
36        <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id"
37        DataType="http://www.w3.org/2001/XMLSchema#anyURI">
38            <AttributeValue>
39                CISCO:UC:VoiceOrVideoCall
40            </AttributeValue>
41        </Attribute>
42    </Resource>
43    <Action>
44        <Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id"
45        DataType="http://www.w3.org/2001/XMLSchema#anyURI">
46            <AttributeValue>
47                Any
48            </AttributeValue>
49        </Attribute>
50    </Action>
51    <Environment>
52        <Attribute AttributeId="urn:Cisco:uc:1.0:description"
53        DataType="http://www.w3.org/2001/XMLSchema#string">
54            <AttributeValue>
55                CUCM Routing Request v1.0
56            </AttributeValue>
57        </Attribute>
58    </Environment>
59</Request>


Let's get this working for you; then we can tackle any other problems.

I don't get any error using with curl the sample request you posted.
So it was a problem with the curl command, not with the request.

If it can be of any help:

I tried to run only the saxXacmlHandler.py script. When I run it with the temp file created by the sample application I get the right output

 --- Begin Document ---
 AttributeId urn:oasis:names:tc:xacml:1.0:subject:role-id
 AttributeId urn:Cisco:uc:1.0:callingnumber
 CallingNumber 227
 AttributeId urn:Cisco:uc:1.0:callednumber
 CalledNubmer 9999
 AttributeId urn:Cisco:uc:1.0:transformedcgpn
 TransformedCgpn 227
 AttributeId urn:Cisco:uc:1.0:transformedcdpn
TransformedCdpn 9999
AttributeId urn:oasis:names:tc:xacml:1.0:resource:resource-id
AttributeId urn:oasis:names:tc:xacml:1.0:action:action-id
AttributeId urn:Cisco:uc:1.0:triggerpointtype
endElement Request




but when I run it with the sample request you posted it gives this

  --- Begin Document ---
 AttributeId urn:oasis:names:tc:xacml:1.0:subject:role-id
 AttributeId urn:Cisco:uc:1.0:callingnumber
 CallingNumber
 
 AttributeId urn:Cisco:uc:1.0:callednumber
 CalledNubmer
 
 AttributeId urn:Cisco:uc:1.0:transformedcgpn
TransformedCgpn

AttributeId urn:Cisco:uc:1.0:transformedcdpn
TransformedCdpn

AttributeId urn:oasis:names:tc:xacml:1.0:resource:resource-id
AttributeId urn:oasis:names:tc:xacml:1.0:action:action-id
AttributeId urn:Cisco:uc:1.0:description
endElement Request






Thank you again for your help

It's actually working, it's a side effect of the way that saxXacmlHandler.py is written. It matched 'spaces' as the numbers instead of throwing away white space in the XML, which would be nicer. You can either edit my request to change the way the <AttributeValue> tags are laid out:

<AttributeValue>
2011
</AttributeValue>



<AttributeValue>2011</AttributeValue>



Or you can look at the characters procedure in saxXacmlHandler.py:

1def characters(self, ch):
2    if self.isCallingNumber == 1:
3        self.CallingNumber = ch
4        print 'CallingNumber ' + ch
5        self.isCallingNumber = 0
6etc...


To do this in a slightly more functional way, you can modify that procedure to deal with white space:

 1def characters(self, ch):
 2    if ch.isspace():
 3        # Characters are spaces
 4        ch = ''
 5    else:
 6        # Strip any whitespace
 7        chStrip = ch.strip()
 8        if self.isCallingNumber == 1:
 9            self.CallingNumber = chStrip
10            print 'CallingNumber: ' + chStrip
11            self.isCallingNumber = 0
12etc...


change ch to chstrip in each of the 'if' stanzas of 'def characters', and it will deal with the white space issues.

Ok, so we found out thant the problem isn't in the request.

So the problem is in the response or in the UCM. This is the response that the sample app prints on screen:

<?xml encoding="UTF-8" version="1.0"?> <Response><Result><Decision>Permit</Decision><Obligations><Obligation FulfillOn="Permit" ObligationId="continue.simple"><AttributeAssignment AttributeId="Policy:continue.simple"><AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string"><cixml ver="1.0"><divert><destination>236</destination></divert></cixml></AttributeValue></AttributeAssignment></Obligation></Obligations></Result></Response>

It seems correct to me (I already tried replacing left and right brackets in the <cixml>...</cixml> block with &lt; and &rt;).
Maybe it's something in the header of the POST response?

two things:

1. What is the URI in the request field in CUCM?

2. There are circumstances where everything looks fine, but the action won't happen. In that case, try restarting the CallManager Service from the Servicability page.

Mark

And the CIXML block has to use &lt and &gt in the response or it will definitely fail to take the action...

with "URI in the request field in CUCM" you mean the 'request URI' field in the http request header? If that's the case, the URI is '/samplePolicyApp.py'. I have seen it with wireshark. At the end of the header, and before the xml body, there's this line in the form of a link: '[Full request URI: http://192.168.169.81:8080/samplePolicyApp.py]'

I sniffed the http request with wireshark running the sample app on Windows, because I don't know how to sniff it from the command line on Linux (but I think there's no difference since it comes from the CUCM)

Thank you

Denis

Okay, that should be fine. The way the sample app works is that it just listens to that port and processes any request it receives no matter what gets sent to it. You could just as easily say:

http://server.ip.com:8080/foobar

and the request would work. What will not work is leaving off the port or path. It only gets more complicated if you deploy your app on a webserver hosting many apps.

Two things to check:

1. Your cixml block should use escaped < and > (&lt and &gt). CUCM will ignore the CIXML if it isn't escaped in this way.

2. Restart the CallManager service (via serviceability web page) or reboot the server.

Mark

I rebooted the server and It works!

In the past days I already rebooted the server but it didn't work, so I thought there was another problem.

Thank you very much for your precious help, Mark, you were very patient.

Best regards

Denis

Hi Mark,
I have a little question. Suddenly yesterday the CURRI stopped to work: everything was correct (request, response...) but, like the first time, the CUCM wasn't doing anything with the response (I didn't change anything in the CUCM). So I restarted the CallManager service and everything was perfectly working again.
If this is going to happen again in the future, what could the reason be?

Thank you

Denis

Unfortunately, there is an issue in Unified CM where it will stop working if you make any changes to the URL or interrupt the connection in certain ways. My understanding is that it should be fixed in 9.x. In the meantime, the main workaround is to either never change any settings for a ECCP profile, just switch to a new profile if you need to change something. Or reset the CUCM service on the Unified CM server.

Mark