Permalink
Browse files

Fix for uploading app using non-ascii file names

 - 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...
1 parent 5e3d82b commit 1378748d60c6c3c58cd3e03dc1a08477eba8110e @trisberg trisberg committed Jun 12, 2012
@@ -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>
@@ -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>
@@ -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;
@@ -77,6 +78,11 @@
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;
@@ -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());
@@ -1,55 +0,0 @@
-/*
- * Copyright 2009-2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.cloudfoundry.client.lib;
-
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.nio.charset.Charset;
-
-import org.springframework.http.HttpOutputMessage;
-import org.springframework.http.MediaType;
-import org.springframework.http.converter.StringHttpMessageConverter;
-import org.springframework.util.FileCopyUtils;
-
-public class StringHttpMessageConverterWithoutMediaType extends StringHttpMessageConverter {
-
- private boolean writeAcceptCharset = true;
-
- @Override
- public void setWriteAcceptCharset(boolean writeAcceptCharset) {
- this.writeAcceptCharset = writeAcceptCharset;
- super.setWriteAcceptCharset(writeAcceptCharset);
- }
-
- @Override
- protected MediaType getDefaultContentType(String t) {
- return null;
- }
-
- /*
- * add extra null check for contentType
- */
- @Override
- protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
- if (writeAcceptCharset) {
- outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
- }
- MediaType contentType = outputMessage.getHeaders().getContentType();
- Charset charset = contentType != null && contentType.getCharSet() != null ? contentType.getCharSet() : DEFAULT_CHARSET;
- FileCopyUtils.copy(s, new OutputStreamWriter(outputMessage.getBody(), charset));
- }
-}
@@ -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());
@@ -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)) {
@@ -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;
/**
@@ -55,6 +56,19 @@ public static File springTravel() throws IOException {
}
/**
+ * 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
* @throws IOException
View
@@ -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>
@@ -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>
@@ -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>
Oops, something went wrong.

0 comments on commit 1378748

Please sign in to comment.