Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
31492bf
[bugfix] Make sure streams are closed
adamretter Oct 18, 2015
15b624a
[refactor] When building results use Streams for Binary Content and R…
adamretter Oct 18, 2015
d59b340
[feature] Maven POM files for EXPath HTTP Client
adamretter Oct 18, 2015
e759009
[refatcor] Move files to standard project layout
adamretter Oct 18, 2015
d11dfed
[bugfix] Fix the compilation with Mime4j 0.8.1
adamretter Aug 17, 2017
1ff2593
[feature] Added an assembly for the EXPath HTTP Java Client
adamretter Oct 18, 2015
e0e38ea
[bugfix] Ensure chunked transfer encoding for HTTP 1.1
adamretter Aug 17, 2017
f392ef9
[bugfix] Avoid "null" in some error messages, as the message from Apa…
adamretter Aug 17, 2017
f9adeb2
[bugfix] It is an error if the user manually sets the Content-Type or…
adamretter Aug 17, 2017
4a2c8d1
[refactor] Switched away from using deprecated Apache HTTP Components…
adamretter Aug 17, 2017
dd3c441
[feature] Implemented connection pooling
adamretter Aug 17, 2017
80d5cdc
[feature] Support for transferring GZipped data, just add a gzip="tru…
adamretter Aug 17, 2017
27a0640
[feature] Added support for SNI (Server Name Identification)
adamretter Aug 21, 2017
f5388a5
[bugfix] Fix an issue in DOM namespace handling
adamretter Aug 28, 2017
8b03e48
[feature] Add the ability to do non-chunked transfer encoding for HTT…
adamretter Sep 25, 2017
90d00ff
[ignore] Ignore IntelliJ project files
adamretter Sep 25, 2017
0808693
[bugfix] Avoid NPE when doing non-chunked transfer encoding without s…
adamretter Sep 30, 2017
de19d73
[bugfix] Fix NPE when using Basic Authentication
adamretter Nov 16, 2017
a6d63c6
[feature] Update to the latest Apache HTTP Components
adamretter Jan 19, 2018
e9ac210
[ignore] Added a comment about config options
adamretter Jan 19, 2018
03592e8
[feature/bugfix] Implement missing response charset encoding
adamretter Apr 5, 2018
225fa86
[bugfix] Preemptive Authentication was previously not working
adamretter Oct 11, 2018
6d5e837
[bugfix] Previously when override-media-type was set and a charset wa…
adamretter Apr 23, 2019
b9e5a3f
[feature] Introduce default-charset parameter for http:request
adamretter Apr 24, 2019
b369069
[bugfix] Default charset encoding for application/xml should be UTF-8…
adamretter May 1, 2019
45b39a0
Should not have a relative path to expath-parent
adamretter May 2, 2019
3931545
Update dependencies
adamretter May 2, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.iml
.idea/

/build/expath-http-client-java-*/
/build/expath-http-client-saxon-*/
/build/expath-http-client-java-*.zip
Expand All @@ -13,3 +16,6 @@
/http-client-saxon/build/
/http-client-saxon/dist/
/http-client-saxon/src/org/expath/httpclient/saxon/version.properties

/http-client-java/target/
/http-client-saxon/target/
88 changes: 88 additions & 0 deletions http-client-java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.expath.http.client</groupId>
<artifactId>http-client-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../http-client-parent/pom.xml</relativePath>
</parent>

<artifactId>http-client-java</artifactId>
<packaging>jar</packaging>

<name>EXPath HTTP Client Java Library</name>
<description>Java Library implementing the core HTTP Client module features</description>

<scm>
<connection>scm:git:git://github.com/adamretter/expath-http-client-java.git</connection> <!-- TODO when ready change me to scm:git:git://github.com/expath/expath-http-client-java.git -->
<developerConnection>scm:git:git://github.com/adamretter/expath-http-client-java.git</developerConnection> <!-- TODO when ready change me to scm:git:git://github.com/expath/expath-http-client-java.git -->
<url>http://github.com/adamretter/expath-http-client-java</url>
</scm>

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.expath.tools</groupId>
<artifactId>tools-java</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.ccil.cowan.tagsoup</groupId>
<artifactId>tagsoup</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>apache-mime4j-core</artifactId>
<version>0.8.3</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
<groupId>net.jcip</groupId>
<artifactId>jcip-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
19 changes: 19 additions & 0 deletions http-client-java/src/main/assembly/assembly.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>application</id>
<formats>
<format>dir</format>
</formats>

<includeBaseDirectory>true</includeBaseDirectory>

<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
177 changes: 177 additions & 0 deletions http-client-java/src/main/java/org/expath/httpclient/ContentType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/****************************************************************************/
/* File: ContentType.java */
/* Author: F. Georges - fgeorges.org */
/* Date: 2009-02-22 */
/* Tags: */
/* Copyright (c) 2009 Florent Georges (see end of file.) */
/* ------------------------------------------------------------------------ */


package org.expath.httpclient;

import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.NameValuePair;

import javax.annotation.Nullable;

/**
* Represent a Content-Type header.
* <p>
* Provide the ability to get the boundary param in case of a multipart
* content type on the one hand, and the ability to get only the MIME type
* string without any param on the other hand.
*
* @author Florent Georges
*/
public class ContentType {

public ContentType(final String type, final String charset, final String boundary) {
this.myType = type;
this.myCharset = charset;
this.myBoundary = boundary;
}

public static ContentType parse(@Nullable final Header header, @Nullable final String overrideType, @Nullable final String defaultCharset) throws HttpClientException {
final String type;
final String charset;
final String boundary;

if (overrideType != null) {
// get the internet media type from the override
type = extractMediaTypeFromContentType(overrideType);

// does the override contain a charset?
if (overrideType.indexOf("charset=") > -1) {
// get the charset from the override
charset = overrideType.replaceFirst(".+charset=([^;\\s]+).*", "$1");
} else {
// get the charset from the header or the default
if (header == null || !"Content-Type".equalsIgnoreCase(header.getName())) {
throw new HttpClientException("Header is not content type");
}
final HeaderElement[] headerElements = header.getElements();
if (headerElements.length > 1) {
throw new HttpClientException("Multiple Content-Type headers");
}

final NameValuePair headerCharset = headerElements[0].getParameterByName("charset");
if (headerCharset != null) {
charset = headerCharset.getValue();
} else {
charset = defaultCharset;
}
}

// does the override contain a boundary?
if (overrideType.indexOf("boundary=") > -1) {
boundary = overrideType.replaceFirst(".+boundary=([^;\\s]+).*", "$1");
} else {
// get the boundary from the header or null
if (header == null || !"Content-Type".equalsIgnoreCase(header.getName())) {
throw new HttpClientException("Header is not content type");
}
final HeaderElement[] headerElements = header.getElements();
if (headerElements.length > 1) {
throw new HttpClientException("Multiple Content-Type headers");
}

final NameValuePair headerBoundary = headerElements[0].getParameterByName("boundary");
boundary = headerBoundary == null ? null : headerBoundary.getValue();
}

} else {
// get the internet media type from the header
if (header == null || !"Content-Type".equalsIgnoreCase(header.getName())) {
throw new HttpClientException("Header is not content type");
}
final HeaderElement[] headerElements = header.getElements();
if (headerElements.length > 1) {
throw new HttpClientException("Multiple Content-Type headers");
}

type = extractMediaTypeFromContentType(header.getValue());

// get the charset from the header or the default
final NameValuePair headerCharset = headerElements[0].getParameterByName("charset");
if (headerCharset != null) {
charset = headerCharset.getValue();
} else {
charset = defaultCharset;
}

// get the boundary from the header
final NameValuePair headerBoundary = headerElements[0].getParameterByName("boundary");
boundary = headerBoundary == null ? null : headerBoundary.getValue();
}

return new ContentType(type, charset, boundary);
}

private static String extractMediaTypeFromContentType(final String contentType) {
final int idxParamSeparator = contentType.indexOf(';');
if (idxParamSeparator > -1) {
return contentType.substring(0, idxParamSeparator);
} else {
return contentType;
}
}

@Nullable
public String getType() {
return myType;
}

@Nullable
public String getCharset() {
return myCharset;
}

@Nullable
public String getBoundary() {
return myBoundary;
}

@Nullable
public String getValue() {
final StringBuilder builder = new StringBuilder(myType);
if (myCharset != null) {
builder.append("; charset=").append(myCharset);
}
if (myBoundary != null) {
builder.append("; boundary=").append(myCharset);
}

return builder.toString();
}

@Override
public String toString() {
return getValue();
}

private final String myType;
private final String myCharset;
private final String myBoundary;
}


/* ------------------------------------------------------------------------ */
/* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS COMMENT. */
/* */
/* The contents of this file are subject to the Mozilla Public License */
/* Version 1.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.mozilla.org/MPL/. */
/* */
/* Software distributed under the License is distributed on an "AS IS" */
/* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See */
/* the License for the specific language governing rights and limitations */
/* under the License. */
/* */
/* The Original Code is: all this file. */
/* */
/* The Initial Developer of the Original Code is Florent Georges. */
/* */
/* Contributor(s): none. */
/* ------------------------------------------------------------------------ */
Original file line number Diff line number Diff line change
Expand Up @@ -101,39 +101,6 @@ public Header getFirstHeader(String name)
return null;
}

public String getFirstHeaderWithoutParam(String name)
throws HttpClientException
{
Header h = getFirstHeader(name);
return getHeaderWithoutParam(h);
}

public static String getValueWithoutParam(String header_value)
throws HttpClientException
{
Header h = new BasicHeader("X-Dummy", header_value);
return getHeaderWithoutParam(h);
}

public static String getHeaderWithoutParam(Header header)
throws HttpClientException
{
// get the content type, only the mime string, like "type/subtype"
if ( header != null ) {
HeaderElement[] elems = header.getElements();
if ( elems == null ) {
return null;
}
else if ( elems.length == 1 ) {
return elems[0].getName();
}
else {
throw new HttpClientException("Multiple Content-Type headers");
}
}
return null;
}

private List<Header> myHeaders;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,14 @@ private Result sendOnce(Result result, URI uri, HttpRequest request, RequestPars
{
HttpConnection conn = new ApacheHttpConnection(uri);
try {
if ( parser.getSendAuth() ) {
HttpResponse response = request.send(result, conn, parser.getCredentials());
if ( response.getStatus() == 401 ) {
conn.disconnect();
conn = new ApacheHttpConnection(uri);
// create a new result, and throw the old one away
result = result.makeNewResult();
request.send(result, conn, parser.getCredentials());
}
else {
HttpResponse response = request.send(result, conn, null);
if ( response.getStatus() == 401 ) {
conn.disconnect();
conn = new ApacheHttpConnection(uri);
// create a new result, and throw the old one away
result = result.makeNewResult();
request.send(result, conn, parser.getCredentials());
}
}
}
finally {
conn.disconnect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public void setRequestMethod(String method, boolean with_content)
throws HttpClientException;
public void setFollowRedirect(boolean follow);
public void setTimeout(int seconds);
public void setGzip(boolean gzip);
public void setChunked(boolean chunked);
public void setPreemptiveAuthentication(boolean preemptiveAuthentication);
// responses...
public int getResponseStatus()
throws HttpClientException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ public HttpResponse send(Result result, HttpConnection conn, HttpCredentials cre
public String getHttpVersion();
public void setHttpVersion(String ver)
throws HttpClientException;
public void setDefaultCharset(String charset);
public void setOverrideType(String type);
public void setHeaders(HeaderSet headers);
public void setBody(HttpRequestBody body)
throws HttpClientException;
public void setStatusOnly(boolean only);
public void setFollowRedirect(boolean follow);
public void setTimeout(Integer seconds);
public void setGzip(boolean gzip);
public boolean isChunked();
public void setChunked(boolean chunked);
boolean isPreemptiveAuthentication();
void setPreemptiveAuthentication(final boolean preemptiveAuthentication);
}


Expand Down
Loading