2

I need to set a http header "Content-Type: application/json" when uploading my test data with wagon:upload. I am setting the server as described in: Advanced Configuration of the HttpClient HTTP Wagon

Here is my wagon configuration in the pom.xml:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>wagon-maven-plugin</artifactId>
  <version>1.0</version>
  <configuration>
    <serverId>wagon-upload-test-data</serverId>
    <url>http://localhost:8000/</url>
    <fromDir>${project.basedir}/src/test/resources/testdata/</fromDir>
  </configuration>
  <executions>
    <execution>
      <id>upload-test-resources</id>
      <phase>generate-test-resources</phase>
      <goals>
        <goal>upload</goal>
      </goals>
    </execution>
  </executions>
</plugin>

And here is the maven settings configuration of the servers:

<settings>
...
  <servers>
    <server>
      <id>wagon-upload-test-data</id>
      <configuration>
        <!-- also tried with and without global configuration -->
        <httpHeaders>
          <httpHeader>
            <name>Content-Type</name>
            <value>application/json</value>
          </httpHeader>
        </httpHeaders>
        <httpConfiguration>
          <all>  <!-- also tried with put -->
            <useDefaultHeaders>false</useDefaultHeaders> <!-- tried with true -->
            <headers>
              <header>
                <name>Content-Type</name>
                <value>application/json</value>
              </header>
              <header>
                <name>Accept</name>
                <value>*/*</value>
              </header>
            </headers>      
          </all>
        </httpConfiguration>
      </configuration>
    </server>
  </servers>
</settings>

When I call the plugin, it executes fine, my test data is being put on the server, but the server settings seem to be ignored - here is the HTTP PUT request that I always get on my test server:

cache-control: no-cache
cache-store: no-store
pragma: no-cache
expires: 0
accept-encoding: gzip
content-length: 132
host: localhost:8000
connection: Keep-Alive
user-agent: Apache-HttpClient/4.3.5 (java 1.5)
x-php-ob-level: 0

{
  "users": [{
    "username" : "dummyMachine",
    "score" : 3456
  }, {
    "username" : "dumminister",
    "score" : 4125
  }]
}

In order to make sure that the correct maven settings file was used, I also ran wagon:upload with the -X tag, here are some logs:

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T18:41:47+02:00)
Maven home: /usr/local/Cellar/maven/3.3.9/libexec
Java version: 1.8.0_92, vendor: Oracle Corporation
...
Reading global settings from /usr/local/Cellar/maven/3.3.9/libexec/conf/settings.xml
[DEBUG] Reading user settings from /Users/martindobrev/.m2/settings.xml
---> COMMENT: THE SETTINGS FILE USED IS THE CORRECT ONE !!! 
...
...
[DEBUG] Goal:          org.codehaus.mojo:wagon-maven-plugin:1.0:upload (default-cli)
[DEBUG] Style:         Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <excludes>${wagon.excludes}</excludes>
      <followSymLink default-value="false">${wagon.followSymLink}</followSymLink>
      <fromDir default-value="${project.basedir}">/PATH_TO_M/src/test/resources/testdata/</fromDir>
      <includes>${wagon.includes}</includes>
      <optimize default-value="false">${wagon.optimize}</optimize>
      <project default-value="${project}"/>
      <serverId default-value="serverId">wagon-upload-test-data</serverId>
      <settings default-value="${settings}"/>
      <skip default-value="false">${wagon.skip}</skip>
      <toDir default-value="">${wagon.toDir}</toDir>
      <url>http://localhost:8000/</url>
      <useDefaultExcludes default-value="true">${wagon.useDefaultExcludes}</useDefaultExcludes>
    </configuration>

What am I doing wrong? Can someone please help me fix this problem!!!

ADDITIONAL INFO: 13.10.2016

I tried different versions of maven and wagon-upload - nothing seems to work. Here is a simple project on github to test the problem

maddob
  • 989
  • 1
  • 12
  • 29
  • 1
    Are you overriding the wagon provider on the command line with `-Dmaven.wagon.provider.http`? By default, [it is lightweight](https://maven.apache.org/guides/mini/guide-wagon-providers.html), which provides the `` configuration. – Tunaki Oct 11 '16 at 09:16
  • No, I am not overriding the default provider - shall I? – maddob Oct 11 '16 at 09:19
  • 1
    You can try to set `httpclient` in your `` element for your server settings, still not sure if that will solve anything. – Tunaki Oct 11 '16 at 09:26
  • I tried both options - setting in xml and setting with parameter (-D...) , still nothing, but thanks for the idea – maddob Oct 11 '16 at 09:30
  • 1
    So I tried to debug this and I think you're out of luck. It simply cannot work with Maven 3.3.9 IMO. The `` element is not read (gory details is that it is a class called `DefaultWagonManager` from `maven-compat` that is used and that class doesn't do it). I have no idea how to make it work here, try mailing the Maven dev list. – Tunaki Oct 11 '16 at 14:20
  • Thanks for your effort @Tunaki !!! – maddob Oct 11 '16 at 14:47
  • FYI, I found a recent issue mentioning something close to this [WAGON-468](https://issues.apache.org/jira/browse/WAGON-468). – Tunaki Nov 28 '16 at 17:39

0 Answers0