Using url-expression - java

I have a spring integration configured to build a url from a property and some variables:
<int-http:outbound-gateway
url="${pdf.url}?id={id}&version={version}"
request-factory="int.http.requestFactory"
http-method="GET"
transfer-cookies="false"
header-mapper="fTokenHeaderMapper"
expected-response-type="java.lang.String" >
<int-http:uri-variable name="id" expression="payload.id"/>
<int-http:uri-variable name="version" expression="payload.version"/>
</int-http:outbound-gateway>
Now I want to change it so that the server part (pdf.url) could be changed on the fly and not only on startup. To achieve that I have changed from 'url' to 'url-expression' and something like this:
<int-http:outbound-gateway
url-expression="#configurationService.getConfiguration('pdf.url')?id={id}&version={version}"
request-factory="int.http.requestFactory"
http-method="GET"
transfer-cookies="false"
header-mapper="fTokenHeaderMapper"
expected-response-type="java.lang.String" >
<int-http:uri-variable name="id" expression="payload.id"/>
<int-http:uri-variable name="version" expression="payload.version"/>
</int-http:outbound-gateway>
This line seems to work:
url-expression="#configurationService.getConfiguration('pdf.url')"
But how do I include the variables in a similar way as the first example?

From the big height I'd move that URI variables part to the configurationService.getConfiguration(), too. It will be more cleaner to read the XML config.
From other side the url-expression is a SpEL runtime expression. So, any its part which should not be executable, must be as literal:
url-expression="#configurationService.getConfiguration('pdf.url') + '?id={id}&version={version}'"

Your configuration is only read once during startup, so you can't change the value of pdf.url during runtime and expect that it'll change dynamically.

Related

Replace XML value in Velocity

I will preface the below with stating i am new to Java in general:
I have the need to insert the a value into an already existing XML in the below case for the attribute "directory".
<?xml version="1.0" encoding="UTF-8"?>
<DTABLEITEM Name="0216.11 neu">
<DVALUE Name="Type" Value="2"/>
<DVALUE Name="Workspace" Value="ST_0216.11.ARD"/>
<DVALUE Name="IntSetupFile" Value=""/>
<DVALUE Name="IntDocPlotCmd" Value=""/>
<DVALUE Name="Directory" Value=""/>
<DVALUE Name="Resource" Value=""/>
/DTABLEITEM>
Below is an example of code that works in one use case where i was able to replace a value easily.
#foreach ($item1 in $xmlf1.find("/."))
$item1.toString().replace("<<wfp.Macro_Settings_Name/>>","(Broken or Missing) <<wfp.Macro_Settings_Name/>>")
#end
The below returns my XML without any modifications but after many hours searching i cannot find anything that works for me either i need a way of replacing that whole line as a string or a way to set the value neither of which i have been successful with.
I understand the below is simply loading the XML and printing
#foreach ($item1 in $xmlf1.find("/."))
$item1
#end

Changing double to Double in hybris

I have a requirement to change a field from double to Double in hybris typeSystem and was wondering if it actually creates a new database field or just changes the type in app layer.
Thanks in advance.
After the items.xml change and system update the data base field remained the same type. All reads and write are from the same column. So, the answer to my question is no, the column type does not change in database. Only the application layer (model) has changed the field from double to Double.
You have the mapping in core-advanced-deployment.xml.
The mapping depends on DB :
<type-mapping type="java.lang.Double" persistence-type="decimal(30,8)" />
<type-mapping type="double" persistence-type="decimal(30,8) DEFAULT 0" />
or:
<type-mapping type="java.lang.Double" persistence-type="double" />
<type-mapping type="double" persistence-type="double default 0" />
or:
<type-mapping type="java.lang.Double" persistence-type="float" />
<type-mapping type="double" persistence-type="float default 0" />
So you see that it's currently map that's why you can do that and you don't see change in the DB.
Note that changing a type is strongly discouraged because you can switch to uncompatble type. For instance if you have a column of String you can't migrate it to Number for example because a string is not always parseable in a number.

LiquiBase : How to use <whereparams> inside an <update>?

I am looking for an example on how to use the <whereparams></whereparams> which belongs to <update></update>, but I couldn't find anything (even in the official documentation).
any help is much appreciated.thanks.
An example usage is
<update tableName="updateTest">
<column name="varcharColumn" value="new column 1 value"/>
<column name="dateCol" valueDate="2008-01-01"/>
<column name="intCol" valueNumeric="11"/>
<where>id=:value</where>
<whereParams>
<param valueNumeric="134" />
</whereParams>
</update>
where the :value statements in the <where> block is replaced with the values in the `param' blocks. If there are multiple :value statements they are replaced in order within the where clause.
However, looking at the code, it looks like the usage of whereParams is not well used or integrated. Perhaps I am missing where it is being picked up, but it may not even be working outside blob/clob updating.
Give it a try and see if it works for you, otherwise I'd say stick with the standard where block until support is improved.
I support #nathan-voxland answer. Seems he is very good in liquibase.
But i want share one more where/whereParams example with additional ability (you can use whereParams block for field names also):
<where>:name=:value and :name=:value</where>
<whereParams>
<param name="id" valueNumeric="21"/>
<param name="name" value="bob"/>
</whereParams>
I believe my example do not need more explanations.
In response to Nathan's comment about lack of support for this feature, I can confirm that it is working well in version 3.3.2. When he commented liquibase was at version 3.1.1. Maybe support was improved somewhere between 3.1.1 and 3.3.2, but from a quick browse through the change log I don't see which version this would have been.
The docs at http://www.liquibase.org/documentation/changes/update.html are sparse, but basically the contains a SQL-like where clause. So if you would normally do something like
UPDATE cat.person SET address = NULL WHERE id=12;
Then your changeset would look like this:
<changeSet author="liquibase-docs" id="update-example">
<update catalogName="cat"
schemaName="public"
tableName="person">
<column name="address" type="varchar(255)"/>
<where>id=12</where>
</update>
</changeSet>

How to put a newline in ant property

This doesn't seem to work:
<property name="foo" value="\n bar \n"/>
I use the property value in the body of an e-mail message (which is sent as plain text):
<mail ...>
<message>some text${foo}</message>
and I get literal "\n" in the e-mail output.
These all work for me:
<property name="foo" value="bar${line.separator}bazz"/>
<property name="foo">bar
bazz2</property>
<property name="foo" value="bar
bazz"/>
You want ${line.separator}. See this post for an example. Also, the Ant echo task manual page has an example using ${line.separator}.
By using ${line.separator} you're simply using a Java system property. You can read up on the list of system properties here, and here is Ant's manual page on Properties.

How do I pass model data beween a view state and action state in Spring Web Flow 2

In the Web Flow below I bind form data to a flow variable (lifeCycleForm) on a submit event in the view state. I have verified that the name, label and description properties are all populated as expected.
However, when the expression in the action state is evaluated all three properties are null. My form bean is serializable and I am just using simple string properties.
What I am doing wrong?
I am pretty new to Spring WebFlow so I might have missed something obvious.
<var name="lifeCycleForm" class="com.btmatthews.freelancer.lifecycle.portlet.LifeCycleForm" />
<view-state id="createLifeCycle" model="lifeCycleForm">
<binder>
<binding property="name" required="true" />
<binding property="label" required="true" />
<binding property="description" required="false" />
</binder>
<transition on="submit" to="createLifeCycleAction" />
<transition on="cancel" to="lifeCycleCreationCancelled" bind="false" />
</view-state>
<action-state id="createLifeCycleAction">
<evaluate expression="lifeCycleService.createLifeCycle(lifeCycleForm.name, lifeCycleForm.label, lifeCycleForm.description, null, null)" />
<transition on="success" to="lifeCycleCreated" />
<transition on="failure" to="createLifeCycle" />
</action-state>
<end-state id="lifeCycleCreated" />
<end-state id="lifeCycleCreationCancelled" />
Update: I neglected to mention in my original posting that it was my unit tests that were failing. I have since learned that AbstractFlowExecutionTests does not implement binding of request parameters. This seems like a bit of an oversight to me. I have tried latest nightly Spring WebFlow 2.0.4 and the behaviour remains the same.
Update: My problems are that Spring WebFlow mocks do not simulate form submission.
Thanks in advance,
Brian
To much chagrin, I also recently found out that the Webflow testing mocks don't use Spring's binding. Have you tried running the flow using debugging in a container like Tomcat from within an IDE like Eclipse ? If you haven't, it'll be very useful. If you need help, I can provide further tips, but to start I'd say download the Eclipse Web Standard Tools and Web Tools Project plugins if you haven't already.
Just as a side note, if you really want to be able to unit test binding, you can also still use the Spring Webflow 1 FormActions to bind to the model object, even though it will make your flow slightly more verbose.

Categories