Search in sources :

Example 76 with HTTPConduit

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());
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) User(org.apache.cxf.systest.jaxrs.jaxws.User) QName(javax.xml.namespace.QName) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) UserImpl(org.apache.cxf.systest.jaxrs.jaxws.UserImpl) Service(javax.xml.ws.Service) BookSoapService(org.apache.cxf.systest.jaxrs.jaxws.BookSoapService) Client(org.apache.cxf.endpoint.Client) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) WebClient(org.apache.cxf.jaxrs.client.WebClient) HelloWorld(org.apache.cxf.systest.jaxrs.jaxws.HelloWorld)

Example 77 with HTTPConduit

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();
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) InputStream(java.io.InputStream) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SocketTimeoutException(java.net.SocketTimeoutException) Test(org.junit.Test)

Example 78 with HTTPConduit

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());
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Test(org.junit.Test)

Example 79 with HTTPConduit

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"));
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) ContentDisposition(org.apache.cxf.jaxrs.ext.multipart.ContentDisposition) PushbackInputStream(java.io.PushbackInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MultipartBody(org.apache.cxf.jaxrs.ext.multipart.MultipartBody) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 80 with HTTPConduit

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());
}
Also used : Bus(org.apache.cxf.Bus) DestinationFactory(org.apache.cxf.transport.DestinationFactory) Destination(org.apache.cxf.transport.Destination) JettyHTTPDestination(org.apache.cxf.transport.http_jetty.JettyHTTPDestination) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) ConfigurerImpl(org.apache.cxf.configuration.spring.ConfigurerImpl) QName(javax.xml.namespace.QName) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) JettyHTTPServerEngine(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) JettyHTTPDestination(org.apache.cxf.transport.http_jetty.JettyHTTPDestination)

Aggregations

HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)125 Client (org.apache.cxf.endpoint.Client)52 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)47 Test (org.junit.Test)42 URL (java.net.URL)35 Bus (org.apache.cxf.Bus)32 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)32 QName (javax.xml.namespace.QName)22 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)20 Service (javax.xml.ws.Service)16 KeyStore (java.security.KeyStore)15 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)15 Greeter (org.apache.hello_world.Greeter)14 SOAPService (org.apache.hello_world.services.SOAPService)14 TrustManager (javax.net.ssl.TrustManager)13 IOException (java.io.IOException)12 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)11 InputStream (java.io.InputStream)8 X509TrustManager (javax.net.ssl.X509TrustManager)8 BindingProvider (javax.xml.ws.BindingProvider)8