Japanese characters cannot be seen in Spring Batch Admin UI - spring-batch-admin

Japanese characters cannot be seen in Spring Batch Admin UI.
My code is as the following:
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
stepContribution.setExitStatus(new ExitStatus("SKIPPED", "例パラメータ does not exist."));
}
But it displayed Exit Message as the following:
How can I do to display the japanese characters in Spring Batch Admin UI??
I used SpringBatchAdmin 1.0.0.

When I set the UTF-8 encoding in freemarker template, Japanese character can be shown in Spring Batch Admin UI.
There are 2 ways to solve the problem:
Using SpringBatchAdmin 1.2.2 and above because I found that the problem had already fixed on SpringBatchAdmin 1.2.2.
Overriding the resources-context.xml under /META-INF/spring/batch/servlet/resources/ of spring-batch-admin-resources-1.0.0.RELEASE.jar
Since the first way is not ok for me, I use the second way.
I create an xml file under /META-INF/spring/batch/servlet/override/ to override the resources-context.xml.
I add the contentType property in standard bean.
Here is the snippet of newly created xml file:
<bean id="standard" parent="parentLayout">
<property name="url" value="/layouts/standard.ftl" />
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="attributes">
<props merge="true">
<prop key="body">/layouts/home.ftl</prop>
<!-- Matches the prefix of the servlet mapping in web.xml -->
<prop key="servletPath">#{resourceService.servletPath}</prop>
</props>
</property>
</bean>
Hope this will help the others also. :)

Related

Reading method-level properties using JUnit + spring-test

What is the best way to use spring-test with JUnit to read property files specific to a test method?
The following bean illustrates the intent to search method-level, then class-level, then package-level, then root-level property files:
<bean name="properties" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer" >
<property name="locations">
<list>
<value>classpath:properties.xml</value>
<value>classpath:*/properties.xml</value>
<value>classpath:*/*/properties.xml</value>
<value>classpath:*/*/*.properties.xml</value>
</list>
</property>
</bean>
I've considered using/subclassing PropertySourcesPlaceholderConfigurer or SpringMethodRule, but so far, neither a viable nor elegant solution has occurred to me. spring-test offers a variety of promising class-level annotations, but the stumbling block is that I want to be able to find a method-specific file, e.g.:
classpath:myPackage/myClass/myMethod.properties.xml
If you are just looking for an algorithm that helps you to look up classpath resources based on the current method, you can take inspiration from the ServletTestExecutionListener in the Spring TestContext Framework, specifically the detectDefaultScript() method.
Regards,
Sam (author of the Spring TestContext Framework)

CAS primaryAuthenticationHandler ldapAuthenticationHandler

I think I've exhausted searching and need to ask this seemingly very popular question about CAS configuration for Active Directory. I followed the steps on CAS docs to modify the deployerConfigContext.xml to include the ldapAuthenticationHandler bean.
But seems like CAS is continuing to use AcceptUsersAuthenticationHandler defined in the same file in the primaryAuthenticationHandler tag.
Question: So basically I need to replace AcceptUsersAuthenticationHandler with ldapAuthenticationHandler as the default authenticator. What is the correct syntax to do so in the following snippet?
<bean id="primaryAuthenticationHandler"
class="org.jasig.cas.authentication.AcceptUsersAuthenticationHandler">
<property name="users">
<map>
<entry key="casuser" value="Mellon"/>
</map>
</property>
</bean>
This is what I have tried so far:
<bean id="primaryAuthenticationHandler" class="org.jasig.cas.authentication.LdapAuthenticationHandler"></bean>
java.lang.NoSuchMethodException: org.jasig.cas.authentication.LdapAuthenticationHandler.<init>()
<bean id="primaryAuthenticationHandler" class="org.jasig.cas.authentication.ldapAuthenticationHandler"></bean>
java.lang.ClassNotFoundException: org.jasig.cas.authentication.ldapAuthenticationHandler
<bean id="primaryAuthenticationHandler" class="ldapAuthenticationHandler"></bean>
java.lang.ClassNotFoundException: ldapAuthenticationHandler
Did you add the dependency in pom.xml?
<dependency>
<groupId>org.jasig.cas</groupId>
<artifactId>cas-server-support-ldap</artifactId>
<version>${cas.version}</version>
</dependency>
Indeed, LdapAuthenticationHandler doesn't implement a default constructor, you need to configure a org.ldaptive.auth.Authenticator on the attribute c:authenticator-ref:
<bean id="ldapAuthenticationHandler"
class="org.jasig.cas.authentication.LdapAuthenticationHandler"
p:principalIdAttribute="mail"
c:authenticator-ref="authenticator"/>
LDAP authentication is not as simple as the default hardcoded user/password authentication handler. In this link you can see an example on how to configure a connection to Active Directory: Active Directory Authentication
Following the example, you will find in "LDAP Properties Starter" some properties defined. You will need to copy them to the file cas.properties on the same folder as deployerConfigContext.xml. You have to adjust the properties to your usecase and be aware that some of the properties names don't correspond with the ones on the xml examples.

Issue upgrading from Jackson 1.9 to 2.5 using Spring 3.1.2 - ProviderBase class not found

I'm trying to upgrade a current project from Jackson 1.9 to 2.5. Everything was going well until I tried to startup my WAS 7 server and receive this error:
org.springframework.beans.factory.CannotLoadBeanClassException: Error
loading class
[com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider] for bean
with name 'jaxbProvider' defined in ServletContext resource
[/WEB-INF/spring/applicationContext-configuration.xml]: problem with
class file or dependent class; nested exception is
java.lang.NoClassDefFoundError:
com.fasterxml.jackson.jaxrs.base.ProviderBase
This appears to be in relation to trying to register the Jackson Provider in my web.xml below:
<!-- Jackson Provider -->
<bean id="jaxbProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider" >
<property name="mapper" ref="jacksonObjectMapper"/>
</bean>
<bean id="jacksonObjectMapper" class="com.fasterxml.jackson.databind.ObjectMapper" >
<property name="annotationIntrospector" ref="jacksonAnnotationIntrospector"></property>
</bean>
<bean id="jacksonAnnotationIntrospector" class="com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair" >
<constructor-arg ref="primaryAnnotationIntrospector" />
<constructor-arg ref="secondaryAnnotationIntrospector" />
</bean>
<bean id="primaryAnnotationIntrospector" class="com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector" />
<bean id="secondaryAnnotationIntrospector" class="com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector" />
I have the following jars on my classpath:
jackson-annotations-2.5.0.jar
jackson-core-2.5.0.jar
jackson-databind-2.5.0.jar
jackson-jaxrs-json-provider-2.5.0.jar
jackson-module-jaxb-annotations.2.5.0.jar
Now from my understanding its looking for this fellow:
com.fasterxml.jackson.jaxrs.base.ProviderBase
but can't find it. A google search reveals that class as belonging to a
jackson-jaxrs-provider project, but I can't find a specific jar for that. I think that's because that is just a base for the jackson-jaxrs-json-provider.2.5.0.jar that I already included. So shouldn't it inherently be able to see that base class through the jackson-jaxrs-json-provider.2.5.0.jar??
If anyone has an idea of what could be wrong I would be very appreciative!
Thanks.
If you used Maven, adding jackson-jaxrs-json-provider as a dependency, you will see all the following pulled in
(I had an image from another post with v2.2.3- disregard the version)
As you can see, it does depend on a jackson-jaxrs-base, which is where the ProviderBase is located.
You can download it here (just click the 2.5.0, then the Download Bundle)

Spring 3 with json and xstream output not working

I have this working now now, but am lost as to why this problem occurred..
I followed the following
http://pfelitti87.blogspot.co.uk/2012/07/rest-services-with-spring-3-xml-json.html
but i changed the controller method and added #ResponseBody...
#ResponseBody
#ResponseStatus(HttpStatus.OK)
#RequestMapping(value="/names", method=RequestMethod.GET)
public List<Book> getNames() {
return returnData();
}
By adding this i noticed that the output would appear as json, regardless of the extension i specified?...
Any ideas why #RepsonseBody would cause this issue?
The post only works for resolving different views based on different types. It does not work on your case.
If you are using Spring 3.2.x, the configuration below would solve your problem.
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager"/>
<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="true"/>
<property name="mediaTypes">
<value>
json=application/json
xml=application/xml
</value>
</property>
<property name="defaultContentType" value="application/json"/>
</bean>
However, if you are using 3.1.x, there are approaches like http://tedyoung.me/2011/07/28/spring-mvc-responsebody and http://springinpractice.com/2012/02/22/supporting-xml-and-json-web-service-endpoints-in-spring-3-1-using-responsebody that might help you.

Spring MVC and JSON, Jackson class not found exception

I cant get Spring's JSON support working. In my spring-servlet.xml file i have included following lines:
<mvc:annotation-driven/>
<context:component-scan base-package="my.packagename.here" />
<context:annotation-config />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
<bean id="jacksonMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
I have also downloaded jackson libraries and added them to my eclipse project and also to WEB-INF/lib folder. When sending request to controller with jQuery getJSON method i get following errors:
javax.servlet.ServletException: Servlet.init() for servlet dispatcher threw exception
java.lang.NoClassDefFoundError: org/codehaus/jackson/JsonProcessingException
java.lang.ClassNotFoundException: org.codehaus.jackson.JsonProcessingException
What do you think is the problem. I'm guessing it has something to do with my spring-servlet.xml file. I can paste entire error log, if you need.
For Jackson v2 jars, class to be used for bean should be
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
For older jackson version, org.springframework.http.converter.json.MappingJacksonHttpMessageConverter is ok. Make sure the jar files are added to the project library.
The answer of anshul tiwari partially captures the problem. Here is a more complete answer ...
When Jackson made it to version 2.0, the core library got changed from jackson-core-asl-x.x.x.jar to jackson-core-x.x.x.jar. With that, the paths changed. In version 1, org.codehaus.jackson was the path. In version 2, it is in com.fasterxml.jackson.core if you were to open up the jar file.
Now if you have the libraries of version 2 and you are seeing the org.codehaus.jackson ClassNotFoundException, it means that there is a mixing of versions. Some code is expecting v1 but you have provided v2. This is certainly possible when using Spring so you have to be careful to choose the correct jar file for your code.
EDIT
In fact, looking at 3.2 Spring source code, org.springframework.http.converter.json.MappingJacksonHttpMessageConverter still references the org.codehaus stuff so this is a case where Spring source code needs to import the correct path and there is nothing you the developer can do to use jackson 2.
JsonProcessingException is part of the jackson-core-asl-x.x.x.jar. Make sure that it's part of your classpath.
Just to complement anshul tiwari answer, the bean tag should go inside mvc:annotation-driver:
<mvc:annotation-driven>
<mvc:message-converters>
<bean
class="org.springframework.http.converter.ResourceHttpMessageConverter" />
<!-- <bean -->
<!-- class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"
/> -->
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
<!-- <bean -->
<!-- class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"
/> -->
</mvc:message-converters>
</mvc:annotation-driven>
Use it Like below : Hope it will work..
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"
default-lazy-init="true">
<context:component-scan base-package="com.vc.bmp.resource" />
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<!-- property name="prefixJson" value="true" />
<property name="supportedMediaTypes" value="application/json" /-->
<property name="objectMapper">
<bean class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="serializationInclusion">
<value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
</property>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>