Quantcast
Channel: Apache Timeline
Viewing all articles
Browse latest Browse all 5648

WebClient issues with SSL

$
0
0
Here's the code snippet:

import org.apache.cxf.jaxrs.client.WebClient;

public class ProtoClient {

public ProtoClient(String baseAddress) {

client = WebClient.create(baseAddress);

public WebClient getClient() {

return client;

...

public GeneratedMessage submitToWS(Class<?> responseClass, GeneratedMessage
request) throws MyException {

...

response = this.client.post(request.toByteArray());

...

in = response.readEntity(InputStream.class);
...

parseFrom = responseClass.getDeclaredMethod("parseFrom",

new Class[] { InputStream.class });

resp = (GeneratedMessage) parseFrom.invoke(null, in);

} catch (Exception e) {

logger.error("Exception",e);

} finally {

if (null != in) {

try {

in.close();

} catch (IOException e) {

logger.error("IOException : Cannot close the inputstream",e);

public static ProtoClient getUserClient() {

...

String API = GetConfigurations.getEddieConfig("API_NAME");

if(SSL) {

URL_BASE = GetConfigurations.getEnvConfig("URL_BASE_SSL");

} else {

URL_BASE = GetConfigurations.getEnvConfig("URL_BASE");

ProtoClient userClient = new ProtoClient(URL_BASE);

WebClient client = userClient.getClient();

client.path(API);

//with URL_BASE and API; it ends up being sth like this:

//http://api-sandbox.myws.com/api/v2/api-name

client.accept(MediaType.APPLICATION_OCTET_STREAM_TYPE);

// accepts protobuf objects

client.type(MediaType.APPLICATION_OCTET_STREAM_TYPE);

WebClient.getConfig(client).getHttpConduit().getClient().setConnectionTimeout(
CONNECTION_TIMEOUT_IN_MS);

WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(
TIMEOUT_IN_MS);

WebClient.getConfig(client).getHttpConduit().getClient().setConnection(ConnectionType.
KEEP_ALIVE);

...

return userClient;

Viewing all articles
Browse latest Browse all 5648

Trending Articles