Search in sources :

Example 46 with JacksonJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in project cxf by apache.

the class JAXRSRxJava3ObservableTest method testGetHelloWorldJson.

@Test
public void testGetHelloWorldJson() throws Exception {
    String address = "http://localhost:" + PORT + "/rx3/observable/textJson";
    List<Object> providers = new LinkedList<>();
    providers.add(new JacksonJsonProvider());
    providers.add(new ObservableRxInvokerProvider());
    WebClient wc = WebClient.create(address, providers);
    Observable<HelloWorldBean> obs = wc.accept("application/json").rx(ObservableRxInvoker.class).get(HelloWorldBean.class);
    Holder<HelloWorldBean> holder = new Holder<>();
    Disposable d = obs.subscribe(v -> {
        holder.value = v;
    });
    if (d == null) {
        throw new IllegalStateException("Subscribe did not return a Disposable");
    }
    Thread.sleep(2000);
    assertEquals("Hello", holder.value.getGreeting());
    assertEquals("World", holder.value.getAudience());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) Holder(javax.xml.ws.Holder) ObservableRxInvoker(org.apache.cxf.jaxrs.rx3.client.ObservableRxInvoker) WebClient(org.apache.cxf.jaxrs.client.WebClient) LinkedList(java.util.LinkedList) ObservableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.ObservableRxInvokerProvider) Test(org.junit.Test)

Example 47 with JacksonJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in project cxf by apache.

the class JAXRSRxJava3ObservableTest method doTestGetHelloWorldJsonList.

private void doTestGetHelloWorldJsonList(String address) throws Exception {
    WebClient wc = WebClient.create(address, Collections.singletonList(new JacksonJsonProvider()));
    WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000);
    GenericType<List<HelloWorldBean>> genericResponseType = new GenericType<List<HelloWorldBean>>() {
    };
    List<HelloWorldBean> beans = wc.accept("application/json").get(genericResponseType);
    assertEquals(2, beans.size());
    assertEquals("Hello", beans.get(0).getGreeting());
    assertEquals("World", beans.get(0).getAudience());
    assertEquals("Ciao", beans.get(1).getGreeting());
    assertEquals("World", beans.get(1).getAudience());
}
Also used : GenericType(javax.ws.rs.core.GenericType) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) List(java.util.List) LinkedList(java.util.LinkedList) WebClient(org.apache.cxf.jaxrs.client.WebClient)

Example 48 with JacksonJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in project cxf by apache.

the class JAXRSRxJava3ObservableTest method testObservableImmediateErrorsWithExceptionMapper.

@Test
public void testObservableImmediateErrorsWithExceptionMapper() throws Exception {
    String address = "http://localhost:" + PORT + "/rx3/observable/immediate/mapper/errors";
    final Observable<Response> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new ObservableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(ObservableRxInvoker.class).get();
    final TestObserver<Response> subscriber = new TestObserver<>();
    obs.subscribe(subscriber);
    subscriber.await(3, TimeUnit.SECONDS);
    subscriber.assertValue(r -> r.getStatus() == 409 && r.readEntity(String.class).contains("stackTrace")).assertComplete();
}
Also used : Response(javax.ws.rs.core.Response) BeforeClass(org.junit.BeforeClass) WebClient(org.apache.cxf.jaxrs.client.WebClient) Assert.assertTrue(org.junit.Assert.assertTrue) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Test(org.junit.Test) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) TimeUnit(java.util.concurrent.TimeUnit) GenericType(javax.ws.rs.core.GenericType) ClientBuilder(javax.ws.rs.client.ClientBuilder) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) ObservableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.ObservableRxInvokerProvider) List(java.util.List) MediaType(javax.ws.rs.core.MediaType) ObservableRxInvoker(org.apache.cxf.jaxrs.rx3.client.ObservableRxInvoker) Response(javax.ws.rs.core.Response) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Observable(io.reactivex.rxjava3.core.Observable) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) Disposable(io.reactivex.rxjava3.disposables.Disposable) Holder(javax.xml.ws.Holder) LinkedList(java.util.LinkedList) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ObservableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.ObservableRxInvokerProvider) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ObservableRxInvoker(org.apache.cxf.jaxrs.rx3.client.ObservableRxInvoker) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 49 with JacksonJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in project cxf by apache.

the class JAXRSRxJava3ObservableTest method testObservableImmediateErrors.

@Test
public void testObservableImmediateErrors() throws Exception {
    String address = "http://localhost:" + PORT + "/rx3/observable/immediate/errors";
    final Observable<HelloWorldBean> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new ObservableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(ObservableRxInvoker.class).get(HelloWorldBean.class);
    final TestObserver<HelloWorldBean> subscriber = new TestObserver<>();
    obs.subscribe(subscriber);
    subscriber.await(3, TimeUnit.SECONDS);
    subscriber.assertError(InternalServerErrorException.class);
}
Also used : ObservableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.ObservableRxInvokerProvider) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ObservableRxInvoker(org.apache.cxf.jaxrs.rx3.client.ObservableRxInvoker) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 50 with JacksonJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider in project cxf by apache.

the class JAXRSRxJava2SingleTest method testGetHelloWorldJson.

@Test
public void testGetHelloWorldJson() throws Exception {
    String address = "http://localhost:" + PORT + "/rx2/single/textJson";
    final Flowable<HelloWorldBean> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new FlowableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(FlowableRxInvoker.class).get(HelloWorldBean.class);
    final TestSubscriber<HelloWorldBean> subscriber = new TestSubscriber<>();
    obs.subscribe(subscriber);
    subscriber.await(3, TimeUnit.SECONDS);
    subscriber.assertValue(r -> "Hello".equals(r.getGreeting()) && "World".equals(r.getAudience())).assertComplete();
}
Also used : FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx2.client.FlowableRxInvokerProvider) BeforeClass(org.junit.BeforeClass) Assert.assertTrue(org.junit.Assert.assertTrue) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Test(org.junit.Test) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) TimeUnit(java.util.concurrent.TimeUnit) ClientBuilder(javax.ws.rs.client.ClientBuilder) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) MediaType(javax.ws.rs.core.MediaType) Flowable(io.reactivex.Flowable) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) FlowableRxInvoker(org.apache.cxf.jaxrs.rx2.client.FlowableRxInvoker) TestSubscriber(io.reactivex.subscribers.TestSubscriber) FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx2.client.FlowableRxInvokerProvider) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) FlowableRxInvoker(org.apache.cxf.jaxrs.rx2.client.FlowableRxInvoker) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Aggregations

JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)225 WebClient (org.apache.cxf.jaxrs.client.WebClient)152 Response (javax.ws.rs.core.Response)129 ArrayList (java.util.ArrayList)112 HashMap (java.util.HashMap)104 URL (java.net.URL)103 Book (org.apache.cxf.systest.jaxrs.security.Book)76 Test (org.junit.Test)66 JwtAuthenticationClientFilter (org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter)50 JwtClaims (org.apache.cxf.rs.security.jose.jwt.JwtClaims)50 JwtToken (org.apache.cxf.rs.security.jose.jwt.JwtToken)45 List (java.util.List)31 ClientBuilder (javax.ws.rs.client.ClientBuilder)28 Number (org.apache.coheigea.cxf.jaxrs.json.common.Number)28 LinkedList (java.util.LinkedList)27 GenericType (javax.ws.rs.core.GenericType)27 JwsWriterInterceptor (org.apache.cxf.rs.security.jose.jaxrs.JwsWriterInterceptor)27 MediaType (javax.ws.rs.core.MediaType)26 AbstractResourceInfo (org.apache.cxf.jaxrs.model.AbstractResourceInfo)26 AbstractBusClientServerTestBase (org.apache.cxf.testutil.common.AbstractBusClientServerTestBase)26