Skip to content

Commit

Permalink
Introduce specific MessageBodyReader/Writer methods to client ClientB…
Browse files Browse the repository at this point in the history
…uilderImpl
  • Loading branch information
geoand committed Jan 24, 2023
1 parent b60b23d commit 4e32c07
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
Expand All @@ -21,6 +22,8 @@
import javax.ws.rs.RuntimeType;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Configuration;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.MessageBodyWriter;

import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.client.api.ClientLogger;
Expand Down Expand Up @@ -344,6 +347,23 @@ public ClientBuilderImpl register(Object component, Map<Class<?>, Integer> contr
return this;
}

/*
* Add some custom methods that allow registering MessageBodyReader and MessageBodyWriter classes with all the necessary
* information
*/

public ClientBuilderImpl registerMessageBodyReader(MessageBodyReader<?> reader, Class<?> handledType, List<String> consumes,
boolean builtin, Integer priority) {
configuration.registerMessageBodyReader(reader, handledType, consumes, RuntimeType.CLIENT, builtin, priority);
return this;
}

public ClientBuilderImpl registerMessageBodyWriter(MessageBodyWriter<?> writer, Class<?> handledType, List<String> consumes,
boolean builtin, Integer priority) {
configuration.registerMessageBodyWriter(writer, handledType, consumes, RuntimeType.CLIENT, builtin, priority);
return this;
}

public ClientBuilderImpl trustAll(boolean trustAll) {
this.trustAll = trustAll;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,41 @@ public void register(Object component, Map<Class<?>, Integer> componentContracts

}

/*
* Add some custom methods that allow registering MessageBodyReader and MessageBodyWriter classes with all the necessary
* information
*/

public void registerMessageBodyReader(MessageBodyReader<?> reader, Class<?> handledType, List<String> consumes,
RuntimeType runtimeType, boolean builtin, Integer priority) {
if (isRegistered(reader)) {
return;
}
ResourceReader resourceReader = new ResourceReader();
resourceReader.setFactory(new UnmanagedBeanFactory<>(reader));
resourceReader.setMediaTypeStrings(consumes);
resourceReader.setBuiltin(builtin);
resourceReader.setPriority(priority);
resourceReader.setConstraint(runtimeType);
resourceReaders.add(handledType, resourceReader);
allInstances.put(reader.getClass(), reader);
}

public void registerMessageBodyWriter(MessageBodyWriter<?> messageBodyWriter, Class<?> handledType, List<String> consumes,
RuntimeType runtimeType, boolean builtin, Integer priority) {
if (isRegistered(messageBodyWriter)) {
return;
}
ResourceWriter resourceWriter = new ResourceWriter();
resourceWriter.setFactory(new UnmanagedBeanFactory<>(messageBodyWriter));
resourceWriter.setMediaTypeStrings(consumes);
resourceWriter.setBuiltin(builtin);
resourceWriter.setPriority(priority);
resourceWriter.setConstraint(runtimeType);
resourceWriters.add(handledType, resourceWriter);
allInstances.put(messageBodyWriter.getClass(), messageBodyWriter);
}

public void register(Object component, int priority) {
register(component, Integer.valueOf(priority));
}
Expand Down

0 comments on commit 4e32c07

Please sign in to comment.