use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.
the class WSAFaultToClientServerTest method testTwoWayFaultTo.
@Test
public void testTwoWayFaultTo() throws Exception {
ByteArrayOutputStream input = setupInLogging();
AddNumbersPortType port = getTwoWayPort();
// setup a real decoupled endpoint that will process the fault correctly
HTTPConduit c = (HTTPConduit) ClientProxy.getClient(port).getConduit();
c.getClient().setDecoupledEndpoint("http://localhost:" + FaultToEndpointServer.FAULT_PORT2 + "/sendFaultHere");
EndpointReferenceType faultTo = new EndpointReferenceType();
AddressingProperties addrProperties = new AddressingProperties();
AttributedURIType epr = new AttributedURIType();
epr.setValue("http://localhost:" + FaultToEndpointServer.FAULT_PORT2 + "/sendFaultHere");
faultTo.setAddress(epr);
addrProperties.setFaultTo(faultTo);
BindingProvider provider = (BindingProvider) port;
Map<String, Object> requestContext = provider.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + FaultToEndpointServer.PORT + "/jaxws/add");
requestContext.put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProperties);
try {
port.addNumbers(-1, -2);
fail("Exception is expected");
} catch (Exception e) {
// do nothing
}
String in = new String(input.toByteArray());
// System.out.println(in);
assertTrue("The response from faultTo endpoint is expected and actual response is " + in, in.indexOf("Address: http://localhost:" + FaultToEndpointServer.FAULT_PORT2 + "/sendFaultHere") > -1);
assertTrue("WS addressing header is expected", in.indexOf("http://www.w3.org/2005/08/addressing") > -1);
assertTrue("Fault deatil is expected", in.indexOf("Negative numbers cant be added") > -1);
((Closeable) port).close();
}
use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.
the class WebSocketTransportFactory method getConduit.
/**
* {@inheritDoc}
*/
public Conduit getConduit(EndpointInfo endpointInfo, EndpointReferenceType target, Bus bus) throws IOException {
HTTPConduit conduit = new AhcWebSocketConduit(bus, endpointInfo, target);
String address = conduit.getAddress();
if (address != null && address.indexOf('?') != -1) {
address = address.substring(0, address.indexOf('?'));
}
HTTPConduitConfigurer c1 = bus.getExtension(HTTPConduitConfigurer.class);
if (c1 != null) {
c1.configure(conduit.getBeanName(), address, conduit);
}
configure(bus, conduit, conduit.getBeanName(), address);
conduit.finalizeConfig();
return conduit;
}
use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.
the class JAXRSSamlTest method testSAMLTokenHeaderUsingAuthorizationPolicy.
@Test
public void testSAMLTokenHeaderUsingAuthorizationPolicy() throws Exception {
String address = "https://localhost:" + PORT + "/samlheader/bookstore/books/123";
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(address);
SpringBusFactory bf = new SpringBusFactory();
URL busFile = JAXRSSamlTest.class.getResource("client.xml");
Bus springBus = bf.createBus(busFile.toString());
bean.setBus(springBus);
// Create SAML Token
SAMLCallback samlCallback = new SAMLCallback();
SAMLUtil.doSAMLCallback(new SamlCallbackHandler(), samlCallback);
SamlAssertionWrapper assertion = new SamlAssertionWrapper(samlCallback);
Document doc = DOMUtils.createDocument();
Element token = assertion.toDOM(doc);
WebClient wc = bean.createWebClient();
HTTPConduit http = (HTTPConduit) WebClient.getConfig(wc).getConduit();
AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
String encodedToken = encodeToken(DOM2Writer.nodeToString(token));
authorizationPolicy.setAuthorization(encodedToken);
authorizationPolicy.setAuthorizationType("SAML");
http.setAuthorization(authorizationPolicy);
try {
Book book = wc.get(Book.class);
assertEquals(123L, book.getId());
} catch (WebApplicationException ex) {
fail(ex.getMessage());
} catch (ProcessingException ex) {
if (ex.getCause() != null && ex.getCause().getMessage() != null) {
fail(ex.getCause().getMessage());
} else {
fail(ex.getMessage());
}
}
}
use of org.apache.cxf.transport.http.HTTPConduit 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.transport.http.HTTPConduit in project cxf by apache.
the class UsernameTokenTest method testPlaintextWSDLOverHTTPSViaCode.
@org.junit.Test
public void testPlaintextWSDLOverHTTPSViaCode() throws Exception {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
final KeyStore ts = KeyStore.getInstance("JKS");
try (InputStream trustStore = ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", UsernameTokenTest.class)) {
ts.load(trustStore, "password".toCharArray());
}
tmf.init(ts);
TLSClientParameters tlsParams = new TLSClientParameters();
tlsParams.setTrustManagers(tmf.getTrustManagers());
tlsParams.setDisableCNCheck(true);
HTTPConduitConfigurer myHttpConduitConfig = new HTTPConduitConfigurer() {
public void configure(String name, String address, HTTPConduit c) {
if ("{http://cxf.apache.org}TransportURIResolver.http-conduit".equals(name)) {
c.setTlsClientParameters(tlsParams);
}
}
};
BusFactory busFactory = BusFactory.newInstance();
bus = busFactory.createBus();
bus.setExtension(myHttpConduitConfig, HTTPConduitConfigurer.class);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = new URL("https://localhost:" + PORT + "/DoubleItUTPlaintext?wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPort");
DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(utPort, test.getPort());
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(utPort);
}
((BindingProvider) utPort).getRequestContext().put(SecurityConstants.USERNAME, "Alice");
((BindingProvider) utPort).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.ws.common.UTPasswordCallback");
Client client = ClientProxy.getClient(utPort);
HTTPConduit http = (HTTPConduit) client.getConduit();
http.setTlsClientParameters(tlsParams);
assertEquals(50, utPort.doubleIt(25));
((java.io.Closeable) utPort).close();
}
Aggregations