Fetching the error details of the failed iflow by using api
2023-12-10 19:14:11 Author: blogs.sap.com(查看原文) 阅读量:9 收藏

In this blog we are fetching the error message and other details of the failed iflows.

Step1: Create the iflow with desired iflow name.

Step2: Connect the Sender and  integration process with the HTTP Adapter and  in the Address field  give the desired endpoint address like as shown below(/Fetching_ the_Error_Msg).

Step3:Add Content Modifier with two properties as given below.

Name                  Source Type                                Source Value                              Data Type

LogEndDate                Expression         ${date:now:yyyy-MM-dd’T’HH:mm:ss.SSS}    java.lang.String

LogStartDate                  Xpath                              /Root/StartDate                                java.lang.String

Step4: Now add Request reply and connect with receiver with the OData V2 Adapter.

Do the following configurations in Connection and processing tab in the V2 OData Adapter.

Follow the below configuration to fetch the MPL logs from the MessageProcessingLogs API using OData V2 adapter.

In Connection tab:

Address : https://<<TenentURL>>/odata/api/v1

Authentication : Basic

Credential Name:  (Deploy the CPI log Credentials with a particular name in the security Material in monitoring section as User credentials type).Give that particular name in the Credential Name field.

In Processing Tab:

Resource Path : MessageProcessingLogs

Query Option: $select=MessageGuid,CorrelationId,ApplicationMessageId,ApplicationMessageType,LogStart,LogEnd,Sender,Receiver,IntegrationFlowName,Status,AlternateWebLink,IntegrationArtifact,LogLevel,CustomStatus,TransactionId,PreviousComponentName&$filter=LogStart ge datetime’${property.LogStartDate}’ and LogEnd le datetime’${property.LogEndDate}’.

Step5:Add the iterating Splitter with the below given Xpath Expression(//MessageProcessingLog).

Step6:Now create one Local Integration Process and Add one Content Modifier.

After adding the content modifier create one property as shown below.

Name : MessageId      Source Type : XPath   Source Value : /MessageProcessingLog/MessageGuid

DataType : java.lang.String

Step7:Add the groovy Script element  and create groovy script with the below script.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
    def body = message.getBody(String);
    body = body.replaceAll("<MessageProcessingLog>","").trim();
    body = body.replaceAll("</MessageProcessingLog>","").trim();
    //body = body.replaceAll("        <?xml version="1.0" encoding="UTF-8"?>","").trim();
    body = body.replaceAll("\\\t|\\\n|\\\r","");
    message.setBody(body);
    return message;
}

Step8:Add one more content modifier to store the entire body with the help of property.

Name : MessageInfo     Source Type : Expression   Source Value : ${in.body}

DataType : java.lang.String

Step9: Now add one Request reply and receiver with the HTTP Adapter.

In Connection Tab:

Address : https://<<TenentURL>>/odata/api/v1//MessageProcessingLogs(‘${property.MessageId}’)/ErrorInformation/$value

Authencation : Basic

Credential Name : (Deploy the CPI log Credentials with a particular name in the security Material in monitoring section as User credentials type).Give that particular name in the Credential Name field.

Step10:Add content modifier to set the content-type in the Header

Name : Content-Type     Source-Type : Constant    Source Value : application/xml

And set the body in the context Modifier as given below.

<MessageProcessingLog>

${property.MessageInfo}

<ErrorDetails>${in.body}</ErrorDetails>

</MessageProcessingLog>

Step11: Define one process call in the main integration process as shown below and select the created local integration process.

Step12: Next add the Gather and set the following fields as below:

Incoming Format : Plain Text

Aggregation Algorithm:Concatentate

Step13: Now add one XML modifier and check the remove xml declaration.

Step14: Add content modifier to set the content-type in the Header

Name:Content-Type     Source-Type:Constant    Source Value:application/xml

And set the body in the context Modifier as given below.

<MessageProcessingLogs>

${in.body}

</MessageProcessingLogs>

Step15: Add one Message Mapping element  and create Mapping as shown below.

After creating the Mapping Upload the Source and Target XSD files with below given xsd Codes.

Source XSD:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="MessageProcessingLogs">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="1" maxOccurs="unbounded" name="MessageProcessingLog">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element type="xs:string" nillable="false" maxOccurs="unbounded" name="MessageGuid" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="CorrelationId" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="ApplicationMessageId" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="ApplicationMessageType" xmlns=""/>
                            <xs:element type="xs:dateTime" nillable="true" minOccurs="0" maxOccurs="unbounded" name="LogStart" xmlns=""/>
                            <xs:element type="xs:dateTime" nillable="true" minOccurs="0" maxOccurs="unbounded" name="LogEnd" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="Sender" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="Receiver" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="IntegrationFlowName" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="Status" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="AlternateWebLink" xmlns=""/>
                            <xs:element nillable="false" maxOccurs="unbounded" name="IntegrationArtifact">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="Id" xmlns=""/>
                                        <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="Name" xmlns=""/>
                                        <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="Type" xmlns=""/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="LogLevel" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="CustomStatus" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="TransactionId" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="ErrorDetails" xmlns=""/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Target XSD:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="MessageProcessingLogs">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="1" maxOccurs="unbounded" name="MessageProcessingLog">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="IntegrationFlowName" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="PackageName" xmlns=""/>
                            <xs:element type="xs:string" nillable="false" maxOccurs="unbounded" name="MessageGuid" xmlns=""/>
                            <xs:element type="xs:dateTime" nillable="true" minOccurs="0" maxOccurs="unbounded" name="LogStart" xmlns=""/>
                            <xs:element type="xs:dateTime" nillable="true" minOccurs="0" maxOccurs="unbounded" name="LogEnd" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="Status" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="LogLevel" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="TransactionId" xmlns=""/>
                            <xs:element type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" name="ErrorDetails" xmlns=""/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

After uploading the XSD files do the one to one Mapping with all the elements in the Target XSD.

Step16: After doing the message Mapping add the xml to csv convertor with

path to source element in xsd field : /MessageProcessingLogs/MessageProcessingLog

and check the include field name as header.

After xml to csv convertor save and deploy the iflow and fetch the endpoints from the message monitoring.

After deploying the Iflow test the iflow in postman as shown below with below body.

<Root>

<StartDate>2023-12-09T9:15:00.000</StartDate>

</Root>

After giving the body click on the send icon.

After click on the send save the response into the file .So, we can view the file in the csv format.


文章来源: https://blogs.sap.com/2023/12/10/fetching-the-error-details-of-the-failed-iflow-by-using-api/
如有侵权请联系:admin#unsafe.sh