I have a Property Mapping (colorMap.xml):
<bean id="B_colorMapping" class="com.project.color.colorMap">
<property name="map">
<map>
<entry key="1" value="blue" />
<entry key="2" value="blue-green" />
<entry key-ref="10" value-ref="B_colorMapping" />
</map>
</property>
</bean>
<bean id="R_colorMapping" class="com.project.color.colorMap">
<property name="map">
<map>
<entry key="1" value="red" />
<entry key="2" value="red-yellow" />
<entry key-ref="10" value-ref="R_colorMapping" />
</map>
</property>
</bean>
And the com.project.color.colorMap codes look like this:
public class colorMap {
private Map<Object, Object> map;
public Map<Object, Object> getMap() {
return map;
}
public void setMap(Map<Object, Object> Cmap) {
map = Cmap;
}
}
Right now, what is happening, I manually update the colorMap.xml by adding entries and values. What I'm planning to do is to create a JSP page to handle the adding of the values in my xml.
for now, I want to display the values of my xml on the JSP page.
For example: (on the JSP page...)
B_colorMapping:
Color Key: 1 Value: blue
Color Key: 2 Value: blue-green
R_colorMapping:
Color Key:1 Value: red
Color Key:2 Value: red-yellow
Can someone offer a help or tip on how to do this? THis is spring MVC (Object, Map, ModelAndView).
I'm stuck on this one.
Related
I need to provide a timeStamp and two signature action with different features,
when we put two signature it understand only first
how we could handle it in cxf?
we should provide custom action
http://cxf.apache.org/docs/ws-security.html
<constructor-arg>
<map>
<entry key="action" value="Timestamp Signature 12345"/>
<entry key="wss4j.action.map">
<map key-type="java.lang.Integer" value-type="java.lang.Object">
<entry key="12345" value-ref="customSignature"/>
</map>
</entry>
and we should create a class
CustomSignatureAction extends SignatureAction {
and override features which different with fist signature
I'm trying to add a simple redirect into a web application built in Restlets, and it's proving non-trivial. The task is a simple one: I want to actually redirect all missing files from a web application to the same static file.
I'm using org.restlet.routing.Redirector with the following values (I'm using Spring injection):
<bean name="router" class="org.restlet.ext.spring.SpringRouter">
<constructor-arg ref="trackerComponentChildContext" />
<property name="attachments">
<map>
<entry key="/api" value-ref="apiRouter" />
<entry key="/statics" value-ref="staticsDirectory" />
<entry key="/" value-ref="staticsRedirector" />
</map>
</property>
</bean>
<bean id="staticsRedirector" class="ca.uhnresearch.pughlab.tracker.restlets.CustomRedirector">
<constructor-arg ref="trackerComponentChildContext" />
<constructor-arg value="{o}/statics/index.html" />
<constructor-arg value="7" />
</bean>
I can play with the file hierarchy relatively simply, but I just want to send anything that doesn't match either /api or /statics to /statics/index.html within the same application.
Restlet is almost getting it, and it does seem now to pick up the reference to the correct file, it just doesn't quite serve it.
I've put a working copy of the whole thing (including Thierry's suggestions below) at: https://github.com/morungos/restlet-spring-static-files. What I'd like to happen is something like the equivalent sequential attempts below:
curl http://localhost:8080/statics/**/* to hit the corresponding /statics/**/*
curl http://localhost:8080 to hit the main /statics/index.html
curl http://localhost:8080/**/* to hit the main /statics/index.html
I made some tests regarding your issue and I can't figure out how to have your message :-(. Perhaps it's because I haven't the whole code.
In fact, I saw a problem at the level of the SpringRouter itself. I would like to attach the redirector with an attachDefault and not an attach("/", ...) / attach("", ...). The method setDefaultAttachment actually does an attach("", ...).
So I made work something with the following updates:
Create a custom SpringRouter
public class CustomSpringRouter extends SpringRouter {
public void setDefaultAttachment(Object route) {
if (route instanceof Redirector) {
this.attachDefault((Restlet) route);
} else {
super.setDefaultAttachment(route);
}
}
}
Create a custom Redirector. I got the context from the component instead of a child context.
public class CustomRedirector extends Redirector {
public CustomRedirector(Component component, String targetPattern, int mode) {
super(component.getContext(), targetPattern, mode);
}
}
I then use the following Spring configuration:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="myComponent" class="org.restlet.ext.spring.SpringComponent">
<property name="defaultTarget" ref="router" />
</bean>
<bean name="router" class="test.CustomSpringRouter">
<property name="attachments">
<map>
<entry key="/api" value-ref="apiRouter" />
<entry key="/statics" value-ref="staticsDirectory" />
</map>
</property>
<property name="defaultAttachment" ref="staticsRedirector" />
</bean>
<bean id="staticsRedirector" class="test.CustomRedirector">
<constructor-arg ref="myComponent" />
<constructor-arg value="{o}/statics/index.html" />
<constructor-arg value="7" />
</bean>
<bean name="apiRouter" class="org.restlet.ext.spring.SpringRouter">
(...)
</bean>
(...)
</beans>
Hope it helps you,
Thierry
I've a properties file like this :
firstproperty=1,2,3,4
secondproperty=47,998,120
thirdproperty=54
My properties file is well defined in my Spring configuration as property for my PropertyPlaceHolderConfigurer bean.
I want to load values in a
HashMap<String, ArrayList<String>>
like this :
<util:map id="properties" map-class="java.util.HashMap">
<entry key="first" value="${firstproperty}" />
<entry key="second" value="${secondproperty}" />
<entry key="three" value="${thirdproperty}" />
</util:map>
The problem is that for each entry, multiple values separated by commas count as one value. I tried to configure value-type of my util-map to an ArrayList but it was unsuccessful. Any idea ?
P.S : I use Spring 3.2.
I searched Spring EL in config file, maybe this is what you want:
<bean id="taxCalculator" class="org.spring.samples.TaxCalculator">
<property name="defaultLocale" value="#{ systemProperties['user.region'] }.split(',')"/>
<!-- other properties -->
I am not sure about the location of split method, you can try yourself to find the correct way. For more details, please refer:http://docs.spring.io/spring/docs/3.0.x/reference/expressions.html
I have several maps defined in my context file. Is there a way to combine those maps into one map that contains all of their entries, without writing Java code (and without using nested maps)? I'm looking for the equivalent of Map m = new HashMap(); m.putAll(carMap); m.putAll(bikeMap);
Seems like there should be a way to do this in Spring context file, but the Spring 3.0 reference doc section on util:map doesn't cover this use case.
<!-- I want to create a map with id "vehicles" that contains all entries of the other maps -->
<util:map id="cars">
<entry key="groceryGetter" value-ref="impreza"/>
</util:map>
<util:map id="bicycles">
<entry key="commuterBike" value-ref="schwinn"/>
</util:map>
Using collection merging concept in Spring, multiple beans like these can be merged incrementally. I used this in my project to merge lists , but can be extended to merge maps as well.
E.g.
<bean id="commonMap"
class="org.springframework.beans.factory.config.MapFactoryBean">
<property name="sourceMap">
<map>
<entry key="1" value="one"/>
<entry key="2" value="two"/>
</map>
</property>
</bean>
<bean id="firstMap"
parent="commonMap"
class="org.springframework.beans.factory.config.MapFactoryBean">
<property name="sourceMap">
<map merge="true">
<entry key="3" value="three"/>
<entry key="4" value="four"/>
</map>
</property>
</bean>
The association of the second map definition with the first one is done through the parent attribute on the <bean> node and the entries in the first map are merged with those in the second using the merge attribute on the <map> node.
I bet there is no direct support for this feature in Spring.
However, writing a factory bean to use in Spring is not that difficult (haven't tried to compile that)
public class MapMerger <K,V> implements FactoryBean {
private Map<K,V> result = new HashMap<K,V>();
#Override
public Object getObject() {
return result;
}
#Override
public boolean isSingleton(){
return true;
}
#Override
public Class getObjectType(){
return Map.class;
}
public void setSourceMaps(List<Map<K,V>> maps) {
for (Map<K,V> m : maps) {
this.result.putAll(m);
}
}
}
In spring config, just do something like:
<bean id="yourResultMap" class="foo.MapMerger">
<property name="sourceMaps">
<util:list>
<ref bean="carMap" />
<ref bean="bikeMap" />
<ref bean="motorBikeMap" />
</util:list>
</property>
</bean>
I have used this code as the basis of my development so far : Ajax Simplifications from springsource.
Here is the html & jquery/javascript code:
<c:url var="Controller" value="/ControllerUrl" />
...
var previewDialog = $("<div></div>").dialog({
//all the dialog setttings
});
$(".opener").click(function() {
previewDialog.load("${Controller}",function(data) {
previewDialog.dialog('open');
});
return false;
});
And the controller :
#RequestMapping(value = "/ControllerUrl", method = RequestMethod.GET)
public String previewDialog(Model model) {
MyClass myClass = new MyClass();
myClass.setTitle("SUCCESS");
model.addAttribute(myClass);
return "dialogContent";
}
This is all almost working, except in dialogContent.jsp (which is indeed opened in my dialog) "SUCCESS" is not printed:
<div id="divContent">
Title : ${myClass.title} <br>
</div>
What am I missing/doing wrong ?
Secondly, what is the besy way to submit json data to server in this context - I attempted using $.ajax() and $.postJSON() but ran into problems as they work differently to the $.load() statement.
Thanks in advance.
Can you try:
In the Controller:
return new ModelAndView("view-name", "myclass", myClass);
In your JSP:
${myClass.title}
The trouble is that this would till return HTML rather than just plain text.
Also, you can probably return json or xml by changing your controller as follows:
#RequestMapping(value = "/ControllerURL", method = RequestMethod.GET, headers="Accept=application/xml, application/json")
public #ResponseBody DealManager homeXmlJson(Locale locale, Model model) {
MyClass myClass = new MyClass();
myClass.setTitle("SUCCESS");
return myClass;
}
Then when you call it using $.getJSON it should return a json representation of the object from which you should be able to extract the title.
Use a tool like REST-Client to see what is returned when you pass different Accept parameters to the controller URL. the parameter being:
Accept: text/html, Accept: application/json, Accept: application/xml
You will have to configure your rest context as well. Here is an example of one I'm using:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jsonConverter" />
<ref bean="marshallingConverter" />
<!-- <ref bean="atomConverter" /> -->
</list>
</property>
</bean>
<!-- Handle JSON Conversions -->
<bean id="jsonConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json" />
</bean>
<!-- Handle XML Conversion -->
<bean id="marshallingConverter"
class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<constructor-arg ref="jaxbMarshaller" />
<property name="supportedMediaTypes" value="application/xml" />
</bean>
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.pack1.app.domain.MyEntity</value>
<value>com.pack1.app.service.MyEntityTwo</value>
</list>
</property>
</bean>
</beans>