Created
October 18, 2013 20:06
-
-
Save aVolpe/7047456 to your computer and use it in GitHub Desktop.
ServiceDefinitionRegister.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ServiceDefinitionRegister implements BeanFactoryPostProcessor { | |
Logger logger = LoggerFactory.getLogger(ServiceDefinitionRegister.class); | |
@Override | |
public void postProcessBeanFactory(ConfigurableListableBeanFactory bf) | |
throws BeansException { | |
Map<String, Object> beans = bf.getBeansWithAnnotation(WebService.class); | |
for (Entry<String, Object> entry : beans.entrySet()) { | |
Object bean = entry.getValue(); | |
WebService ws = bean.getClass().getAnnotation(WebService.class); | |
String name = getName(entry.getKey()); | |
DefaultWsdl11Definition newWS = createWebService(name, ws.xsds()); | |
bf.registerSingleton(name, newWS); | |
bf.autowireBeanProperties(bean, | |
RootBeanDefinition.AUTOWIRE_BY_TYPE, false); | |
} | |
} | |
private String getName(String beanName) { | |
return beanName | |
.substring(0, beanName.toUpperCase().indexOf("ENDPOINT")); | |
} | |
/** | |
* @param path1 | |
* @param path2 | |
* @param name | |
* @return | |
* @throws IOException | |
*/ | |
private DefaultWsdl11Definition createWebService(String name, | |
String ... strings) { | |
logger.info("Creating Menu Web Service"); | |
DefaultWsdl11Definition toRet = new DefaultWsdl11Definition(); | |
toRet.setPortTypeName(name); | |
toRet.setServiceName(name); | |
Resource[] resources = new Resource[strings.length]; | |
for (int i = 0; i < strings.length; i++) { | |
resources[i] = new ClassPathResource(strings[i]); | |
if (!resources[i].exists()) { | |
throw new RuntimeException("XSD with url: " + strings[i] | |
+ " doesn't exist!"); | |
} | |
} | |
CommonsXsdSchemaCollection collection = new CommonsXsdSchemaCollection(); | |
collection.setInline(true); | |
collection.setXsds(resources); | |
try { | |
collection.afterPropertiesSet(); | |
} catch (IOException e) { | |
throw new KarakuRuntimeException("Check XML location", e); | |
} | |
toRet.setSchemaCollection(collection); | |
toRet.setLocationUri("/endpoints"); | |
return toRet; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment