How to handle error in xml-script within transition - moqui

If I try to call a service in xml-script that has missing required input parameters, a ServiceException is thrown and the call returns to the browser with a 200 status. I don't see how I am supposed to catch the error or otherwise deal with it. Do I need to test for completeness before calling the service? And why doesn't a 500 level status get generated and returned?

When script went wrong, error is added messageFacade, so you may detect whether the xml-script in transition or service has error via ec.message.hasError(). If there is logic error instead of exception in script, you are supposed to add error to messageFacade by yourself.
Then before return the response to client, you shall check ec.message.hasError() in a conditional-response and use ec.web.response.setStatus() to return whatever code you want (500 in your case)
<transition name="createSample">
<actions>
... some service-call or xml-actions ...
<if condition="ec.message.hasError()">
ec.web.response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR)
</if>
</actions>
<conditional-response type="none">
<condition>
<expression>ec.message.hasError()</expression>
</condition>
</conditional-response>
<default-response url="."/>
</transition>

Related

Invalid content error on compression:extract

I am attempting to use the zip-extract method in a foreach loop to unzip several files. When I attempt to deploy the project the following error is returned:
Invalid content was found starting with element 'compression:extract'. One of >'{"http://www.mulesoft.org/schema/mule/core":annotations, >"http://www.mulesoft.org/schema/mule/core":abstract-message-processor, >"http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-message-processor}' is expected.
The actual code is:
<compression:extract doc:name="Extract" doc:id="9119d722-95eb-4aee-a734-50e2a2825449" >
<set-payload value="#[payload]" />
<compression:extractor >
<compression:zip-extractor />
</compression:extractor>
</compression:extract>
I have not been able to find anything online that would point towards a solution.
It look like accidentally a <set-payload> was put inside the <compression:extract> element. Also it doesn't make sense at all because it puts the payload as the payload, which it is already is. Just remove that line.
Maybe the intention was to use <compression-compressed>?
Example:
<compression:extract>
<compression:compressed>#[payload]</compression:compressed>
<compression:extractor>
<compression:zip-extractor/>
</compression:extractor>
</compression:extract>
payload is already the default, so it is not needed.

MuleSoft - how to catch an error/exception into Munit test?

Into a flow i raised and error and i would like to test it in Munit.
The documentation doesn't seem to contain and explain this particular case.
what is the text that i need to insert into :
expected error type
expected exception
All errors thrown in Mule contain meta-data including a TYPE.
For example, here is a list of some specific HTTP: errors thrown by the HTTP module:
HTTP:UNSUPPORTED_MEDIA_TYPE
HTTP:CONNECTIVITY
HTTP:INTERNAL_SERVER_ERROR
HTTP:METHOD_NOT_ALLOWED
Each module's documentation should contain all specific error types thrown by that module. Here is the HTTP one example: https://docs.mulesoft.com/connectors/http/http-documentation#throws
In your screenshot for example it uses APIKIT module. APIKIT module has its own errors again. Think of it as certain Java classes throwing custom exceptions specific to that class.
And here is a full list of core error types you can catch like EXPRESSION for example:
https://docs.mulesoft.com/mule-runtime/4.1/mule-error-concept
The attribute expectedErrorType expects an error type ID that needs to be defined inside the application being tested. This attribute allows you to validate that a defined error type in your application is thrown. If you define an errorType that does not exists in your application, the test does not run.
<munit:test name="MUnit-test-suite"
description="Test Error Type"
expectedErrorType="FTP:ILLEGAL_PATH">
...
</munit:test>
This Error Type test expects that an FTP operation will throw an FTP:ILLEGAL_PATH error.
You will need to configure this for your specific type you are expecting.
The attribute expectException expects a literal exception class name (canonical form). When you provide a literal value, it should take the form of the canonical class name of the exception that is expected. In these cases, Mule always throws a MuleMessagingException. MUnit validates the provided classname if the underlying cause of the MuleMessagingException thrown is of the exact same type.
<munit:test name="testExceptions"
description="Test Exceptions"
expectedException="java.lang.RuntimeException">
...
</munit:test>
If you define that your test expects an exception and none is thrown, the test fails immediately.
So you don't need to provide both.

Handling OData Exceptions with Batch mode

I'm implementing SAPUI5 (Fiori like) application, that calls multiple CREATE operations in one batch. At now I've just redefined methods /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_BEGIN / END and proper method is called multiple times. It is working fine when there is no errors.
How should I throw business exception in CREATE_ENTITY method to get message at ForntEnd layer? In console I can see only:
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code>005056A509B11ED1B9BF9F46AA8E82ED</code>
<message xml:lang="en">In the context of Data Services an unknown internal server error occured</message>
</error>
How to handle that?
I solved by myself.
Redefine /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_BEGIN and not
implement any code. That will allow to call multiple operations (eg.
_CREATE_ENTITY) in one batch.
Implement _CREATE_ENTITY accordingly, make necessary checks and prepare data to be processed (create/ update), do not use COMMIT in that methods.
Redefine /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_END and call all needed BAPI's or SQL INSERT / UPDATE statements. In case of any error throw /IWBEP/CX_MGW_BUSI_EXCEPTION - it will be handled properly on Front End. COMMIT will be called automatically.

Error Getting Property

So.. I've got this CA
<CustomAction Id="InstallSetProp" Property="CustomActionData" Value="<some other data that's formatted exactly the same> /webconftmploc="[WEBCONFIGTMPLOC]"" />
However, when this CA is called, a message box is shown saying "Error Getting Property" which is bogus since the property is correctly set and accessible later on. (And does nothing except mess up my attempts to fully automate installation) I'm running the .msi through a bootstrapper that switches /qr to help with this.
The message box error is not shown when /webconftmploc="[WEBCONFIGTMPLOC]" is removed, for the record [WEBCONFIGTMPLOC] is either an absolute file path or "Not Set" and I'm wondering if there's any special reason why this behaviour can occur.
However, I'm much more interested in any possible way to suppress or fix this action, of-course.
That CustomAction only sets a property. It is not possible for it to show an error message. If any of the properties were not defined they would just resolve to blank. Something else must be showing the error message.
However, it appears that you are trying to pass data to a deferred custom action due to your use of the specially named CustomActionData. That isn't quite the way to use CustomActionData though. Instead, the Property attribute should be set to the Id of the CustomAction that you want to pass data too. Say the custom action that uses that property value is something like:
<CustomAction Id='MyDeferredCustomAction' Execute='deferred' ... />
To pass it the string you are trying to send, you could write:
<CustomAction Id="InstallSetProp"
Property="MyDeferredCustomAction"
Value="<some other data that's formatted exactly the same> /webconftmploc="[WEBCONFIGTMPLOC]"" />
Notice that the second custom action is setting a property with the same name as the deferred custom action: MyDeferredCustomAction. The MyDeferredCustomAction can access the value <some other data that's formatted exactly the same> /webconftmploc="value_of_WEBCONFIGIMPLOC_goes_here" via the magical CustomActionData property. You can read more about that here: http://msdn.microsoft.com/en-US/library/2w2fhwzz(v=VS.80).aspx

Logging additional custom information in PHPUnit for reports

I am using PHPUnit Selenium for functional testing of my project.
I am using junit for logging and using the log file to gnerate the report. Following is the log tag in phpunit.xml
<phpunit>
<logging>
<log type="junit" target="reports/logfile.xml" logIncompleteSkipped="false" />
</logging>
</phpunit>
Then I use the logfile.xml to generate the report.
What I am looking for is the ability to log additional information (information telling what exactly is getting tested in assertion, in both cases i.e. in both pass/fail of assertion).
Basically in reports I want to tell what is being asserted. And that information will be written by the test writer in the test case manually along with assertion.
assert functions comes with the third optional parameter as message but that is shown only on failure.
Eg:
<?php
// $accountExists is the dummy variable which wil probably checking in database for the existence of the record
$this->assertEquals(true, $accountExists, 'Expecting for accountExists to be true');
?>
Above will return message on failure but not when test is passed.
you must use the
--printer command line argument to point to a custom printer class
http://www.phpunit.de/manual/3.6/en/extending-phpunit.html#extending-phpunit.PHPUnit_Framework_TestListener
in your endTest function whatever you put in printf will show up in your log file.