Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import br.com.willianantunes.serenata.JarbasAPI;
import br.com.willianantunes.support.ScenarioBuilder;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Producer;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.ExchangeBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.common.message.CxfConstants;
import org.apache.camel.component.cxf.jaxrs.CxfRsBinding;
import org.apache.camel.component.cxf.jaxrs.CxfRsEndpoint;
import org.apache.camel.component.cxf.jaxrs.CxfRsProducer;
import org.apache.camel.component.cxf.spring.SpringJAXRSClientFactoryBean;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.test.spring.CamelSpringBootRunner;
import org.apache.camel.test.spring.UseAdviceWith;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(CamelSpringBootRunner.class)
@UseAdviceWith
@SpringBootTest
public class CxfRouteTest {
@Autowired
private ModelCamelContext camelContext;
@Autowired
private ProducerTemplate producerTemplate;
@Autowired
private ScenarioBuilder scenarioBuilder;
@Autowired
private ApplicationContext applicationContext;
@Test
public void test() throws Exception {
SpringJAXRSClientFactoryBean serviceEndpointViaXML = applicationContext.getBean("serviceEndpointViaXML", SpringJAXRSClientFactoryBean.class);
SpringJAXRSClientFactoryBean serviceEndpoint = applicationContext.getBean("serviceEndpoint", SpringJAXRSClientFactoryBean.class);
// String uri = "cxfrs://bean://serviceEndpoint"; // does not work
String uri = "cxfrs://bean://serviceEndpointViaXML"; // works
CxfRsEndpoint endpoint = camelContext.getEndpoint(uri, CxfRsEndpoint.class);
endpoint.start(); // to make binding available at https://github.com/apache/camel/blob/834a59910e4b6b8d089e229b39f6c8673e7c3f9a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java#L282
CxfRsProducer producer = (CxfRsProducer)endpoint.createProducer();
Exchange exchange = new ExchangeBuilder(camelContext)
.withBody(6470354)
.withHeader(CxfConstants.OPERATION_NAME, "reimbursementByDocumentId")
.withHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, false)
.withPattern(ExchangePattern.InOut).build();
producer.process(exchange);
assertThat(exchange.getOut().getBody()).isNotNull();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment