Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAMEL-12541: rsClient does not work programmatically, only with XML #2350

Merged
merged 3 commits into from
May 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ protected JAXRSServerFactoryBean newJAXRSServerFactoryBean() {

@Override
protected JAXRSClientFactoryBean newJAXRSClientFactoryBean() {
return new SpringJAXRSClientFactoryBean();
checkBeanType(bean, JAXRSClientFactoryBean.class);
return (JAXRSClientFactoryBean)bean;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.apache.cxf.version.Version;
import org.junit.Test;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class CxfRsSpringEndpointTest extends CamelSpringTestSupport {

private static final String BEAN_SERVICE_ENDPOINT_NAME = "serviceEndpoint";
private static final String BEAN_SERVICE_ADDRESS = "http://localhost/programmatically";
private static final String BEAN_SERVICE_USERNAME = "BEAN_SERVICE_USERNAME";
private static final String BEAN_SERVICE_PASSWORD = "BEAN_SERVICE_PASSWORD";

@Test
public void testCreateCxfRsServerFactoryBean() {
CxfRsEndpoint endpoint = resolveMandatoryEndpoint("cxfrs://bean://rsServer", CxfRsEndpoint.class);
Expand Down Expand Up @@ -62,13 +69,51 @@ public void testCreateCxfRsClientFactoryBean() {

}

@Test
public void testCreateCxfRsClientFactoryBeanProgrammatically() {

CxfRsEndpoint endpoint = resolveMandatoryEndpoint("cxfrs://bean://" + BEAN_SERVICE_ENDPOINT_NAME, CxfRsEndpoint.class);
SpringJAXRSClientFactoryBean cfb = (SpringJAXRSClientFactoryBean)endpoint.createJAXRSClientFactoryBean();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may need to check the instance of cfb is not the one we set before.


assertEquals("Got the wrong address", BEAN_SERVICE_ADDRESS, cfb.getAddress());
assertNotNull("Service class must not be null", cfb.getServiceClass());
assertEquals("Got the wrong ServiceClass", CustomerService.class, cfb.getServiceClass());
assertEquals("Got the wrong username", BEAN_SERVICE_USERNAME, cfb.getUsername());
assertEquals("Got the wrong password", BEAN_SERVICE_PASSWORD, cfb.getPassword());
}

public static SpringJAXRSClientFactoryBean serviceEndpoint() {

SpringJAXRSClientFactoryBean clientFactoryBean = new SpringJAXRSClientFactoryBean();
clientFactoryBean.setAddress(BEAN_SERVICE_ADDRESS);
clientFactoryBean.setServiceClass(CustomerService.class);
clientFactoryBean.setUsername(BEAN_SERVICE_USERNAME);
clientFactoryBean.setPassword(BEAN_SERVICE_PASSWORD);

return clientFactoryBean;
}

@Override
protected AbstractXmlApplicationContext createApplicationContext() {
String version = Version.getCurrentVersion();

ClassPathXmlApplicationContext applicationContext = null;

if (version.startsWith("2") && (version.contains("2.5") || version.contains("2.4"))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version check could be removed as we already move to 2.6.x

return new ClassPathXmlApplicationContext(new String("org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointBeans.xml"));
applicationContext = new ClassPathXmlApplicationContext(new String("org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointBeans.xml"));
} else {
applicationContext = new ClassPathXmlApplicationContext(new String("org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointBeans-2.6.xml"));
}
return new ClassPathXmlApplicationContext(new String("org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpointBeans-2.6.xml"));

emulateBeanRegistrationProgrammatically(applicationContext);

return applicationContext;
}

}
private void emulateBeanRegistrationProgrammatically(ClassPathXmlApplicationContext applicationContext) {

DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) applicationContext.getBeanFactory();
BeanDefinitionBuilder definitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(CxfRsSpringEndpointTest.class.getName()).setFactoryMethod("serviceEndpoint");
beanFactory.registerBeanDefinition(BEAN_SERVICE_ENDPOINT_NAME, definitionBuilder.getBeanDefinition());
}
}