I am facing a problem in assigning default String value in Smooks. When I assign the default value as "Unknown" for <jb:value> it doesn't take it and throws an error.
Smooks config file:
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.3.xsd"
xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.4.xsd">
<jb:bean beanId="ResData" class="java.util.HashMap"
createOnElement="perReturn" retain="true">
<jb:value property="TransactionId" data="TransactionId" />
<jb:value property="amount" data="amount" />
<jb:value property="subscriberConfirmationNo" data="ConfirmationNo" />
<jb:value property="errorMessage" data="errorMessage" />
<jb:value property="status" data="status" />
<jb:value property="Tokan" data="Tokan" />
<jb:value property="Freefield1" data="Freefield1" />
</jb:bean>
<jb:bean beanId="ErrorMap" class="java.util.HashMap"
createOnElement="Body" retain="true">
<jb:expression property="errorText">
if(VARS.isdef("ResData"))
{
if(ResData.status == "0" )
{
return "Success";
}
else if(ResData.status == "1")
{
return ResData.errorMessage;
}
else if(ResData.status == null)
{
return "Sorry! Request could not be processed due to a technical issue.
Status will be updated in 48hrs.";
}
else
{
return ResData.errorMessage;
}
}
else
{
return "Sorry! Request could not be processed due to a technical issue.
Please try again later.";
}
</jb:expression>
<jb:value property="errorCode" data="Response/perReturn/errorMessage"
decoder="String" default="Error" />
<jb:value property="errorFlag" data="Response/perReturn/status"
decoder="Integer" default="2" />
<jb:value property="partnerId" data="Body" decoder="String">
<jb:decodeParam name="valuePreprocess">return "8011";</jb:decodeParam>
</jb:value>
</jb:bean>
Source File:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sync="http://sync.partner.virtualization.xyzz.com">
<soapenv:Header />
<soapenv:Body>
<sync:Response>
<perReturn>
<TransactionId>123456789</TransactionId>
<amount>10</amount>
<ConfirmationNo>0000000000</ConfirmationNo>
<errorMessage></errorMessage>
<status>0</status>
<Tokan>01244243016</Tokan>
<Freefield1>1437083181</Freefield1>
</perReturn>
</sync:Response>
</soapenv:Body>
I added the Smooks config file and source data. When the error message is null in the source file, I want to default error code to some text but it isn't working.
Related
I am trying to create a file in a subdirectory of the internal storage and then saving a picture taken with a picture intent in this file. The picture is only supposed to be used once so everytime a new picture is taken the file can be overwritten with the new picture. I have created a file and with the fileprovider i get a URI for the file and try to save the picture herein but this doesn't seem to work.
The manifest.xlm file:
<uses-feature android:name="android.hardware.camera"
android:required="true" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths" />
</provider>
The TakePictureFragment containing the method for creating a file and taking the picture:
fun createFileAndIntent() {
//Lav nyt subdirectory i **internal storage**
val dir = File(context?.filesDir, "mydir")
if (!dir.exists()) {
dir.mkdir()
} else dir.delete()
val filePath = File(context?.filesDir, "mydir")
val newFile = File(filePath, "7Kabale.jpg")
if (!newFile.exists() || !newFile.canRead()) throw
IllegalArgumentException("newFile does not exist")
val fileURI = FileProvider.getUriForFile(
requireContext(),
context?.packageName + ".provider",
newFile
)
if (Uri.EMPTY.equals(fileURI)) throw IllegalArgumentException("Uri not found")
val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileURI)
startActivity(takePictureIntent)
}
provider_paths.xml file
<paths>
<external-path
name="external"
path="." />
<external-files-path
name="external_files"
path="." />
<cache-path
name="cache"
path="." />
<external-cache-path
name="external_cache"
path="." />
<files-path
name="files"
path="." />
</paths>
I have defined a global function as below
<configuration doc:name="Configuration">
<expression-language autoResolveVariables="true">
<import class="java.text.SimpleDateFormat" />
<global-functions>
def convertDate(shiftDate){
dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return dateFormat.format(shiftDate);
}
</global-functions>
</expression-language>
</configuration>
But when calling via logger nothing seems to happen
<logger message="Convert Date #[convertDate(xpath://address/#timestamp)]" level="DEBUG" doc:name="Logger"/>
The xpath expression xpath://address/#timestamp yields 2014-10-29T15:23:07
But before the logger I see
xpath-branch:/address/#timestamp is: org.dom4j.tree.DefaultAttribute#6452310a [Attribute: name timestamp value "2014-10-29T15:23:07"]
The error message is as below
org.mule.api.expression.InvalidExpressionException: [Error: unexpected end of statement]
[Near : {... convertDate(xpath://address/#payloadID) ....}]
What am I doing wrong here? Many Thanks.
You're mixing MEL and the old style of expressions.
This is old style: xpath://address/#payloadID
This is MEL: xpath('//address/#payloadID').value
So you need to use:
<logger
message="Convert Date #[convertDate(xpath('//address/#payloadID').value)]"
level="DEBUG" />
See: http://www.mulesoft.org/documentation/display/current/Mule+Expression+Language+Tips#MuleExpressionLanguageTips-XPathSupport
How to include Spring configuration files optionally? I think about something simular to this:
<spring>
<context>
<resource uri="file:///Objects/RequiredObjects.xml" />
<resource uri="file:///Objects/OptionalObjects.xml" required="false" />
</context>
This way I could provide developers the possibility to override some configuration parts (e.g. for a local speed improvement or automatism during app startup) without affecting the app.config and the problem that a developer could checkin his modified file when it is not really his intent to change the config for all.
Not as simple as in AutoFac (because there is already a builtin way) but possible to achieve something similar with a little coding:
using System.IO;
using System.Xml;
using Spring.Core.IO;
public class OptionalFileSystemResource : FileSystemResource
{
public OptionalFileSystemResource(string uri)
: base(uri)
{
}
public override Stream InputStream
{
get
{
if (System.IO.File.Exists(this.Uri.LocalPath))
{
return base.InputStream;
}
return CreateEmptyStream();
}
}
private static Stream CreateEmptyStream()
{
var xml = new XmlDocument();
xml.LoadXml("<objects />");
var stream = new MemoryStream();
xml.Save(stream);
stream.Position = 0;
return stream;
}
}
Register a section handler:
<sectionGroup name="spring">
...
<section name="resourceHandlers" type="Spring.Context.Support.ResourceHandlersSectionHandler, Spring.Core"/>
...
</sectionGroup>
...
<spring>
<resourceHandlers>
<handler protocol="optionalfile" type="MyCoolStuff.OptionalFileSystemResource, MyCoolStuff" />
</resourceHandlers>
...
<context>
<resource uri="file://Config/MyMandatoryFile.xml" />
<resource uri="optionalfile://Config/MyOptionalFile.xml" />
...
You'll find more information about resources and resource handlers in the Spring.Net documentation.
I build a WCF selfhosted WS (basichttp-binding) with 2 methods. Then created a WSDL and delivered it to a customer. Now they are sending SOAP-requests to the service but one of my methods (PostSendeplatz) fails everytime with a null parameter. In the trace I see the following:
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Verbose">
<TraceIdentifier>http://msdn.microsoft.com/de-DE/library/System.Runtime.Serialization..aspx</TraceIdentifier>
<Description>An unrecognized element was encountered in the XML during deserialization which was ignored.</Description>
<AppDomain>RabbitServerTopSelf.vshost.exe</AppDomain>
<ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/StringTraceRecord">
<Element>http://plantri.de:sendeplatz</Element>
</ExtendedData>
</TraceRecord>
I checked my namespaces in DataContracts, ServiceContract and ServiceImplementation:
[ServiceContract(Namespace = "http://plantri.de")]
public interface IRabbitImportService {
[OperationContract]
bool PostSendung(Sendung sendung, out string errorMsg);
[OperationContract]
bool PostSendeplatz(Sendeplatz sendePlatz, out string errorMsg);
}
...
[DataContract(Namespace = "http://plantri.de")]
public class Sendeplatz : RabbitIdBase { ...
...
[DataContract(Namespace = "http://plantri.de")]
public class Sendung : RabbitIdBase { ...
...
[ServiceBehavior(Namespace="http://plantri.de")]
public class RabbitImportService : Log4NetLogWriter, IRabbitImportService {
...
public bool PostSendung(Sendung sendung, out string errorMsg) {
... do something and return success
}
public bool PostSendeplatz(Sendeplatz sendePlatz, out string errorMsg) {
errorMsg = String.Empty;
if (sendePlatz == null) {
Error("no Sendeplatz send!");
return false;
}
... never came until this point!!!!
}
Here is a part of the soap-envelope which isn't deserialized (from the trace):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://192.168.40.64:8800/RabbitImportService</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://plantri.de/IRabbitImportService/PostSendeplatz</Action>
</s:Header>
<soapenv:Body>
<PostSendeplatz xmlns="http://plantri.de">
<sendeplatz>
<Id>1258878</Id>
...
But the working envelope looks quite the same:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://192.168.40.64:8800/RabbitImportService</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://plantri.de/IRabbitImportService/PostSendung</Action>
</s:Header>
<soapenv:Body>
<PostSendung xmlns="http://plantri.de">
<sendung>
<Id>564589</Id>
...
I don't have a chance to change the client proxy which was writen by a customer (JAVA).
Did anyone have an idea to solve the problem?
But the working envelope looks quite the same: How?
<PostSendeplatz xmlns="http://plantri.de">
<sendeplatz>
<PostSendung xmlns="http://plantri.de">
<sendung>
I see these tag names differs.
I cannot read the value attribute of <add name="ReleaseVersion" value="4"/> in the app.config below. I am at a complete loss. I suspect the XPath value or a Key value.
Target
<Target Name="xxx"
DependsOnTargets="CopyFilesToOutputDirectory" >
<ItemGroup>
<_DestinationAppConfigFile Include="#(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')" />
</ItemGroup>
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="ReadAttribute"
File="%(_DestinationAppConfigFile.FullPath)"
XPath="/configuration/system.diagnostics/switches/add[#name='ReleaseVersion']/#value"
Value="$(ReleaseVersion)" />
<Error Condition = " '$(ReleaseVersion)'=='' "
Text="Failed to read attribute." />
<Message Text="ReleaseVersion: $(ReleaseVersion)"
Importance="high" />
</Target>
App.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.diagnostics>
<switches>
<!-- ReleaseVersion (Conditional release switch); 0- = PRODUCTION, 1 = MIRROR, 2 = EMERGENCYRELEASE, 3 = USERACCEPTANCETESTING, 4 = QA, 5 = DEVELOPMENT, 6 = DRN DEVELOPMENT -->
<add name="ReleaseVersion" value="4"/>
<!-- Stop (Stops execution to allow for Just-In-Time (JIT) debugging); 0 = CONTINUE EXECUTION, 1 = LAUNCH DEBUGGER -->
<add name="Stop" value="0"/>
</switches>
</system.diagnostics>
</configuration>
Update
I reviewed the code for XmlFile.ReadAttribute at http://msbuildextensionpack.codeplex.com/SourceControl/changeset/view/83099#1714660 and it makes the call SelectSingleNode using the namespace syntax. That could be the problem.
private void ReadAttribute()
{
if (string.IsNullOrEmpty(this.XPath))
{
this.Log.LogError("XPath is Required");
return;
}
this.LogTaskMessage(string.Format(CultureInfo.CurrentUICulture, "Read Attribute: {0}", this.XPath));
XmlNode node = this.xmlFileDoc.SelectSingleNode(this.XPath, this.namespaceManager);
if (node != null && node.NodeType == XmlNodeType.Attribute)
{
this.Value = node.Value;
}
}
Your sample code is almost correct; it just needs a slight change to the usage of the XmlFile task. The call to XmlFile ReadAttribute should declare Value as the task's output. To do this, add the Output element to the task declaration, set to the TaskParameter value to "Value" and set the PropertyName value to "ReleaseVersion", similar to the following:
<MSBuild.ExtensionPack.Xml.XmlFile
TaskAction="ReadAttribute"
File="[example-path-to-app-config]"
XPath="/configuration/system.diagnostics/switches/add[#name='ReleaseVersion']/#value">
<Output TaskParameter="Value" PropertyName="ReleaseVersion" />
<MSBuild.ExtensionPack.Xml.XmlFile>
After making the change, the attribute value should be found/read by the task, assuming your ToolsVersion is set to the version needed by your particular implementation of MSBuild Extension Pack