struts common error forward - struts

How can I use common forward for all actions. I mean I don't want to write common forward in all actions.
<forward name="invalidlogin" path="/invalidlogin.jsp" />
I don't want to write this in all <Actions>.

It sounds like you're just describing a global forward. Global forwards are defined in the struts-config.xml file. That way, the forward is defined for all actions so any action can use the forward.
So you would place something like the following in your struts-config.xml file:
<global-forwards>
<forward name="error" path="jsp/error.jsp"/>
</global-forwards>
Then just forward to "error" in your action class:
return mapping.findForward("error");

Related

Proxy configuration using local-entry or properties

I have configured proxy with following xml:
<parameter name="transport.vfs.FileURI">vfs:file:///data/queues/documents-validation</parameter>
But I would like to use something more manageable than hard coded value. Maybe something like
<parameter name="transport.vfs.FileURI" expression="get-property('source.uri')" />
Any suggestions would be appreciated.
I asked myself the same questions a couple of weeks. Unfortunately there's no way to achive this when you want to pick up files. I was told that this will work in version 4.9.
If you want to have this when you write files than this is no problem. You just need to set the 'to' header parameter and then call the send mediator.
Example:
Regards
Martin

How to create a Spring authentication filter with pattern /**

<sec:http auto-config="false" use-expressions="true" pattern="/**"
authentication-manager-ref="authenticationManager" entry-point-ref="authenticationEntryPoint">
<sec:custom-filter ref="myFilter" position="BASIC_AUTH_FILTER" />
<sec:intercept-url pattern="/**" access="permitAll" />
</sec:http>
HI,
What I'm trying to do seems like it would be so simple, yet i've been trying to figure out how to do it for hours. Hopefully someone can help.
I simply want to create an authentication filter that will intercept all incoming requests, do some processing, then pass it on to the next filter in the chain.
When I try and do that using a pttern of /, I keep getting that error "A universal match pattern ('/') is defined before other patterns in the filter chain, causing them to be ignored. Please check the ordering in your namespace or FilterChainProxy bean configuration" even though i've tried all kinds of things, like guaranteeing my filter is the very last one listed in the security.xml file. I've even attempted to specify the order with a filterChainProxy definition like this:
<beans:bean id="filterChainProxy"
class="org.springframework.security.web.FilterChainProxy">
<sec:filter-chain-map>
<sec:filter-chain pattern="/**"
filters="<filterlist, with mine being the very last!>" />
</sec:filter-chain-map>
</beans:bean>
Nothing seemed to work, despite spending hours researching and googling to try and figure that out, so I gave up, and created an entry in the web.xml file for my filter. Finally, I hit a breakpoint in the filter, so I knew it was getting invoked. But then the problem I ran into was, nothing was getting injected by Spring, I'm assuming because I went "outside the framework", and, I can't even pull the authenticated user, I get a Spring error saying i'm not authenticated, yet other filters defined inside the security.xml can pull it just fine.
I'm not sure what to do here; very suprised something so simply is so difficult.
Please advise, thanks

How can I easily add and remove message conversion logic into a processing flow in Spring Integration?

I've been playing with Spring integration, and I can't see how best to solve the following problem.
Say I have XML messages arriving onto a channel. These messages may have arbitrary structure, and I want to convert them to my canonical form, so I think I want to write custom converters for each type of structure, so that I can do whatever processing and error-checking I want.
The obvious thing is to wire up a router to have a look at the messages and route to an appropriate converter, but I think this means I need to hard-code the processing flow onto a channel pointing at each converter.
I'd like to avoid hard-configuring in the different converters and routing logic, and the alternative that springs to mind is to have a set of converters that implement some kind of boolean canHandle(message), so that we just show the message to each converter until one 'claims' the message or we run out. This way, it seems like I might be able to annotate the converters into the configuration without actually modifying the processing flow.
I'm new to Spring integration and I may well be mis-thinking this. Is there a stock way to do this in Spring integration, have I missed something or am I going about it all wrong?
There are a number of ways to do this. The first one that came to mind is a recipient list router with selector expressions:
<recipient-list-router id="simpleDynamicRouter" input-channel="simpleDynamicInput">
<recipient selector-expression="#handler1.canHandle(payload)" channel="toHandler1"/>
<recipient selector-expression="#handler2.canHandle(payload)" channel="toHandler2"/>
<recipient selector-expression="#handler3.canHandle(payload)" channel="toHandler3"/>
</recipient-list-router>
<transformer ... ref="handler1" />
<transformer ... ref="handler2" />
<transformer ... ref="handler3" />
Where handler1 etc are <bean/>s with your implementation, and canHandle() method.
Another option is to write your own custom dynamic router; there's an example of how to do that here https://github.com/SpringSource/spring-integration-samples/tree/master/advanced/dynamic-ftp

Confusing about Global forward and Action mapping

for example
<global-forwards>
<forward name="welcome" path="/Welcome.do"/>
</global-forwards>
<action-mappings>
<action path="/Welcome" forward="/welcomeStruts.jsp"/>
</action-mappings>
My question is:
When client requests Welcome.do page, the global forward will map the /welcome.do page with the name attribute "welcome". Then in action-mapping it will map between the name in forward tag with the path in action tag so it will know that it should forward to the welcomeStruts.jsp file.
Am I correct?
If not, how can it determine the correct mapping between user's request *.do to the corresponding jsp file?
Thank you
You're not correct. When a request comes in, Struts tries to map the URL or the request with the path of an action. Forwards are not used at this stage.
When the action returns a forward name, Struts first looks for a forward with this name in the forwards of the action, and if not found, it looks in the global forwards.

struts-config.xml file - purpose of input

I am new to struts. I am wondering what input variable here signifies. After some googling, the only conclusive piece of info was this:
Input: The physical page (or another ActionMapping) to which control should be forwarded when validation errors exist in the form bean.
Is there any other use for the input parameter besides the case of an error occurring?
<action
roles="somerole"
path="some/path"
type="some.java.class"
name="somename"
input="someInput"
scope="request"
validate="false"
parameter="action">
<forward name="success" path="some/path"/>
<forward name="download" path="/another/path"/>
</action>
Yes, although you're correct that it's primarily a forward for failed validation.
The input has a dedicated method to return it: ActionMapping.getInputForward(). This can be used in custom (Java-based) validation to return to the input page.
It can also be used to identify a "landing" page: an action base class or custom request processor might send GET requests to the input forward, and process POSTs normally.