cancel
Showing results for 
Search instead for 
Did you mean: 

Change HTTP response status codes in B1if?

adam_kimmorley
Explorer
0 Kudos

Hi,

I'm trying to change the response code for a step called from an incoming HTTP request. In the step I attempt to do something but I receive an error from DI that I want to pass back to the web service calling me. I log the error and format the response, but the other end of the call wants something other than HTTP 200 OK as the response if something went wrong. Is it possible to change the response code to say something like a 409 Conflict?

If it is possible, is it documented anywhere?

Accepted Solutions (1)

Accepted Solutions (1)

HuanYang
Employee
Employee
0 Kudos

Hello Adam Kimmorley,

You may use

<xsl:attribute name="http-status">205</xsl:attribute>

to define a return code.

Thanks & Best regards

Huan Yang

adam_kimmorley
Explorer
0 Kudos

Thanks Huan, Where can I find this documented?

HuanYang
Employee
Employee
0 Kudos

Hello Adam Kimmorley,

I just found it's not in the current document.

We will enhance it.

For you reference, I put a sample here.

Right now you can use the below code for atom0.xsl as reference. Just make sure that the <xsl:attribute name="http-status">205</xsl:attribute> attribute shall be in the transform template of the last XFORM atom (final atom).

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:b1e="urn:com.sap.b1i.sim:b1event" xmlns:b1ie="urn:com.sap.b1i.sim:b1ievent" xmlns:b1im="urn:com.sap.b1i.sim:b1imessage" xmlns:bfa="urn:com.sap.b1i.bizprocessor:bizatoms" xmlns:jdbc="urn:com.sap.b1i.adapter:jdbcadapter" xmlns:js="com.sap.b1i.bpc_tools.Javascript" xmlns:rfc="urn:sap-com:document:sap:rfc:functions" xmlns:sim="urn:com.sap.b1i.sim:entity" xmlns:uplt="urn:com.sap.b1i.xcellerator:upltdoc" xmlns:utils2="com.sap.b1i.bpc_tools.Utilities" xmlns:vpf="urn:com.sap.b1i.vplatform:entity" xmlns:xci="urn:com.sap.b1i.xcellerator:intdoc" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" bfa:force="" vpf:force="" jdbc:force="" rfc:force="" b1ie:force="" b1e:force="" xci:force="" sim:force="" utils2:force="" b1im:force="" uplt:force="" js:force="">
	<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
	<xsl:param name="atom"/>
	<xsl:param name="sessionid"/>
	<xsl:variable name="msg" select="/vpf:Msg/vpf:Body/vpf:Payload[./@Role='S']"/>
	<xsl:variable name="vptsDoc" select="document('/com.sap.b1i.internal/xml/timestamp')"/>
	<xsl:variable name="vpts" select="concat($vptsDoc/*/@year,'/',$vptsDoc/*/@month,'/',$vptsDoc/*/@date,' ',$vptsDoc/*/@hour,':',$vptsDoc/*/@minute,':',$vptsDoc/*/@second)"/>
	<xsl:variable name="vpSender" select="/vpf:Msg/vpf:Header/vpf:Sender/@Id"/>
	<xsl:variable name="vpObject" select="/vpf:Msg/vpf:Header/vpf:Sender/@ObjId"/>
	<xsl:variable name="vpReceiver" select="/vpf:Msg/vpf:Header/vpf:ReceiverList/vpf:Receiver[./@handover='P']/@Id"/>
	<xsl:template match="/">
		<vpf:Msg>
			<xsl:copy-of select="/vpf:Msg/@*"/>
			<xsl:copy-of select="/vpf:Msg/vpf:Header"/>
			<vpf:Body>
				<xsl:copy-of select="/vpf:Msg/vpf:Body/*"/>
				<vpf:Payload Role="R" id="{$atom}" ts="{$vpts}">
					<xsl:call-template name="transform"/>
				</vpf:Payload>
			</vpf:Body>
		</vpf:Msg>
	</xsl:template>
	<xsl:template name="transform">
		<xsl:attribute name="pltype">json</xsl:attribute>
		<!--If commenting the following the statement, then it will use the default value 200-->
		<xsl:attribute name="http-status">205</xsl:attribute>
		<io xmlns="urn:com.sap.b1i.bizprocessor:bizatoms">
			<object>
				<string name="Code">A001</string>
				<string name="Name">Item001</string>
			</object>
		</io>
	</xsl:template>
</xsl:stylesheet>

Please let me know if any question.

Thanks & Best regards

Huan Yang

adam_kimmorley
Explorer
0 Kudos

That explains why I couldn't find it anywhere. Thanks for that 🙂

Answers (2)

Answers (2)

former_member585068
Discoverer
0 Kudos

Hello Huan,

I have the same question:

I tested http-status codes in b1i.

HTTP-STATUS 200 (SUCCESS)

When I use http-status 200 i get a succesfully response in postman

HTTP-STATUS 201 (ERROR)

When I use http-status 201 i get a error response in postman.

SUMMARY: I looks like B1i can’t handle http-status 200 succes but when we use another http-status code in reponse there is a error.

Is there more documentation about this?

Kind regards,

Mark van der Steen

adam_kimmorley
Explorer
0 Kudos

Where did you get the idea of using http-status as an attribute? I can't find anything anywhere about specifying the status 😞

HuanYang
Employee
Employee
0 Kudos

Hello Mark van der Steen,

Thanks for the help and feedback.

Based on my local test, postman return "Could not get any response" if 409, while SoapUI can return 409.

    <xsl:template name="transform">
        <xsl:attribute name="pltype">json</xsl:attribute>
        <xsl:attribute name="http-status">409</xsl:attribute>
        <io xmlns="urn:com.sap.b1i.bizprocessor:bizatoms">
            <object>
                <string name="Code">A001</string>
                <string name="Name">Item001</string>
            </object>
        </io>
    </xsl:template>

We will investigate this matter.

Thanks & Best regards

Huan Yang

adam_kimmorley
Explorer
0 Kudos

I've had success with a 406 error. I found that even though Postman didn't receive the message, if you take a look at the traffic using Fiddler, the response eventually comes through correctly. So it's like postman's timeout is too early or something

HuanYang
Employee
Employee
0 Kudos

Hello Adam Kimmorley,

Yes, You can define the response content.

If you need more help, please upload your test step.

Thanks & Best regards

Huan Yang

adam_kimmorley
Explorer
0 Kudos

Hi Huan,

It's not the content I need help with, I have formatted the body of the message, it's the HTTP status code I want to change... https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

If you look at the raw HTTP response, we're talking about this bit....

Is that possible in B1if?