2017-09-04 5 views
1

Ich versuche HTTP.PUT von meinem Maven Plugin zu einem Zielserver zu tun zu tun:korrekte Art und Weise HTTP.PUT

private void uploadFile(Wagon wagon, String fileName, Artifact artifact) throws MojoExecutionException { 
    if (artifact != null) { 
     try { 
      //org.apache.maven.wagon 
      wagon.put(artifact.getFile(), fileName); 

     } catch (TransferFailedException | ResourceDoesNotExistException | AuthorizationException e) { 
      throw new MojoExecutionException("failed", e); 
     } 
    } 
} 

Anfrage

PUT /somepath/myfile.bla HTTP/1.1 
Cache-control: no-cache 
Cache-store: no-store 
Pragma: no-cache 
Expires: 0 
Accept-Encoding: gzip 
Content-Type: application/json 
Authorization: Bearer xxx 
Content-Length: 123 
Host: targethost 
Connection: Keep-Alive 
User-Agent: Apache-HttpClient/4.3.5 (java 1.5) 

Antwort

HTTP/1.1 404 Not Found 
Server: nginx/1.12.1 
Date: Thu, 31 Aug 2017 11:45:18 GMT 
Content-Type: text/html; charset=UTF-8 
Content-Length: 69 
Connection: keep-alive 

Diese scheint mir völlig legitim, aber es scheitert mit 404, wie Sie sehen. Der Betreuer des target sagt mir, dass der Dateiname darf nicht in den Weg und in der Tat enthalten sein, wenn ich es mit curl tun:

curl -v -X PUT -T myfile.bla https://targethost/somepath -H "Authorization: Bearer .." --Capath /path/to -k 

es ergibt sich:

> PUT /somepath HTTP/1.1 
> User-Agent: curl/7.38.0 
> Host: targethost 
> Accept: */* 
> Authorization: Bearer ... 
> Content-Length: 123 
> Expect: 100-continue 

Am versäumt, die PUT als der Betreuer von targetthost erfordert. Ich habe auch versucht

File file = artifact.getFile(); 
((HttpWagon) wagon).putFromStream(new FileInputStream(file), fileName, file.length(), file.lastModified()); 

aber das Ergebnis ist das gleiche. Irgendwelche Hinweise?

+1

haben Sie versucht, 'wagon.put (artifact.getFile(), filename);' aber anstelle des 'Dateiname == targethost/somepath/myfile.bla' benutze 'filename == targethost/somepath /'? – diginoise

+0

Danke für Ihren Kommentar, ich habe einfach das Ziel von putToStream Anruf entfernt und es funktioniert wie erwartet jetzt. –

Antwort

0

Alles, was ich tun musste, war das Ziel aus putFromStream Aufruf zu entfernen:

((HttpWagon) wagon).putFromStream(new FileInputStream(file), "", file.length(), file.lastModified()); 
Verwandte Themen