use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.
the class JAXRSSoapBookTest method doTestHelloSoapCustomDataBinding.
private void doTestHelloSoapCustomDataBinding(String address) throws Exception {
final QName serviceName = new QName("http://hello.com", "HelloWorld");
final QName portName = new QName("http://hello.com", "HelloWorldPort");
Service service = Service.create(serviceName);
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address);
HelloWorld hw = service.getPort(HelloWorld.class);
Client cl = ClientProxy.getClient(hw);
HTTPConduit http = (HTTPConduit) cl.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(0);
httpClientPolicy.setReceiveTimeout(0);
http.setClient(httpClientPolicy);
User user = new UserImpl("Barry");
User user2 = hw.echoUser(user);
assertNotSame(user, user2);
assertEquals("Barry", user2.getName());
}
use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.
the class DispatchClientServerTest method testTimeout.
@Test
public void testTimeout() throws Exception {
// CXF-2384
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
// pick one of the other service/ports that would have an address
// without a service running
QName otherServiceName = new QName("http://apache.org/hello_world_soap_http", "SOAPProviderService");
QName otherPortName = new QName("http://apache.org/hello_world_soap_http", "SoapProviderPort");
SOAPService service = new SOAPService(wsdl, otherServiceName);
assertNotNull(service);
Dispatch<SOAPMessage> disp = service.createDispatch(otherPortName, SOAPMessage.class, Service.Mode.MESSAGE);
disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + TestUtil.getPortNumber("fake-port") + "/SOAPDispatchService/SoapDispatchPort");
DispatchImpl<?> dispImpl = (DispatchImpl<?>) disp;
HTTPConduit cond = (HTTPConduit) dispImpl.getClient().getConduit();
cond.getClient().setConnectionTimeout(500);
InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
assertNotNull(soapReqMsg);
try {
disp.invoke(soapReqMsg);
fail("Should have faulted");
} catch (SOAPFaultException ex) {
fail("should not be a SOAPFaultException");
} catch (WebServiceException ex) {
// expected
assertTrue(ex.getCause().getClass().getName(), ex.getCause() instanceof java.net.ConnectException || ex.getCause() instanceof java.net.SocketTimeoutException);
}
dispImpl.close();
}
use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.
the class JAXRSMultipartTest method testUseProxyToAddBookAndSimpleParts.
@Test
public void testUseProxyToAddBookAndSimpleParts() throws Exception {
MultipartStore store = JAXRSClientFactory.create("http://localhost:" + PORT, MultipartStore.class);
HTTPConduit conduit = WebClient.getConfig(store).getHttpConduit();
conduit.getClient().setReceiveTimeout(1000000);
Book b = store.testAddBookAndSimpleParts(new Book("CXF in Action", 124L), "1", 2);
assertEquals(124L, b.getId());
assertEquals("CXF in Action - 12", b.getName());
}
use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.
the class JAXRSMultipartTest method testUploadImageFromForm.
@Test
public void testUploadImageFromForm() throws Exception {
InputStream is1 = getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
String address = "http://localhost:" + PORT + "/bookstore/books/formimage";
WebClient client = WebClient.create(address);
HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit();
conduit.getClient().setReceiveTimeout(1000000);
conduit.getClient().setConnectionTimeout(1000000);
client.type("multipart/form-data").accept("multipart/form-data");
ContentDisposition cd = new ContentDisposition("attachment;filename=java.jpg");
MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
headers.putSingle("Content-ID", "image");
headers.putSingle("Content-Disposition", cd.toString());
headers.putSingle("Content-Location", "http://host/bar");
headers.putSingle("custom-header", "custom");
Attachment att = new Attachment(is1, headers);
MultipartBody body = new MultipartBody(att);
MultipartBody body2 = client.post(body, MultipartBody.class);
InputStream is2 = body2.getRootAttachment().getDataHandler().getInputStream();
byte[] image1 = IOUtils.readBytesFromStream(getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
byte[] image2 = IOUtils.readBytesFromStream(is2);
assertTrue(Arrays.equals(image1, image2));
ContentDisposition cd2 = body2.getRootAttachment().getContentDisposition();
assertEquals("attachment;filename=java.jpg", cd2.toString());
assertEquals("java.jpg", cd2.getParameter("filename"));
assertEquals("http://host/location", body2.getRootAttachment().getHeader("Content-Location"));
}
use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.
the class ApplicationContextTest method checkContext.
private void checkContext(TestApplicationContext ctx) throws Exception {
ConfigurerImpl cfg = new ConfigurerImpl(ctx);
EndpointInfo info = getEndpointInfo("bla", "Foo", "http://localhost:9000");
Bus bus = (Bus) ctx.getBean(Bus.DEFAULT_BUS_ID);
bus.setExtension(cfg, Configurer.class);
DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
DestinationFactory factory = dfm.getDestinationFactory("http://cxf.apache.org/transports/http");
Destination d = factory.getDestination(info, bus);
assertTrue(d instanceof JettyHTTPDestination);
JettyHTTPDestination jd = (JettyHTTPDestination) d;
assertEquals("foobar", jd.getServer().getContentEncoding());
JettyHTTPServerEngine engine = (JettyHTTPServerEngine) jd.getEngine();
assertEquals(111, engine.getThreadingParameters().getMinThreads());
assertEquals(120, engine.getThreadingParameters().getMaxThreads());
assertEquals("TestPrefix", engine.getThreadingParameters().getThreadNamePrefix());
ConduitInitiatorManager cim = bus.getExtension(ConduitInitiatorManager.class);
ConduitInitiator ci = cim.getConduitInitiator("http://cxf.apache.org/transports/http");
HTTPConduit conduit = (HTTPConduit) ci.getConduit(info, bus);
assertEquals(97, conduit.getClient().getConnectionTimeout());
info.setName(new QName("urn:test:ns", "Bar"));
conduit = (HTTPConduit) ci.getConduit(info, bus);
assertEquals(79, conduit.getClient().getConnectionTimeout());
JettyHTTPDestination jd2 = (JettyHTTPDestination) factory.getDestination(getEndpointInfo("foo", "bar", "http://localhost:9001"), bus);
engine = (JettyHTTPServerEngine) jd2.getEngine();
assertEquals(40000, engine.getMaxIdleTime());
assertFalse(engine.getSendServerVersion());
assertEquals(99, engine.getThreadingParameters().getMinThreads());
assertEquals(777, engine.getThreadingParameters().getMaxThreads());
assertEquals("AnotherPrefix", engine.getThreadingParameters().getThreadNamePrefix());
assertTrue("The engine should support session manager", engine.isSessionSupport());
assertNotNull("The handlers should not be null", engine.getHandlers());
assertEquals(1, engine.getHandlers().size());
JettyHTTPDestination jd3 = (JettyHTTPDestination) factory.getDestination(getEndpointInfo("sna", "foo", "https://localhost:9002"), bus);
engine = (JettyHTTPServerEngine) jd3.getEngine();
assertEquals(111, engine.getThreadingParameters().getMinThreads());
assertEquals(120, engine.getThreadingParameters().getMaxThreads());
assertEquals("TestPrefix", engine.getThreadingParameters().getThreadNamePrefix());
assertEquals(engine.getTlsServerParameters().getClientAuthentication().isWant(), true);
assertEquals(engine.getTlsServerParameters().getClientAuthentication().isRequired(), true);
JettyHTTPDestination jd4 = (JettyHTTPDestination) factory.getDestination(getEndpointInfo("sna", "foo2", "https://localhost:9003"), bus);
engine = (JettyHTTPServerEngine) jd4.getEngine();
assertEquals(engine.getTlsServerParameters().getClientAuthentication().isWant(), false);
assertEquals(engine.getTlsServerParameters().getClientAuthentication().isRequired(), false);
JettyHTTPDestination jd5 = (JettyHTTPDestination) factory.getDestination(getEndpointInfo("sna", "foo", "http://localhost:9100"), bus);
engine = (JettyHTTPServerEngine) jd5.getEngine();
String r = "expected fallback thread parameters configured for port 0";
assertNotNull(r, engine.getThreadingParameters());
assertEquals(r, 21, engine.getThreadingParameters().getMinThreads());
assertEquals(r, 389, engine.getThreadingParameters().getMaxThreads());
}
Aggregations