Skip to content

Commit

Permalink
MP rest client review comments implemented
Browse files Browse the repository at this point in the history
Signed-off-by: David Kral <david.k.kral@oracle.com>
  • Loading branch information
Verdent committed Jun 11, 2019
1 parent 7b4cfa2 commit 122b5a3
Show file tree
Hide file tree
Showing 36 changed files with 523 additions and 657 deletions.
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<groupId>org.glassfish.jersey.ext.microprofile</groupId>
<artifactId>jersey-mp-rest-client</artifactId>
<version>${project.version}</version>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -26,7 +26,6 @@
import javax.ws.rs.core.UriBuilder;

import org.glassfish.jersey.internal.guava.Preconditions;
import org.glassfish.jersey.internal.inject.InjectionManager;

/**
* Jersey implementation of {@link javax.ws.rs.client.WebTarget JAX-RS client target}
Expand Down
115 changes: 9 additions & 106 deletions ext/microprofile/mp-rest-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
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>jersey-microprofile</artifactId>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>project</artifactId>
<groupId>org.glassfish.jersey.ext.microprofile</groupId>
<version>2.29-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -59,10 +59,15 @@
<artifactId>jersey-media-json-binding</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-cdi1x</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>1.1.5</version>
<version>${jsonp.ri.version}</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
Expand All @@ -73,107 +78,10 @@
<groupId>org.glassfish</groupId>
<artifactId>jsonp-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>3.0.3.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-bundle</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-config</artifactId>
<version>1.3.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.rest.client</groupId>
<artifactId>microprofile-rest-client-tck</artifactId>
<version>1.2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>2.21.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testng</groupId>
<artifactId>arquillian-testng-container</artifactId>
<version>1.4.1.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-test-spi</artifactId>
<version>1.4.1.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-embedded</artifactId>
<version>2.0.1.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-noop</artifactId>
<version>0.30.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!--<parallel>classes</parallel>
<perCoreThreadCount>true</perCoreThreadCount>
<threadCount>1</threadCount>
<forkCount>1C</forkCount>
<reuseForks>true</reuseForks>-->
<suiteXmlFiles>
<suiteXmlFile>tck-suite.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>uk.co.deliverymind</groupId>
<artifactId>wiremock-maven-plugin</artifactId>
<version>2.7.0</version>
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<dir>target/classes</dir>
<params>--port=8765 --verbose</params>
</configuration>
</execution>
</executions>
</plugin>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
Expand All @@ -194,9 +102,4 @@
</plugins>
</build>

<!-- <properties>-->
<!-- <surefire.security.argline>-Djava.security.manager -Djava.security.policy=${project.build.directory}/test-classes/server.policy</surefire.security.argline>-->
<!-- </properties>-->


</project>
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,11 @@ class BeanClassModel {
* Create new instance of bean annotated parameter.
*
* @param interfaceModel rest client interface model
* @param beanClass bean annotated parameter class
* @param beanClass bean annotated parameter class
* @return new instance
*/
static BeanClassModel fromClass(InterfaceModel interfaceModel, Class<?> beanClass) {
return new Builder(interfaceModel, beanClass)
.processPathFields()
.processHeaderFields()
.processCookieFields()
.processQueryFields()
.processMatrixFields()
.build();
}

Expand All @@ -83,7 +78,7 @@ List<ParamModel> getParameterModels() {
* Resolves bean path parameters.
*
* @param webTarget web target path
* @param instance actual method parameter value
* @param instance actual method parameter value
* @return updated web target path
*/
@SuppressWarnings("unchecked")
Expand All @@ -103,7 +98,7 @@ WebTarget resolvePath(WebTarget webTarget, Object instance) {
/**
* Resolves bean header parameters.
*
* @param headers headers
* @param headers headers
* @param instance actual method parameter value
* @return updated headers
*/
Expand All @@ -124,7 +119,7 @@ MultivaluedMap<String, Object> resolveHeaders(MultivaluedMap<String, Object> hea
/**
* Resolves bean cookie parameters.
*
* @param cookies cookies
* @param cookies cookies
* @param instance actual method parameter value
* @return updated cookies
*/
Expand All @@ -145,13 +140,13 @@ Map<String, String> resolveCookies(Map<String, String> cookies,
/**
* Resolves bean query parameters.
*
* @param query queries
* @param query queries
* @param instance actual method parameter value
* @return updated queries
*/
@SuppressWarnings("unchecked")
Map<String, Object[]> resolveQuery(Map<String, Object[]> query,
Object instance) {
Object instance) {
parameterModels.stream()
.filter(paramModel -> paramModel.handles(QueryParam.class))
.forEach(parameterModel -> {
Expand All @@ -167,12 +162,12 @@ Map<String, Object[]> resolveQuery(Map<String, Object[]> query,
* Resolves bean matrix parameters.
*
* @param webTarget web target path
* @param instance actual method parameter value
* @param instance actual method parameter value
* @return updated web target path
*/
@SuppressWarnings("unchecked")
WebTarget resolveMatrix(WebTarget webTarget,
Object instance) {
Object instance) {
AtomicReference<WebTarget> toReturn = new AtomicReference<>(webTarget);
parameterModels.stream()
.filter(paramModel -> paramModel.handles(MatrixParam.class))
Expand All @@ -185,17 +180,16 @@ WebTarget resolveMatrix(WebTarget webTarget,
return toReturn.get();
}


/**
* Resolves bean form parameters.
*
* @param form web form
* @param form web form
* @param instance actual method parameter value
* @return updated web form
*/
@SuppressWarnings("unchecked")
Form resolveForm(Form form,
Object instance) {
Object instance) {
parameterModels.stream()
.filter(paramModel -> paramModel.handles(FormParam.class))
.forEach(parameterModel -> {
Expand Down Expand Up @@ -235,52 +229,27 @@ private Builder(InterfaceModel interfaceModel, Class<?> beanClass) {
this.beanClass = beanClass;
}

/**
* Parses all {@link PathParam} annotated fields from bean class.
*
* @return updated builder instance
*/
Builder processPathFields() {
return processFieldsByParameterClass(PathParam.class);
private void processPathFields() {
processFieldsByParameterClass(PathParam.class);
}

/**
* Parses all {@link HeaderParam} annotated fields from bean class.
*
* @return updated builder instance
*/
Builder processHeaderFields() {
return processFieldsByParameterClass(HeaderParam.class);
private void processHeaderFields() {
processFieldsByParameterClass(HeaderParam.class);
}

/**
* Parses all {@link CookieParam} annotated fields from bean class.
*
* @return updated builder instance
*/
Builder processCookieFields() {
return processFieldsByParameterClass(CookieParam.class);
private void processCookieFields() {
processFieldsByParameterClass(CookieParam.class);
}

/**
* Parses all {@link QueryParam} annotated fields from bean class.
*
* @return updated builder instance
*/
Builder processQueryFields() {
return processFieldsByParameterClass(QueryParam.class);
private void processQueryFields() {
processFieldsByParameterClass(QueryParam.class);
}

/**
* Parses all {@link MatrixParam} annotated fields from bean class.
*
* @return updated builder instance
*/
Builder processMatrixFields() {
return processFieldsByParameterClass(MatrixParam.class);
private void processMatrixFields() {
processFieldsByParameterClass(MatrixParam.class);
}

private Builder processFieldsByParameterClass(Class<? extends Annotation> parameterClass) {
private void processFieldsByParameterClass(Class<? extends Annotation> parameterClass) {
for (Field field : beanClass.getDeclaredFields()) {
if (field.isAnnotationPresent(parameterClass)) {
Parameter parameter = Parameter.create(parameterClass, parameterClass, false,
Expand All @@ -290,7 +259,6 @@ private Builder processFieldsByParameterClass(Class<? extends Annotation> parame
parameter, -1));
}
}
return this;
}

/**
Expand All @@ -299,6 +267,11 @@ private Builder processFieldsByParameterClass(Class<? extends Annotation> parame
* @return new instance
*/
BeanClassModel build() {
processPathFields();
processHeaderFields();
processCookieFields();
processQueryFields();
processMatrixFields();
return new BeanClassModel(this);
}
}
Expand Down
Loading

0 comments on commit 122b5a3

Please sign in to comment.