URI encoding on JBoss and Spring application - java

We are developing a Spring application which run on JBoss. I've just discovered a problem with characters encoding and #ModelAttribute and #RequestBody annotations when we are sending requests via GET method described in:
Encoding problem using Spring MVC
http://forum.spring.io/forum/spring-projects/web/74209-responsebody-and-utf-8
and possible solution:
http://wiki.apache.org/tomcat/FAQ/CharacterEncoding#Q2
https://developer.jboss.org/message/643825#643825
https://docs.jboss.org/jbossweb/2.1.x/config/http.html
In general we added:
<system-properties>
<property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
<property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
to standalone.xml file on JBoss and this solved the issue.
We just thinking if there is any possibility to keep this properties in our application and use them when needed instead of changing JBoss configuration? Or maybe you know other working solution on the application side instead of server side?

Related

How to modify Wildfly/JBoss config using Spring Boot

I'm migrating a Spring MVC web application to a Spring Boot. The build (maven) generates a .war file then I upload it to Wildfly Server. I used to be able to upload large file now it doesn't work.
On the old way, using Spring MVC, I updated the Wildfly' server config itself /standalone/configuration/standalone-full.xml which no longer work after switching to Spring Boot
<http-listener name="default" socket-binding="http" max-post-size="304857600" redirect-socket="https" enable-http2="true"/>
So the config above says allow posting files up to ~300MB (see the 304857600)
How to modify Wildfly/JBoss config using Spring Boot?
My google search was redirected here by some user comment, but still unsure how to do it in Spring Boot
https://docs.jboss.org/author/display/WFLY10/Undertow+subsystem+configuration
I'm on:
JDK 1.8
spring-boot-2.1.2.RELEASE.jar
spring-core-5.1.2.RELEASE.jar
Wildfly 10.
SpringBoot ask to setup these two additional config parameter to control the size limits of file upload/post request. I am certain that's causing the limitation in your case, if your Wildfly server is configured to not limit it.
#Max file size.
spring.servlet.multipart.max-file-size
#Max Request Size
spring.servlet.multipart.max-request-size
Reference: SpringBoot guide for file upload feature.

Spring Mail with Freemarker Templates from Database

I am a newbie to adding Freemarker to Spring and Spring Mail. I am not using Spring Boot, but I am using the latest Spring 4.x, and though we have an application context XML file, we do use annotations.
So, ultimately I want to read the templates out of a database, because we may have many of them for many clients. We will not be loading templates from a filename or from disk.
We have our Spring Application as a maven multi-module project:
entity.jar - module
dao.jar - module
services.jar - module
ws.jar - module
Under services we have an application context file that defines Freemarker as follow:
<bean id="freemarkerConfiguration"
class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
<property name="preTemplateLoaders">
<list>
<ref bean="databaseTemplateLoader" />
</list>
</property>
</bean>
<bean name="databaseTemplateLoader"
class="com.myapp.server.util.DatabaseToFreeMarkerTemplateLoader" />
I have a new class called:
public class DatabaseToFreeMarkerTemplateLoader extends StringTemplateLoader
{
// todo: add code here
}
But I am not sure what else I need in here. I am looking on the internet for some examples, but I can't find too much.
If someone can point me to an example, or refer me to another link here, I'll do my best to see if I can literally fill in the blanks.
Thanks!
BTW: I am surprised I had to include spring-web in my services layer in order to make this work. I just wanted to format an email and not html pages. So if there a better formatting tool that works seamlessly with Spring, let me know.
I don't know this part of Spring much, but I don't think you need spring-web. You could just use the FreeMarker API directly both for configuring (i.e., create a freemarker.template.Configuration singleton bean) and generating the output (template = configuration.getTemplate(...), template.process(...)). Finally you simply use message.setText(theOutputFromTemplateDotProcess, true); (where message is the Spring MimeMessageHelper). So there's no much to integrate with Spring here, I believe. (Even if someone needs to load templates from Spring resources, they can use an org.springframework.ui.freemarker.SpringTemplateLoader via Configuration.setTemplateLoader.)
As of using FreeMarker API directly (not related to Spring), see this example: http://freemarker.org/docs/pgui_quickstart_all.html

hibernate connection tomcat

I was working in a web site (production) in Tomcat 7, so now I created a copy of this website and change the hibernate.cfg.xml to work with another database ( testing ).
<property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/test</property>
<property name="hibernate.connection.username">fake</property>
<property name="hibernate.connection.password">fake</property>
However, when I open the new new site, everything is ok, but, is still working with the production database even when I changed the connection string.
Anybody knows if I need to change another thing?. I missing something?. I am quite new in tomcat.
Thanks in advance.
Probably the database connection is configured elsewhere, and this is a redundant configuration. Usually it is configured in a data source - check your tomcat xml config files, or any xml config files of your application (if using spring, for example).
Datasources in Tomcat can be configured in context.xml file. Most probably that is the case.
might be production database running on different port instead of 3306.

Spring in Tomcat - what's lacking?

As far as I'm concerned Spring is integrated in Apache Tomcat. Although, when trying to implement session beans, I've encountered an error
The matching wildcard is strict, but no declaration can be found for element 'aop:scoped-proxy'.
on the declaration of bean:
<bean id="loginStorer" class="sef.inerfaces.service.LoginStorer" scope="session">
<aop:scoped-proxy/>
</bean>
As I googled up, that may be because spring-aop.jar is not present in classpath. So, I guess I have to take it from a standalone Spring installation. My question is: am I right to do so, and if yes, what else from Spring is missing in Tomcat?
P.S. Tomcat is of 7.0.6 version.
Consider using Maven for dependency resolution and build.
As for your assumption, it is incorrect. Tomcat does not bundle Spring out of the box.
This really looks like a problem in the spring context file where the namespace for aop has not been mentioned.

JAX-RPC, Spring web services, and UnsupportedOperationCallException

I have a JAX-RPC web service that I am attempting to consume using Spring. This is my first time using Spring to consume a web service, so right now I'm just trying to get it to integrate with the JAX-RPC web service as a test.
The web service has several dozen operations in it, but for right now I only care about one. Here are the interfaces I've created on the Spring/client side:
public interface WSClient {
public boolean userExists(int userid);
}
public interface WSService {
//this method matches the method signature of the Web Service
public com.company.data.User getUser(int userid);
}
And here is my applicationContext.xml:
<bean id="WSClient" class="com.company.ws.test.WSClientImpl">
<property name="service" ref="myWebService"></property>
</bean>
<bean id="myWebService" class="org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean">
<property name="serviceInterface" value="com.company.ws.test.WSService"/>
<property name="endpointAddress" value="http://1.2.3.4/web-service/data"/>
<property name="namespaceUri" value="http://www.company.com/wdsl"/>
<property name="serviceName" value="CompanyWebService"/>
<property name="username" value="username"/>
<property name="password" value="password"/>
<property name="maintainSession" value="true"/>
</bean>
Using this configuration of JaxRpcPortProxyFactoryBean, invoking the Service returns the following exception:
org.springframework.remoting.RemoteProxyFailureException: Invalid JAX-RPC call configuration; nested exception is operation style: "rpc" not supported
I've never fully understood the difference between RPC and document-style web services; however, I believe this web service is using RPC-style - so this exception confuses me.
Second, I'm confused on which properties I should be setting with JaxRpcPortProxyFactoryBean:
If I set the wsdlDocumentUrl property, I end up getting a HTTP 401 error as this web service sits behind HTTP Basic Authentication, and it seems Spring does not use the username/password properties when fetching the WSDL.
If I specify a PortInterface property (with a value of CompanyWebServiceInterfacePort), then I get a different Exception stating:
Failed to initialize service for JAX-RPC port [{http://www.company.com/wdsl}CompanyWebServiceInterfacePort]; nested exception is WSDL data missing, this operation is not available
In other words, it's telling me that the WSDL is missing - which I can't set since Spring won't use the username/password to fetch it from the server!
I'm not sure if any of this makes any sense, but in essence what I'm unsure of is:
For a JAX-RPC service, do I need to set the PortInterface property? Is this the path I should be going down?
Similiarly, does Spring need me to set the wsdlDocumentUrl property? If so, is there any way I can tell Spring which WSDL and get around the authentication problem?
I eventually solved this by saving a copy of the WSDL file locally, and, since JaxRpcPortProxyFactoryBean expects a java.net.URL for the wsdlDocumentUrl property, had to set it with a path like file:///c:/.../blah.wsdl.
This isn't really all that desireable, I would hate to have to put a file:/// URI in a Spring context file that might be deployed on a server, especially on a different platform - seems odd that this class behaves this way.
I'm guessing most people aren't using Spring aren't using JAX-RPC anyway.

Categories