Fix local server for multiple applications
[anna.git] / example / diameter / launcher / resources / rest_api / helpers / decodeHex.sh
1 #!/bin/bash
2
3 [ -z "$1" ] && { echo "Usage: <hex file from 'tsharkDecoder.sh'>" ; exit 1 ; }
4 [ ! -f "$1" ] && { echo "Cannot find '$1' !" ; exit 1 ; }
5
6 ENDPOINT=$(cat ../.httpServer 2>/dev/null)
7 [ -z "${ENDPOINT}" ] && ENDPOINT=localhost:8000
8
9 cd $(dirname $0)
10 tmpfile=$(mktemp)
11 cat << EOF > $tmpfile
12 {
13   "diameterHex":"$(cat $1)"
14 }
15 EOF
16 responseField=$(curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d@${tmpfile} http://${ENDPOINT}/decode 2>/dev/null | jq '.response')
17 rm ${tmpfile}
18 [ -z "${responseField}" ] && { echo "Unexpected error. Check that ADML is started and the corresponding diameter dictionary is loaded." ; exit 1 ; }
19
20 # Remove surrounding quotes:
21 base64=$(echo ${responseField} | tr -d '"')
22
23 # Decode response (base64), which is xml:
24 echo ${base64} | base64 -d > ${1}.xml
25 echo "Created '${1}.xml'"
26
27 # Also create the json version:
28 diameterJsonHelper/xml2json.py ${1}.xml > ${1}.xml.json
29 echo "Created '${1}.xml.json'"