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

Cherry pick PR from 2.6.0 #355

Merged
merged 21 commits into from Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -22,4 +22,4 @@ logs
.m2
sofa-boot-gradle-plugin/build/
.gradle
sofa-boot-gradle-plugin/out/
sofa-boot-gradle-plugin/out/
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -5,7 +5,6 @@ jdk:
- oraclejdk8

install:

- mvn clean install -DskipTests -B -V
- mvn test

Expand Down
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -73,3 +73,7 @@ SOFA 的第一个版本是阿玺创造的,感谢阿玺给 SOFA 打下了坚实
## 七、文档

请参考 [SOFABoot 官方文档](http://www.sofastack.tech/sofa-boot/docs/Home)。

## 八、开源许可

SOFABoot 基于 Apache License 2.0 协议,SOFABoot 依赖了一些三方组件,它们的开源协议参见 [依赖组件版权说明](https://www.sofastack.tech/sofa-boot/docs/NOTICE)
11 changes: 0 additions & 11 deletions infra-sofa-boot-starter/pom.xml
Expand Up @@ -48,12 +48,6 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-jcl</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down Expand Up @@ -155,11 +149,6 @@
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
Expand Down
Expand Up @@ -19,6 +19,7 @@
import com.alipay.sofa.infra.config.spring.namespace.spi.SofaBootTagNameSupport;
import com.alipay.sofa.infra.log.InfraHealthCheckLoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;

Expand All @@ -29,6 +30,7 @@
* SofaBootNamespaceHandler
*
* @author yangguanchao
* @author qilong.zql
* @since 2018/04/08
*/
public class SofaBootNamespaceHandler extends NamespaceHandlerSupport {
Expand All @@ -38,19 +40,21 @@ public class SofaBootNamespaceHandler extends NamespaceHandlerSupport {

@Override
public void init() {
ServiceLoader<SofaBootTagNameSupport> serviceLoaderSofaBoot = ServiceLoader
.load(SofaBootTagNameSupport.class);
ServiceLoader<SofaBootTagNameSupport> serviceLoaderSofaBoot = ServiceLoader.load(SofaBootTagNameSupport.class);
serviceLoaderSofaBoot.forEach(this::registerTagParser);
}

private void registerTagParser(SofaBootTagNameSupport tagNameSupport) {
if (!(tagNameSupport instanceof BeanDefinitionParser)) {
logger.error("{} tag name supported [{}] parser are not instance of {}.",
tagNameSupport.getClass(), tagNameSupport.supportTagName(),
BeanDefinitionParser.class);
return;
if (tagNameSupport instanceof BeanDefinitionParser) {
registerBeanDefinitionParser(tagNameSupport.supportTagName(),
(BeanDefinitionParser) tagNameSupport);
} else if (tagNameSupport instanceof BeanDefinitionDecorator) {
registerBeanDefinitionDecoratorForAttribute(tagNameSupport.supportTagName(),
(BeanDefinitionDecorator) tagNameSupport);
} else {
logger.error(tagNameSupport.getClass() + " tag name supported ["
+ tagNameSupport.supportTagName() + "] parser are not instance of "
+ BeanDefinitionParser.class + "or " + BeanDefinitionDecorator.class);
}
String tagName = tagNameSupport.supportTagName();
registerBeanDefinitionParser(tagName, (BeanDefinitionParser) tagNameSupport);
}
}
Expand Up @@ -50,4 +50,26 @@ public class SofaBootInfraConstants {
*/
public static final String ENDPOINTS_WEB_EXPOSURE_INCLUDE_CONFIG = "management.endpoints.web.exposure.include";
public static final String SOFA_DEFAULT_ENDPOINTS_WEB_EXPOSURE_VALUE = "info, health, versions, readiness";

/**
* root application context name
*/
public static final String ROOT_APPLICATION_CONTEXT = "RootApplicationContext";

/**
* sofa configuration prefix
*/
public static final String PREFIX = "com.alipay.sofa.boot";

/**
* Thread Pool Core Size to execute async bean initialization
*/
public static final String ASYNC_INIT_BEAN_CORE_SIZE = PREFIX
+ ".asyncInitBeanCoreSize";

/**
* Thread Pool Max Size to execute async bean initialization
*/
public static final String ASYNC_INIT_BEAN_MAX_SIZE = PREFIX
+ ".asyncInitBeanMaxSize";
}
Expand Up @@ -33,6 +33,11 @@
</xsd:complexContent>
</xsd:complexType>

<!-- parameters in service/reference binding.* -->
<xsd:complexType name="TParameter">
<xsd:attribute name="key" type="xsd:string" use="required" />
<xsd:attribute name="value" type="xsd:string" use="required" />
</xsd:complexType>

<!-- Bolt Start -->

Expand Down Expand Up @@ -130,6 +135,7 @@
<xsd:element name="global-attrs" type="BBindingTRRefAttr" minOccurs="0" maxOccurs="1"/>
<xsd:element name="route" type="BBindingTRRefRoute" minOccurs="0" maxOccurs="1"/>
<xsd:element name="method" type="BBindingTRRefMethod" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="parameter" type="TParameter" minOccurs="0" maxOccurs="unbounded"/>
<xsd:any minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
Expand All @@ -142,6 +148,7 @@
<xsd:sequence minOccurs="0">
<xsd:element name="global-attrs" type="BBindingTRSerAttr" minOccurs="0" maxOccurs="1"/>
<xsd:element name="method" type="BBindingTRSerMethod" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="parameter" type="TParameter" minOccurs="0" maxOccurs="unbounded"/>
<xsd:any minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
Expand Down Expand Up @@ -243,6 +250,7 @@
<xsd:element name="global-attrs" type="RestBindingTRRefAttr" minOccurs="0" maxOccurs="1"/>
<xsd:element name="route" type="RestBindingTRRefRoute" minOccurs="0" maxOccurs="1"/>
<xsd:element name="method" type="RestBindingTRRefMethod" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="parameter" type="TParameter" minOccurs="0" maxOccurs="unbounded"/>
<xsd:any minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
Expand All @@ -255,6 +263,7 @@
<xsd:sequence minOccurs="0">
<xsd:element name="global-attrs" type="RestBindingTRSerAttr" minOccurs="0" maxOccurs="1"/>
<xsd:element name="method" type="RestBindingTRSerMethod" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="parameter" type="TParameter" minOccurs="0" maxOccurs="unbounded"/>
<xsd:any minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
Expand Down Expand Up @@ -367,6 +376,7 @@
<xsd:element name="global-attrs" type="DubboBindingTRRefAttr" minOccurs="0" maxOccurs="1"/>
<xsd:element name="route" type="DubboBindingTRRefRoute" minOccurs="0" maxOccurs="1"/>
<xsd:element name="method" type="DubboBindingTRRefMethod" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="parameter" type="TParameter" minOccurs="0" maxOccurs="unbounded"/>
<xsd:any minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
Expand All @@ -379,6 +389,7 @@
<xsd:sequence minOccurs="0">
<xsd:element name="global-attrs" type="DubboBindingTRSerAttr" minOccurs="0" maxOccurs="1"/>
<xsd:element name="method" type="DubboBindingTRSerMethod" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="parameter" type="TParameter" minOccurs="0" maxOccurs="unbounded"/>
<xsd:any minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
Expand Down Expand Up @@ -499,6 +510,7 @@
<xsd:element name="global-attrs" type="H2cBindingRefAttr" minOccurs="0" maxOccurs="1"/>
<xsd:element name="route" type="H2cBindingRefRoute" minOccurs="0" maxOccurs="1"/>
<xsd:element name="method" type="H2cBindingRefMethod" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="parameter" type="TParameter" minOccurs="0" maxOccurs="unbounded"/>
<xsd:any minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
Expand All @@ -511,6 +523,7 @@
<xsd:sequence minOccurs="0">
<xsd:element name="global-attrs" type="H2cBindingSerAttr" minOccurs="0" maxOccurs="1"/>
<xsd:element name="method" type="H2cBindingSerMethod" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="parameter" type="TParameter" minOccurs="0" maxOccurs="unbounded"/>
<xsd:any minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
Expand Down Expand Up @@ -593,4 +606,7 @@
</xsd:complexType>
<!-- registry.confreg -->

<!-- async init -->
<xsd:attribute name="async-init" type="xsd:boolean"/>

</xsd:schema>
Expand Up @@ -20,6 +20,7 @@

<xsd:schema xmlns="http://sofastack.io/schema/sofaboot"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:beans="http://www.springframework.org/schema/beans"
targetNamespace="http://sofastack.io/schema/sofaboot"
elementFormDefault="qualified" attributeFormDefault="unqualified">

Expand All @@ -30,4 +31,52 @@
<!-- http://itdoc.hitachi.co.jp/manuals/3020/30203Y4340e/EY430034.HTM -->
<xsd:include schemaLocation="./rpc.xsd"/>

<!-- extension-point -->
<xsd:element name="extension-point" type="Textension-point"/>

<xsd:complexType name="Textension-point">
<xsd:complexContent>
<xsd:extension base="beans:identifiedType">
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element name="object" type="Tobject" minOccurs="0"/>
<!-- nested bean declaration -->
<xsd:any namespace="##other" minOccurs="0" maxOccurs="1" processContents="skip"/>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="ref" type="xsd:string"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="Tobject">
<xsd:attribute name="class" type="xsd:string" use="required"/>
</xsd:complexType>

<xsd:element name="extension" type="Textension"/>

<xsd:complexType name="Textension">
<xsd:complexContent>
<xsd:extension base="beans:identifiedType">
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element name="require" type="Trequire" minOccurs="0"/>
<xsd:element name="content" type="Tcontent" minOccurs="0"
maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="bean" type="xsd:string" use="required"/>
<xsd:attribute name="point" type="xsd:string" use="required"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="Trequire">
<xsd:attribute name="bean" type="xsd:string" use="required"/>
</xsd:complexType>

<xsd:complexType name="Tcontent">
<xsd:sequence>
<xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="skip"/>
</xsd:sequence>
</xsd:complexType>


</xsd:schema>
@@ -0,0 +1,83 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.infra.config.spring;

import com.sun.org.apache.xml.internal.utils.DefaultErrorHandler;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.xml.DefaultDocumentLoader;
import org.springframework.beans.factory.xml.DelegatingEntityResolver;
import org.springframework.beans.factory.xml.DocumentLoader;
import org.springframework.util.xml.XmlValidationModeDetector;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;

/**
* XML validation with rpc.xsd
*
* @author <a href="mailto:scienjus@gmail.com">ScienJus</a>
*/
public class XsdValidationTest {

@Test
public void testSofaParameter() throws Exception {
loadXml("config/spring/test_sofa_parameter.xml");
}

@Test
public void testSofaParameterMissingKey() throws Exception {
try {
loadXml("config/spring/test_sofa_parameter_missing_key.xml");
Assert.fail();
} catch (SAXParseException e) {
// org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 52;
// cvc-complex-type.4: Attribute 'key' must appear on element 'sofa:parameter'.
assertSaxException(10, 52, "cvc-complex-type.4", e);
}
}

@Test
public void testSofaParameterOutsideBinding() throws Exception {
try {
loadXml("config/spring/test_sofa_parameter_outside_binding.xml");
Assert.fail();
} catch (SAXParseException e) {
// org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 65;
// cvc-complex-type.2.4.a: Invalid content was found starting with element 'sofa:parameter'.
// One of '{"http://sofastack.io/schema/sofaboot":binding.jvm,
// "http://sofastack.io/schema/sofaboot":binding.rest,
// "http://sofastack.io/schema/sofaboot":binding.dubbo,
// "http://sofastack.io/schema/sofaboot":binding.h2c}' is expected.
assertSaxException(11, 65, "cvc-complex-type.2.4.a", e);
}
}

private void assertSaxException(int expectedLineNumber, int expectedColumnNumber,
String expectedErrorCode, SAXParseException e) {
Assert.assertEquals(expectedLineNumber, e.getLineNumber());
Assert.assertEquals(expectedColumnNumber, e.getColumnNumber());
Assert.assertEquals(expectedErrorCode, e.getMessage().split(":")[0]);
}

private void loadXml(String xml) throws Exception {
DocumentLoader documentLoader = new DefaultDocumentLoader();
documentLoader.loadDocument(new InputSource(this.getClass().getClassLoader()
.getResourceAsStream(xml)), new DelegatingEntityResolver(this.getClass()
.getClassLoader()), new DefaultErrorHandler(),
XmlValidationModeDetector.VALIDATION_XSD, true);
}
}
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sofa="http://sofastack.io/schema/sofaboot"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://sofastack.io/schema/sofaboot http://sofastack.io/schema/sofaboot.xsd">

<sofa:reference id="helloSyncService" interface="com.alipay.sofa.rpc.boot.invoke.HelloSyncService">
<sofa:binding.bolt>
<sofa:parameter key="static_key" value="static_value" />
<sofa:parameter key="${dynamic_key}" value="${dynamic_value}" />
</sofa:binding.bolt>
</sofa:reference>

<sofa:service ref="helloSyncServiceImpl" interface="com.alipay.sofa.rpc.boot.invoke.HelloSyncService">
<sofa:binding.rest>
<sofa:parameter key="static_key" value="static_value"/>
<sofa:parameter key="${dynamic_key}" value="${dynamic_value}" />
</sofa:binding.rest>
</sofa:service>

<bean id="helloSyncServiceImpl" class="com.alipay.sofa.rpc.boot.invoke.HelloSyncServiceImpl"/>
</beans>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sofa="http://sofastack.io/schema/sofaboot"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://sofastack.io/schema/sofaboot http://sofastack.io/schema/sofaboot.xsd">

<sofa:reference id="helloSyncService" interface="com.alipay.sofa.rpc.boot.invoke.HelloSyncService">
<sofa:binding.bolt>
<sofa:parameter value="static_value" />
</sofa:binding.bolt>
</sofa:reference>

</beans>