use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.
the class BusShutdownTest method doWork.
private void doWork(URL wsdlUrl, String address) {
SOAPService service = new SOAPService(wsdlUrl);
assertNotNull(service);
Greeter greeter = service.getSoapPort();
// overwrite client address
InvocationHandler handler = Proxy.getInvocationHandler(greeter);
BindingProvider bp = (BindingProvider) handler;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
Client client = ClientProxy.getClient(greeter);
HTTPConduit c = (HTTPConduit) client.getConduit();
c.setClient(new HTTPClientPolicy());
c.getClient().setConnection(ConnectionType.CLOSE);
// invoke twoway call
greeter.sayHi();
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.
the class WSSecurity10Test method testClientServer.
@Test
public void testClientServer() {
BusFactory.setDefaultBus(getStaticBus());
BusFactory.setThreadDefaultBus(getStaticBus());
URL wsdlLocation = null;
PingService svc = null;
wsdlLocation = getWsdlLocation(test.prefix, test.port);
svc = new PingService(wsdlLocation);
final IPingService port = svc.getPort(new QName("http://WSSec/wssec10", test.prefix + "_IPingService"), IPingService.class);
Client cl = ClientProxy.getClient(port);
if (test.streaming) {
// Streaming
((BindingProvider) port).getRequestContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
((BindingProvider) port).getResponseContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
}
HTTPConduit http = (HTTPConduit) cl.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(0);
httpClientPolicy.setReceiveTimeout(0);
http.setClient(httpClientPolicy);
String output = port.echo(INPUT);
assertEquals(INPUT, output);
cl.destroy();
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project uavstack by uavorg.
the class DoTestJaxWSHook method main.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args) {
ConsoleLogger cl = new ConsoleLogger("test");
cl.setDebugable(true);
UAVServer.instance().setLog(cl);
UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR, ServerVendor.TOMCAT);
Map config = new HashMap();
Map adapts = JSONHelper.toObject("{\"org.apache.cxf.frontend.ClientProxy\":{\"getClient\":{args:[\"java.lang.Object\"],target:0}}}", Map.class);
config.put("adapts", adapts);
JaxWSHookProxy jp = new JaxWSHookProxy("test", config);
jp.doInstallDProxy(null, "test");
TestService_Service s = new TestService_Service();
TestService ts = s.getTestServicePort();
// 设置客户端的配置信息,超时等.
Client proxy = ClientProxy.getClient(ts);
HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
// 连接服务器超时时间
policy.setConnectionTimeout(30000);
// 等待服务器响应超时时间
policy.setReceiveTimeout(30000);
conduit.setClient(policy);
ts.echo();
try {
ts.echoFault();
} catch (Exception e) {
e.printStackTrace();
}
Dispatch<SOAPMessage> d = s.createDispatch(new QName("http://service.fat.monitorframework.creditease.com/", "TestServicePort"), SOAPMessage.class, Mode.MESSAGE);
try {
SOAPMessage msg = MessageFactory.newInstance().createMessage();
d.invoke(msg);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("--------------->CECXFClient");
CECXFClient client = new CECXFClient(TestService_Service.class, TestService.class, TestService_Service.TestServicePort);
client.setConnectTimeout(30000);
client.setReceiveTimeout(30000);
try {
client.invoke("echo", null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project ddf by codice.
the class SecureCxfClientFactoryImpl method configureTimeouts.
/**
* Configures the connection and receive timeouts. If any of the parameters are null, the timeouts
* will be set to the system default.
*
* @param clientConfiguration Client configuration used for outgoing requests.
* @param connectionTimeout Connection timeout in milliseconds.
* @param receiveTimeout Receive timeout in milliseconds.
*/
protected void configureTimeouts(ClientConfiguration clientConfiguration, Integer connectionTimeout, Integer receiveTimeout) {
HTTPConduit httpConduit = clientConfiguration.getHttpConduit();
if (httpConduit == null) {
LOGGER.info("HTTPConduit was null for {}. Unable to configure timeouts", this);
return;
}
HTTPClientPolicy httpClientPolicy = httpConduit.getClient();
if (httpClientPolicy == null) {
httpClientPolicy = new HTTPClientPolicy();
}
if (connectionTimeout != null) {
httpClientPolicy.setConnectionTimeout(connectionTimeout);
} else {
httpClientPolicy.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
}
if (receiveTimeout != null) {
httpClientPolicy.setReceiveTimeout(receiveTimeout);
} else {
httpClientPolicy.setReceiveTimeout(DEFAULT_RECEIVE_TIMEOUT);
}
if (httpClientPolicy.isSetConnectionTimeout()) {
LOGGER.debug("Connection timeout has been set.");
} else {
LOGGER.debug("Connection timeout has NOT been set.");
}
if (httpClientPolicy.isSetReceiveTimeout()) {
LOGGER.debug("Receive timeout has been set.");
} else {
LOGGER.debug("Receive timeout has NOT been set.");
}
httpConduit.setClient(httpClientPolicy);
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project ddf by codice.
the class SecureCxfClientFactoryImpl method configureConduit.
@SuppressWarnings("squid:S3776")
private void configureConduit(ClientConfiguration clientConfig) {
HTTPConduit httpConduit = clientConfig.getHttpConduit();
if (httpConduit == null) {
LOGGER.info("HTTPConduit was null for {}. Unable to configure security.", this);
return;
}
if (allowRedirects) {
HTTPClientPolicy clientPolicy = httpConduit.getClient();
if (clientPolicy != null) {
clientPolicy.setAutoRedirect(true);
Bus bus = clientConfig.getBus();
if (bus != null) {
bus.getProperties().put(AUTO_REDIRECT_ALLOW_REL_URI, true);
bus.getProperties().put(AUTO_REDIRECT_MAX_SAME_URI_COUNT, getSameUriRedirectMax());
}
}
}
TLSClientParameters tlsParams = httpConduit.getTlsClientParameters();
if (tlsParams == null) {
tlsParams = new TLSClientParameters();
}
tlsParams.setDisableCNCheck(disableCnCheck);
tlsParams.setUseHttpsURLConnectionDefaultHostnameVerifier(!disableCnCheck);
String cipherSuites = System.getProperty("https.cipherSuites");
if (cipherSuites != null) {
tlsParams.setCipherSuites(Arrays.asList(cipherSuites.split(",")));
}
KeyStore keyStore = null;
KeyStore trustStore = null;
try {
keyStore = SecurityConstants.newKeystore();
trustStore = SecurityConstants.newTruststore();
} catch (KeyStoreException e) {
LOGGER.debug("Unable to create keystore instance of type {}", System.getProperty(SecurityConstants.KEYSTORE_TYPE), e);
}
Path keyStoreFile;
if (keyInfo != null && keyInfo.getKeystorePath() != null) {
keyStoreFile = keyInfo.getKeystorePath();
} else {
keyStoreFile = Paths.get(SecurityConstants.getKeystorePath());
}
Path trustStoreFile = Paths.get(SecurityConstants.getTruststorePath());
String ddfHome = System.getProperty("ddf.home");
if (ddfHome != null) {
Path ddfHomePath = Paths.get(ddfHome);
if (!keyStoreFile.isAbsolute()) {
keyStoreFile = Paths.get(ddfHomePath.toString(), keyStoreFile.toString());
}
if (!trustStoreFile.isAbsolute()) {
trustStoreFile = Paths.get(ddfHomePath.toString(), trustStoreFile.toString());
}
}
String keyStorePassword = SecurityConstants.getKeystorePassword();
String trustStorePassword = SecurityConstants.getTruststorePassword();
if (!Files.isReadable(keyStoreFile) || !Files.isReadable(trustStoreFile)) {
LOGGER.debug("Unable to read system key/trust store files: [ {} ] [ {} ]", keyStoreFile, trustStoreFile);
return;
}
try (InputStream kfis = Files.newInputStream(keyStoreFile)) {
if (keyStore != null) {
keyStore.load(kfis, keyStorePassword.toCharArray());
}
} catch (NoSuchAlgorithmException | CertificateException | IOException e) {
LOGGER.debug("Unable to load system key file.", e);
}
try (InputStream tfis = Files.newInputStream(trustStoreFile)) {
if (trustStore != null) {
trustStore.load(tfis, trustStorePassword.toCharArray());
}
} catch (NoSuchAlgorithmException | CertificateException | IOException e) {
LOGGER.debug("Unable to load system trust file.", e);
}
KeyManager[] keyManagers = null;
try {
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keyStorePassword.toCharArray());
keyManagers = keyManagerFactory.getKeyManagers();
tlsParams.setKeyManagers(keyManagers);
} catch (NoSuchAlgorithmException | KeyStoreException | UnrecoverableKeyException e) {
LOGGER.debug("Unable to initialize KeyManagerFactory.", e);
}
TrustManager[] trustManagers = null;
try {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
trustManagers = trustManagerFactory.getTrustManagers();
tlsParams.setTrustManagers(trustManagers);
} catch (NoSuchAlgorithmException | KeyStoreException e) {
LOGGER.debug("Unable to initialize TrustManagerFactory.", e);
}
if (keyInfo != null) {
LOGGER.trace("Using keystore file: {}, alias: {}", keyStoreFile, keyInfo.getAlias());
tlsParams.setUseHttpsURLConnectionDefaultSslSocketFactory(false);
tlsParams.setCertAlias(keyInfo.getAlias());
try {
if (keyManagers == null) {
throw new KeyManagementException("keyManagers was null");
}
boolean validProtocolFound = false;
String validProtocolsStr = System.getProperty("jdk.tls.client.protocols");
if (StringUtils.isNotBlank(validProtocolsStr)) {
String[] validProtocols = validProtocolsStr.split(",");
for (String validProtocol : validProtocols) {
if (validProtocol.equals(sslProtocol)) {
validProtocolFound = true;
break;
}
}
if (!validProtocolFound) {
LOGGER.error("{} is not in list of valid SSL protocols {}", sslProtocol, validProtocolsStr);
}
} else {
validProtocolFound = true;
}
if (validProtocolFound) {
tlsParams.setSSLSocketFactory(getSSLSocketFactory(sslProtocol, keyInfo.getAlias(), keyManagers, trustManagers));
}
} catch (KeyManagementException | NoSuchAlgorithmException e) {
LOGGER.debug("Unable to override default SSL Socket Factory", e);
}
} else {
tlsParams.setUseHttpsURLConnectionDefaultSslSocketFactory(true);
tlsParams.setCertAlias(SystemBaseUrl.INTERNAL.getHost());
}
httpConduit.setTlsClientParameters(tlsParams);
}
Aggregations