/
api_n1_n2_message_collection_document.go
109 lines (95 loc) · 3.01 KB
/
api_n1_n2_message_collection_document.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* Namf_Communication
*
* AMF Communication Service
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package communication
import (
"fmt"
"net/http"
"strings"
"github.com/gin-gonic/gin"
"github.com/free5gc/amf/internal/logger"
"github.com/free5gc/amf/internal/sbi/producer"
"github.com/free5gc/openapi"
"github.com/free5gc/openapi/models"
"github.com/free5gc/util/httpwrapper"
)
// N1N2MessageTransfer - Namf_Communication N1N2 Message Transfer (UE Specific) service Operation
func HTTPN1N2MessageTransfer(c *gin.Context) {
var n1n2MessageTransferRequest models.N1N2MessageTransferRequest
n1n2MessageTransferRequest.JsonData = new(models.N1N2MessageTransferReqData)
requestBody, err := c.GetRawData()
if err != nil {
problemDetail := models.ProblemDetails{
Title: "System failure",
Status: http.StatusInternalServerError,
Detail: err.Error(),
Cause: "SYSTEM_FAILURE",
}
logger.CommLog.Errorf("Get Request Body error: %+v", err)
c.JSON(http.StatusInternalServerError, problemDetail)
return
}
contentType := c.GetHeader("Content-Type")
s := strings.Split(contentType, ";")
switch s[0] {
case "application/json":
err = fmt.Errorf("N1 and N2 datas are both Empty in N1N2MessgeTransfer")
case "multipart/related":
err = openapi.Deserialize(&n1n2MessageTransferRequest, requestBody, contentType)
default:
err = fmt.Errorf("Wrong content type")
}
if err != nil {
problemDetail := "[Request Body] " + err.Error()
rsp := models.ProblemDetails{
Title: "Malformed request syntax",
Status: http.StatusBadRequest,
Detail: problemDetail,
}
logger.CommLog.Errorln(problemDetail)
c.JSON(http.StatusBadRequest, rsp)
return
}
req := httpwrapper.NewRequest(c.Request, n1n2MessageTransferRequest)
req.Params["ueContextId"] = c.Params.ByName("ueContextId")
req.Params["reqUri"] = c.Request.RequestURI
rsp := producer.HandleN1N2MessageTransferRequest(req)
for key, val := range rsp.Header {
c.Header(key, val[0])
}
responseBody, err := openapi.Serialize(rsp.Body, "application/json")
if err != nil {
logger.CommLog.Errorln(err)
problemDetails := models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
Detail: err.Error(),
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(rsp.Status, "application/json", responseBody)
}
}
func HTTPN1N2MessageTransferStatus(c *gin.Context) {
req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueContextId"] = c.Params.ByName("ueContextId")
req.Params["reqUri"] = c.Request.RequestURI
rsp := producer.HandleN1N2MessageTransferStatusRequest(req)
responseBody, err := openapi.Serialize(rsp.Body, "application/json")
if err != nil {
logger.CommLog.Errorln(err)
problemDetails := models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
Detail: err.Error(),
}
c.JSON(http.StatusInternalServerError, problemDetails)
} else {
c.Data(rsp.Status, "application/json", responseBody)
}
}