Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
135 changes: 135 additions & 0 deletions httpclient5-jakarta-rest-client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
====================================================================
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
====================================================================

This software consists of voluntary contributions made by many
individuals on behalf of the Apache Software Foundation. For more
information on the Apache Software Foundation, please see
<http://www.apache.org />.
--><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">
<parent>
<artifactId>httpclient5-parent</artifactId>
<groupId>org.apache.httpcomponents.client5</groupId>
<version>5.7-alpha1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>httpclient5-jakarta-rest-client</artifactId>
<name>Jakarta REST Client for Apache HttpClient</name>
<description>Type-safe Jakarta REST client backed by Apache HttpClient</description>

<properties>
<Automatic-Module-Name>org.apache.hc.client5.http.rest</Automatic-Module-Name>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5-testing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>skip-on-java8</id>
<activation>
<property>
<name>hc.build.toolchain.version</name>
<value>1.8</value>
</property>
</activation>
<properties>
<maven.main.skip>true</maven.main.skip>
<maven.test.skip>true</maven.test.skip>
<maven.javadoc.skip>true</maven.javadoc.skip>
<maven.source.skip>true</maven.source.skip>
<maven.install.skip>true</maven.install.skip>
<checkstyle.skip>true</checkstyle.skip>
</properties>
</profile>
</profiles>

<reporting>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<inherited>false</inherited>
<reportSets>
<reportSet>
<reports>
<report>index</report>
<report>dependencies</report>
<report>dependency-info</report>
<report>summary</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.hc.client5.http.rest;

import java.util.Locale;

/**
* Builds the value of the {@code Accept} header from the media types declared in a
* {@code @Produces} annotation. Implementations control how multiple media types are
* ordered and whether quality values are assigned.
*
* @since 5.7
*/
public interface AcceptStrategy {

/**
* Default strategy that assigns descending quality values (1.0, 0.9, 0.8, ...) when
* more than one media type is declared. A single type is sent without a quality parameter.
*/
AcceptStrategy QUALITY_DESCENDING = new AcceptStrategy() {

/** Quality-value step. */
private static final double Q_STEP = 0.1;
/** Minimum quality value. */
private static final double Q_MIN = 0.1;

@Override
public String buildAcceptHeader(final String[] produces) {
if (produces.length == 1) {
return produces[0];
}
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < produces.length; i++) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(produces[i]);
final double q = 1.0 - i * Q_STEP;
final double qClamped = Math.max(q, Q_MIN);
sb.append(";q=");
if (qClamped == 1.0) {
sb.append("1.0");
} else {
sb.append(String.format(Locale.ROOT, "%.1f", qClamped));
}
}
return sb.toString();
}
};

/**
* Strategy that lists all media types without quality values, giving them equal
* preference.
*/
AcceptStrategy UNWEIGHTED = produces -> {
final StringBuilder sb = new StringBuilder();
for (final String type : produces) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(type);
}
return sb.toString();
};

/**
* Formats the given media types into an Accept header value.
*
* @param produces the media types from {@code @Produces}, never empty.
* @return the formatted Accept header value.
*/
String buildAcceptHeader(String[] produces);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.hc.client5.http.rest;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;

/**
* Deserializes an HTTP response body into a Java object. Implementations handle a specific
* content type such as JSON or XML.
*
* @since 5.7
*/
public interface EntityReader {

/**
* Reads the response body and converts it to the requested type.
*
* @param stream the response body stream.
* @param rawType the raw return type of the interface method.
* @param genericType the full generic return type, which may be a
* {@link java.lang.reflect.ParameterizedType}.
* @return the deserialized object.
* @throws IOException if reading or deserialization fails.
*/
Object read(InputStream stream, Class<?> rawType, Type genericType) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.hc.client5.http.rest;

import java.io.IOException;

/**
* Serializes a Java object into a byte array for use as an HTTP request body.
* Implementations handle a specific content type such as JSON or XML.
*
* @since 5.7
*/
public interface EntityWriter {

/**
* Serializes the given object into a byte array suitable for use as a request body.
*
* @param body the object to serialize.
* @param mediaType the target media type from the {@code @Consumes} annotation.
* @return the serialized bytes.
* @throws IOException if serialization fails.
*/
byte[] write(Object body, String mediaType) throws IOException;
}
Loading
Loading