In my Spring web flow app, one of my action-state transitions looks like this:
<transition on-exception="com.foo.BarException" to="barView">
<set name="flowScope.error" value="foo.bar" type="string" />
</transition>
I would like to set flowScope.error to the literal String "foo.bar", but Spring interprets this as a reference to the foo object's bar attribute. How can I force Spring to take the String literally?
I figured it out: the value needs needs to be enclosed in single quotes:
<set name="flowScope.error" value="'foo.bar'" type="string" />
Related
I'm interested in the recordTerminator parser property of BeanIO. Does it apply to segments too, like "segmentTerminator"? Namely, I have a stream of fixedlength format, containing of a single record with repeatable segments, and all stream is a single line. Hence, I have set recordTerminator="", but it still gives me
==> Invalid 'state': Expected minimum 1 occurrences
==> Invalid 'city': Expected minimum 1 occurrences
==> Invalid 'street': Invalid field length, expected 35 characters
==> Invalid 'zip': Expected minimum 1 occurrences
It doesn't complain about fields that precede to repeatable segment, and complaints about the fields in a repeatable segment are out of order defined in mapping.xml, that looks like this:
<beanio xmlns="http://www.beanio.org/2012/03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org/2012/03/mapping.xsd">
<stream name="employeeFile" format="fixedlength">
<parser>
<property name="recordTerminator" value="" />
</parser>
<record name="employee" class="example.Employee">
<field name="firstName" length="35" />
<field name="lastName" length="35" />
<field name="title" length="35" />
<field name="salary" length="35" />
<segment name="addressList" collection="list" minOccurs="1" maxOccurs="unbounded" class="example.Address">
<field name="street" length="35" />
<field name="city" length="35" />
<field name="state" length="35" />
<field name="zip" length="10" />
</segment>
</record>
</stream>
</beanio>
Class implementations is like this:
package example;
public class Employee {
String firstName;
String lastName;
String title;
String salary;
List<Address> addressList;
// getters and setters not shown...
}
package example;
public class Address {
private String street;
private String city;
private String state;
private String zip;
// getters and setters not shown...
}
If I remove all preceding fields to repetitive segment both from mapping.xml and the input string, remaining string is properly unmarshalled, and marshalled to json afterwards, I even didn't change implementation of java classes, so the preceding fields stay uninitialized, as expected, but properly printed out after marshalling. Where did I go wrong?
OK, my camel code is in spring xml, looks like this:
<route id="simple-route">
<!-- from id="request-file" uri="file://C:/mqdocuments/?fileName=response464.txt"/-->
<from id="request-file" uri="file://C:/mqdocuments/?fileName=request464.txt"/>
<log id="route-log-request" message="request: ${body}"/>
<setHeader headerName="CamelJmsDestinationName" id="_setHeader1">
<constant>queue://QM_TEST/INPUTQ?targetClient=1</constant>
</setHeader>
<to id="_to1" pattern="InOut" uri="websphere:queue:SYSTEM.DEFAULT.LOCAL.QUEUE?useMessageIDAsCorrelationID=true&replyTo=REPLYQ"/>
<log id="route-log-response" message="response: ${body}"/>
<transform>
<simple>${body}\0</simple>
</transform>
<unmarshal ref="parseTransactions464"/>
<marshal ref="jack"/>
<log id="route-log-json" message="jackson: ${body}"/>
</route>
So basically, when I uncomment input from file, in which the reponse is saved, and place in comment mq to endpoint, unmarshalling is OK, but if I put a request to a queue, and get response, then I hope to rectify the problem by a transform that simply adds EOF character, because without it, it gives me error that I reported in the first place.
And transform doesn't help, because I don't know how to write EOF (ascii 26), but even if I figure that out, I'm not sure it will help.
I'm going to attempt this as an answer, unfortunately I can't test this, I have nothing setup for use with Camel. First I would not change the default recordTerminator value for BeanIO and leave it to use the default which is any of CR, LF or CRLF.
Then in the transformation of the message, I'll append a newline (\n) instead of the \0. I don't quite understand why you would want to use the EOF character if you have control over it. Instead of:
<transform>
<simple>${body}\0</simple>
</transform>
I would go for:
<transform>
<simple>${body}\n</simple>
</transform>
See the section on "Using New Lines or Tabs in XML DSLs" close to the bottom of the page:
Using New Lines or Tabs in XML DSLs
Available from Camel 2.9.3
From Camel 2.9.3: it is easier to specify new lines or tabs in XML
DSLs as you can escape the value now xml
<transform> <simple>The following text\nis on a new line</simple></transform>
I was floating around trying to identify the problem, but in the end, I realized I should have set the charset with the encoding attribute of beanio dataFormat, which I couldn't do because of this defect:
http://camel.465427.n5.nabble.com/Re-Exhausted-after-delivery-attempt-1-caught-java-lang-NullPointerException-charset-tc5817807.html
http://camel.465427.n5.nabble.com/Exhausted-after-delivery-attempt-1-caught-java-lang-NullPointerException-charset-tc5817815.html
https://issues.apache.org/jira/browse/CAMEL-12284
Finally, I was instructed by Claus Ibsen to use such workaround:
<bean class="org.apache.camel.dataformat.beanio.BeanIODataFormat"
id="some_bean_id">
<property name="encoding" value="UTF-8"/>
<property name="mapping" value="mapping.xml"/>
<property name="streamName" value="some_stream_name"/>
</bean>
When I make the following AppleScript call to my app, I get a list of text objects:
tell "MyApp"
name of every myobject
end tell
But the following call returns an error:
tell "MyApp"
name of selected myobjects
end tell
Script Error
MyApp got an error: Can't make name of selected MyObjects into type specifier.
I turned on verbose logging with the -NSScriptingDebugLogLevel 1 argument to my app, which gave me this:
2015-01-27 14:33:53.650 MyApp[4848:2572448] Error converting apple event to script command: -1700
2015-01-27 14:33:53.650 MyApp[4848:2572448] Original event: <NSAppleEventDescriptor: 'core'\'getd'{ '----':'obj '{ 'form':'prop', 'want':'prop', 'seld':'pnam', 'from':'obj '{ 'form':'prop', 'want':'prop', 'seld':'MASM', 'from':null() } }, &'csig':65536 }>
2015-01-27 14:33:53.650 MyApp[4848:2572448] Offending object descriptor: <NSAppleEventDescriptor: 'obj '{ 'form':'prop', 'want':'prop', 'seld':'pnam', 'from':'obj '{ 'form':'prop', 'want':'prop', 'seld':'MASM', 'from':null() } }>
2015-01-27 14:33:53.651 MyApp[4848:2572448] Expected type descriptor: <NSAppleEventDescriptor: 'obj '>
This is the "application" section of my sdef file:
<class name="application" code="capp" plural="applications" inherits="application">
<cocoa class="MyApp.MAApplication" />
<element type="myobject" access="r">
<cocoa key="myobjects" />
</element>
<property name="selected myobjects" code="MASM">
<cocoa key="selectedMyObjects" />
<type type="myobject" list="yes" />
</property>
</class>
And the MyObject class:
<class name="myobject" code="MAMO" inherits="item" plural="myobjects">
<cocoa class="MyObject" />
<property name="id" code="ID " type="text" access="r">
<cocoa key="permanentID" />
</property>
<property name="name" code="pnam" type="text" access="r">
<cocoa key="displayName" />
</property>
</class>
When I just call selected myobjects, I get back a list of identifiers, so that part is working correctly. When can't I get the name or other properties back from that list, when I can with another list specified the exact same way (except as an element instead of property)?
Update
Still not having any luck so far. I noticed, with verbose logging, that when I call name of every MyObject, the command "Intrinsics.get" triggers with an NSPropertySpecifier "displayName of myobjects". Apparently that link doesn't get made when using a property rather than an element to return a list of items. I found a workaround, though, since I specify an is selected property on MyObject. You can call:
name of every myobject whose is selected = true
That works the way I expected my selected myobjects property to work, returning a list of text objects.
Update 2
I added a sample project to GitHub:
https://github.com/abbeycode/AppleScriptObjectList
That contains a sample script with the first two methods that behave as expected, followed by the one that triggers the error. Feel free to mess around if you'd like. I submitted a radar with this sample project.
I'm using Spring Web Flow in my webapp and i would like to know if there is a general way to prevent some subflows to be accessed directly. These subflows are meant to be accessed just from certain flows, not directly by the url, so in these subflows i would like to check "if i was called from a flow".
is there any mechanisms to achieve it? I was looking at spring security but i couldn't find any useful feature to make this kind of restriction.
Thanks you!
You can check this by using input mapper attribute as shown below. Suppose you have a parent flow which invokes 'subflow-flow'. You need to pass an input value containing the name of the parent flow as:
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
...
<subflow-state id="subflow-flow" subflow="subflow-flow">
<!--flowInitiatedBy should be different for each different parent flow-->
<input name="flowInitiatedBy" value="'parentFlowName'"/>
<transition on="invalidAccess" to="someViewWithMessage"/>
<transition on="processedSubflow" to="someOtherState"/>
</subflow-state>
...
</flow>
Then in subflow you can retrieve the parentflowname and perform the check in yourAction class. You can define subflow as:
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"
start-state="start">
<input name="flowInitiatedBy" type="java.lang.String"/>
<action-state id="start">
<evaluate expression="yourAction.checkAccessibility(flowRequestContext)"/>
<transition on="invalidAccess" to="verifyWhetherDraftsExists"/>
<transition on="continue" to="continueToState"/>
</action-state>
<!--define other states for continue transition -->
...
<end-state id="invalidAccess"/>
<end-state id="processedSubflow"/>
</flow>
In your action class:
public class YourAction{
...
public String checkAccessibility(RequestContext context){
String flowInitiatedBy = context.getFlowScope().get("flowInitiatedBy");
//flowInitiatedBy will be empty if initiated by url.
if(flowInitiatedBy is empty){
return "invalidAccess";
}else{
// dosomething
return "continue";
}
}
...
}
Hope this helps.
I also wish there was some kind of built-in, simple mechanism. However, I just did this a slightly different way I thought I'd share. That is, since my Subflow knows its own name, I just had the first state in the Flow configuration check whether or not the Flow ID (name) matches that hardcoded name:
<decision-state id="subOnly">
<if test="flowExecutionContext.definition.id == 'thisSubflowFlowName'" then="invalidAccess" else="mySubflowFirstState"/>
</decision-state>
Where "invalidAccess" is an end-state like the prior answer shows.
I am new to spring web flow , my requirement is return a set object to spring web flow action state by evaluating an expression .I am facing problem with below code please correct me.
<action-state id="openDocument">
<set name="requestScope.startPoint" value="requestParameters.startPoint" />
<set name="requestScope.fileName" value="requestParameters.fileName" />
<set name="requestScope.ext" value="requestParameters.ext" />
<evaluate expression="workflowController.workflowopenFile(requestScope.startPoint,requestScope.fileName,requestScope.ext)"></evaluate>
</action-state>
return the expected object from workflowopenFile() , and set it to a variable in flow with result attribute.
I solved my problem. the problem was in
add return attribute to evaluate tag . (result = "workflowSet").
I am using spring web-flow 2.0 and I need to return a variable from sub-flow to parent flow like:
<end-state id="end" >
<output name="mvViewBean" value="viewBean" />
</end-state>
and use it inside my parent flow like :
<subflow-state id="updateSubflowState" subflow="mv-update" >
<on-exit>
<evaluate expression="mvService.onblabla(mvViewBean)" />
</on-exit>
</subflow-state>
Do i need to define variable definitions or something else?
Just came across this issue...The currentEvent does work, but if you indicate that you accept the variable in your updateSubflowState through a
<output name="mvViewBean" value="flowScope.mvViewBean"/>
then you will be able to access it as mvViewBean.
Yo can get the output values getting attribute in currentEvent.
<subflow-state id="updateSubflowState" subflow="mv-update" >
<on-exit>
<evaluate expression="mvService.onblabla(currentEvent.attributes.mvViewBean)" />
</on-exit>
</subflow-state>