How can I configure AOP in ColdSpring 2.0? - coldfusion

I'd like to implement some before and after method advisors in Coldspring 2.0, and I'd like to use the new schema for AOP and the new autoproxying feature. Unfortunently, the Narwhal documentation for AOP is currently a cliffhanger. Can anyone give me an example of a Coldspring 2.0 configuration file that uses the AOP schema?

I just finished off 1 more section in the AOP documentation, but in the mean time, here are a few examples to get the ball rolling.
This is an example of setting up around advice. It calls the method timeMethod on the object timer, that matches the pointcut of execution(public * *(..)), which translated to: a method execution, that is public, that returns anything, that is named anything, and takes any arguments, of any types. Essentially, it matches everything.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.coldspringframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.coldspringframework.org/schema/aop"
xsi:schemaLocation="http://www.coldspringframework.org/schema/beans http://coldspringframework.org/schema/coldspring-beans-2.0.xsd
http://www.coldspringframework.org/schema/aop http://www.coldspringframework.org/schema/coldspring-aop-2.0.xsd"
>
<!-- AOP configuration -->
<aop:config>
<aop:aspect ref="timer">
<aop:around method="timeMethod"
pointcut="execution(public * *(..))"/>
</aop:aspect>
</aop:config>
<bean name="timer" class="05_AOP.Timer" />
<bean name="longTime" class="05_AOP.LongTime" />
</beans>
The important piece to note, is that while Time.cfc is just a plain ol' CFC, for it to do the around advice, the method that is being used has to take a MethodInvocation as an argument, like so:
public any function timeMethod(required MethodInvocation invocation)
{
...
}
But there you go, there is an example of using AOP in CS2.
You can still use MethodInterceptors and the like as well, but you will be using <aop:advisor> rather than <aop:aspect>.
But overall, I'm working on the CS2 AOP documentation right now, so it should get filled out in the next day or so.

DOC RELEASED! http://sourceforge.net/apps/trac/coldspring/

Related

Changing default base URL of Sitecore ServiceApiController, Is it possible?

when we implement SitecoreApiController, for each action method we make using Sitecore.Services.Core.ServicesController("namespace") attribute, we get a url like this:
/sitecore/api/ssc/{namespace}/{controller}/{id}/{action}
I wonder if we could change this default pattern, somehow in config files. I particularly interested in /sitecore/api/ part, because sometimes in the sense of security concerns, certain clients don't like to reveal that much about CMS platform behind the scene. Sometimes they even ask us to hide anything in HTTP header that tells about Microsoft ASP.NET explicitly.
Is this possible here?
Edit
this link shows a way to customize it using pipelines but I wonder if we could change the base url just through config files without needing a custom pipeline
I had a look at it, and I think I found out how - although I haven't tested it.
It looks for a setting named Sitecore.Services.RouteBase and if it can't find it, it uses sitecore/api/ssc/ as the default value.
You should be able to change it with a config patch like this in the App_Config/Include folder:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="Sitecore.Services.RouteBase" value="custom/api/" />
</settings>
</sitecore>
</configuration>

Extending <redirect:write> in xalan

In my project, I have used the function which xaln provided. Now I need to write another function to fix the meta data of the file which is generated by . So the code just like below:
<redirect:write file="file.html">
<xsl:variable name="meta_fix" select="MetaFix:fix(string,string('file.html'))" /> //call the fix function which is an external java function.
However, what i really want is to extend the xalan redirect function and make a customize tag which will be processed just like the
<customize:write file="file.html" fixMeta="t" />
//or
<redirect:customize-write file="file.html" fixMeta="t" />
How can I extend the xalan write function and make the xalan understand my customize tag?
I believe it's possible to plug an Entity Resolver into Xalan which will be able to review and rewrite URIs, which might let you put your hint into the URI rather than a separate flag variable or attribute. Check the documentation on Apache.
Or I suppose you could try copying the logic of redirect: out of the guts of xalan and adapting apprpriately, then plugging it in as an extension element. I don't remember whether extensions would be able to access enough of xalan's guts to make that work, though, and persionally I wouldn't try it since you'd be making your stylesheets extremely nonportable.

How to specify both jaxws and jaxb bindings to achieve #XmlRootElement

I've inherited a project that communicates with a SOAP-based web service. I'm a total noob at this, although have been doing Java for many years and have done a good bit with XML.
We have a WSDL file for the service, which contains the schema at the top and all the message definition stuff below. At the core of the problem, when I try to connect to the service through our code, I get the dreaded unable to marshal type "https.api_blah_com.services.v4.Product" as an element because it is missing an #XmlRootElement annotation]
My project already has a jaxws binding file:
<jaxws:bindings wsdlLocation="../resources/wsdl/BlahAPI.wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
<jaxws:bindings
node="wsdl:definitions/wsdl:types/xs:schema[#targetNamespace='https:api.blah.com/services/v4']">
<jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xjc:generateElementProperty>true</xjc:generateElementProperty>
</jxb:globalBindings>`
</jaxws:bindings>
</jaxws:bindings>
Now I've read that in order to get all my Java classes generated with #XmlRootElement, I need to add a jaxb:globalBinding turning on simple mode.
I've tried adding to my local copy of the WSDL this:
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings>
<xjc:simple />
</jaxb:globalBindings>
</xs:appinfo>
</xs:annotation>
But the JAXB compiler complains that it cannot honor this globalBindings customization because it's attached to a wrong place or is inconsistent with other bindings.
So I tried adding another bindings file, just for jaxb, like so:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxb:bindings schemaLocation="../resources/wsdl/blah.wsdl">
<jaxb:globalBindings>
<xjc:simple />
</jaxb:globalBindings>
</jaxb:bindings>
</jaxb:bindings>
But then I get an error that blah.wsdl is not part of this compilation.
I am so close to calling this service...I just cannot get past this one thing, and it's all new to me so I'm not sure what else to try.
I could split out their WSDL into an XSD and a WSDL? Is that required to make this work?
I think you have to bind the xsd file not wsdl at this location. <jaxb:bindings schemaLocation="../resources/wsdl/blah.wsdl">. Please refer to section "External Binding Customization Files" at link.
Not sure if JAXB Binding is configured correctly. The #XmlRootElement required if class forms the root of your element structure. However in SOAP, SOAP element would form root of the XML, Hence check if your ObjectFacory.java class is generated, if generated verify if a method is created for the class type which returns an instance of the class type for example you have class Foo an method `public Foo createFoo() which returns instance of Foo should be present in your ObjectFoacory.java
However I would suggest you to use CXF provided WSDL2java this with client option enabled. It takes few minutes to configure a client code

Configuring Unity (2.x) to use Moq as implementation via app.config

I am using Unity for IOC. I would like to configure the creation of moq objects using the app.config.
My config looks some like this:
<unity xmlns="schemas.microsoft.com/practices/2010/unity">
<container>
<register type="Namespace1.IFoo, FooInterface"
mapTo="Namespace2.FooImp, FooImplementation">
</register>
</container>
</unity>
I am looking for a technique to specify a configuration some like this:
<unity xmlns="schemas.microsoft.com/practices/2010/unity">
<container>
<register type="Namespace1.IFoo, FooInterface"
mapTo="Moq.Mock<IFoo>, Moq">
</register>
</container>
</unity>
I Know that I have to access .Object property of a Mock but this sample is just meant to explain what I want to do.
In other words: I do not want to use code to configure unity to use moq. An option would of course be to create some helpers that can be used in general.
After no one could help I figured something out.
Use a Factory for moq and add a factory resolution via unity
sample goes here

How to use interceptor on the default page?

Here's my situation : in the webapp, I use an interceptor to set the language(Locale).
If a user is logged, I used the language property of this user.
Else if a cookie is set, I use the value of this cookie.
Else, I use the setting of the browser.
It works well when I navigate into the app and when I am logged.
The problem is at the welcome page, since it calls mydomain.com/index.jsp, it don't go through the interceptors so the language isn't set(it's always using the browser setting).
Is there a way to go through the interceptors on the index page or to set the Locale value in the index.jsp page ?
Thank you!
The solution :
I removed the .jsp from the index.jsp in the web.xml file :
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
I added the index action to my struts.xml file :
<default-action-ref name="index" />
<action name="index">
<interceptor-ref name="appStack" />
<result name="success">index.jsp</result>
</action>
The language interceptor is part of the appStack.
Thank you guys for your helps!
I recommend that you do one of two things: (your choice)
(1) Implement your logic in a web filter and have your container configured with this filter so you can set the language (if not already set). This is easy to do, just look at any example of a HelloWorld filter.
or...
(2) Make sure that your home page is only reachable as a Struts2 action (you can define a default action in your Struts2 config file) and ensure that your interceptor is part of the default stack.
Hope that helps!
I would just add the conventions plugin (struts2-conventions-plugin-x.x.x.jar) where x.x.x is the version you are using.
Then I would move all the public jsp's under /WEB-INF/content and be done.
In your web.xml I don't mention any welcome files... but if you would like to be explicit:
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
If using Struts 2.2.1 your web.xml should minimally look like...
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>action</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>action</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
If you want to do it the struts.xml way then just move the index.jsp under /WEB-INF and create an action mapping for it... something like:
<action name="index">
<result>/WEB-INF/index.jsp</result>
</action>
which would be in a package with namespace "/" or "".
On the other hand I haven't looked at the Local stuff in a while but are you sure you're not reinventing the wheel... the i18n interceptor is already in the default stack.
Look into it's use. Long story short there are language property files defined for each language. If Struts2 has determined such properties are in use then then the struts tags will search the value in its name attribute for a matching string in the property file and return the value of that map entry.
It all works pretty slick. Sorry if this is what you are already doing but on the chance you didn't know it should save you a lot of time.