Skip to content

Commit

Permalink
Fix for uploading app using non-ascii file names
Browse files Browse the repository at this point in the history
 - setting json/application mediatype and utf-8 character set for StringHttpMessageConverter

 - adding vcap-java-client-test-apps module to build war files for integration tests

Change-Id: Ib2bff737eecfae173a5ae8675d561629ff5fe972
  • Loading branch information
Thomas Risberg committed Jun 15, 2012
1 parent 5e3d82b commit 1378748
Show file tree
Hide file tree
Showing 16 changed files with 462 additions and 58 deletions.
40 changes: 40 additions & 0 deletions cloudfoundry-client-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@
<artifactId>commons-io</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.cloudfoundry.test</groupId>
<artifactId>non-ascii-file-name</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version>
<type>war</type>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -150,7 +157,40 @@
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-test-app</id>
<goals>
<goal>copy</goal>
</goals>
<phase>generate-test-resources</phase>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.cloudfoundry.test</groupId>
<artifactId>non-ascii-file-name</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version>
<type>war</type>
<outputDirectory>${project.build.directory}/generated-test-resources</outputDirectory>
</artifactItem>
</artifactItems>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>${project.build.directory}/generated-test-resources</directory>
</testResource>
</testResources>
</build>

<distributionManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -77,6 +78,11 @@ public class CloudFoundryClient {
private static final String AUTHORIZATION_HEADER_KEY = "Authorization";
private static final String PROXY_USER_HEADER_KEY = "Proxy-User";

private static final MediaType JSON_MEDIA_TYPE = new MediaType(
MediaType.APPLICATION_JSON.getType(),
MediaType.APPLICATION_JSON.getSubtype(),
Charset.forName("UTF-8"));

private RestTemplate restTemplate = new RestTemplate();
private URL cloudControllerUrl;

Expand Down Expand Up @@ -138,7 +144,8 @@ private FormHttpMessageConverter getFormHttpMessageConverter() {

private List<HttpMessageConverter<?>> getFormPartsMessageConverters() {
List<HttpMessageConverter<?>> partConverters = new ArrayList<HttpMessageConverter<?>>();
StringHttpMessageConverter stringConverter = new StringHttpMessageConverterWithoutMediaType();
StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
stringConverter.setSupportedMediaTypes(Collections.singletonList(JSON_MEDIA_TYPE));
stringConverter.setWriteAcceptCharset(false);
partConverters.add(stringConverter);
partConverters.add(new ResourceHttpMessageConverter());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,9 @@ public void infoForUserAvailableWithBearerToken() throws Exception {

assumeTrue(token.toLowerCase().startsWith("bearer"));
String rawToken = token.substring("bearer ".length());
client = new CloudFoundryClient(rawToken, client.getCloudControllerUrl().toString());
CloudFoundryClient bearerTokenClient = new CloudFoundryClient(rawToken, client.getCloudControllerUrl().toString());

CloudInfo info = client.getCloudInfo();
CloudInfo info = bearerTokenClient.getCloudInfo();

assertNotNull(info.getName());
assertNotNull(info.getSupport());
Expand Down Expand Up @@ -811,6 +811,32 @@ public void uploadSinatraApp() throws IOException {
assertEquals(AppState.STARTED, env.getState());
}

@Test
public void uploadAppWithNonAsciiFileName() throws IOException {
String appName = namespacedAppName("non-ascii-file-name");
List<String> uris = new ArrayList<String>();
uris.add(computeAppUrl(appName));

File war = SampleProjects.nonAsciFileName();
List<String> serviceNames = new ArrayList<String>();

client.createApplication(appName, CloudApplication.SPRING,
client.getDefaultApplicationMemory(CloudApplication.SPRING), uris, serviceNames);
client.uploadApplication(appName, war.getCanonicalPath());

CloudApplication app = client.getApplication(appName);
assertNotNull(app);
assertEquals(AppState.STOPPED, app.getState());

client.startApplication(appName);

app = client.getApplication(appName);
assertNotNull(app);
assertEquals(AppState.STARTED, app.getState());

client.deleteApplication(appName);
}

private boolean hasApplication(List<CloudApplication> applications, String targetName) {
for (CloudApplication application : applications) {
if (application.getName().equals(targetName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.FileCopyUtils;

/**
Expand All @@ -54,6 +55,19 @@ public static File springTravel() throws IOException {
return file;
}

/**
* Returns a spring application using a file with a non-ascii name.
*
* @return the non-ascii-file-name WAR file
* @throws IOException
*/
public static File nonAsciFileName() throws IOException {
ClassPathResource cpr = new ClassPathResource("non-ascii-file-name.war");
File file = cpr.getFile();
assertTrue("Expected test app at " + file.getCanonicalPath(), file.exists());
return file;
}

/**
*
* @return The directory containing a simple standalone Ruby script
Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>vcap-java-client-test-apps</module>
<module>cloudfoundry-client-lib</module>
<module>cloudfoundry-maven-plugin</module>
<module>cloudfoundry-caldecott-lib</module>
Expand All @@ -23,6 +24,7 @@
<profile>
<id>integration-test</id>
<modules>
<module>vcap-java-client-test-apps</module>
<module>cloudfoundry-client-lib</module>
<module>cloudfoundry-maven-plugin</module>
<module>cloudfoundry-caldecott-lib</module>
Expand Down
150 changes: 150 additions & 0 deletions vcap-java-client-test-apps/non-ascii-file-name/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.cloudfoundry.test</groupId>
<artifactId>non-ascii-file-name</artifactId>
<name>non-ascii-file-name</name>
<packaging>war</packaging>
<version>0.1.0.BUILD-SNAPSHOT</version>
<properties>
<java-version>1.6</java-version>
<org.springframework-version>3.1.0.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.9</org.aspectj-version>
<org.slf4j-version>1.5.10</org.slf4j-version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>

<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>

<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>

<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
<id>repository.springframework.maven.milestone</id>
<name>Spring Framework Maven Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>non-ascii-file-name</warName>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit 1378748

Please sign in to comment.