Forráskód Böngészése

1.新增webservice

WoNiu 4 éve
szülő
commit
3291312e4d

+ 42 - 0
pom.xml

@@ -97,6 +97,14 @@
             <artifactId>capsule</artifactId>
             <version>1.0-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web-services</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>wsdl4j</groupId>
+            <artifactId>wsdl4j</artifactId>
+        </dependency>
     </dependencies>
 
     <dependencyManagement>
@@ -111,6 +119,22 @@
         </dependencies>
     </dependencyManagement>
 
+    <profiles>
+        <profile>
+            <id>java11</id>
+            <activation>
+                <jdk>[11,)</jdk>
+            </activation>
+
+            <dependencies>
+                <dependency>
+                    <groupId>org.glassfish.jaxb</groupId>
+                    <artifactId>jaxb-runtime</artifactId>
+                </dependency>
+            </dependencies>
+        </profile>
+    </profiles>
+
 
     <build>
         <plugins>
@@ -118,6 +142,24 @@
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
             </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>jaxb2-maven-plugin</artifactId>
+                <version>2.5.0</version>
+                <executions>
+                    <execution>
+                        <id>xjc</id>
+                        <goals>
+                            <goal>xjc</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <sources>
+                        <source>${project.basedir}/src/main/resources/countries.xsd</source>
+                    </sources>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 

+ 1 - 0
src/main/java/com/galaxis/manatee/configuration/ManateeSecurity.java

@@ -40,6 +40,7 @@ public class ManateeSecurity extends WebSecurityConfigurerAdapter {
                 .antMatchers(HttpMethod.POST, SIGN_UP_URL).permitAll()
                 .antMatchers(HttpMethod.GET,GO_CONFIRM).permitAll()
                 .antMatchers(HttpMethod.GET,"/test/**").permitAll()
+                .antMatchers(HttpMethod.GET,"/ws/**").permitAll()
                 .anyRequest().authenticated()
                 .and()
                 .addFilter(new JwtAuthenticationFilter(authenticationManager()))

+ 40 - 0
src/main/java/com/galaxis/manatee/configuration/WebServiceConfig.java

@@ -0,0 +1,40 @@
+package com.galaxis.manatee.configuration;
+
+import org.springframework.boot.web.servlet.ServletRegistrationBean;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.ws.config.annotation.EnableWs;
+import org.springframework.ws.config.annotation.WsConfigurerAdapter;
+import org.springframework.ws.transport.http.MessageDispatcherServlet;
+import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
+import org.springframework.xml.xsd.SimpleXsdSchema;
+import org.springframework.xml.xsd.XsdSchema;
+
+@EnableWs
+@Configuration
+public class WebServiceConfig extends WsConfigurerAdapter {
+	@Bean
+	public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
+		MessageDispatcherServlet servlet = new MessageDispatcherServlet();
+		servlet.setApplicationContext(applicationContext);
+		servlet.setTransformWsdlLocations(true);
+		return new ServletRegistrationBean(servlet, "/ws/*");
+	}
+
+	@Bean(name = "countries")
+	public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
+		DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
+		wsdl11Definition.setPortTypeName("CountriesPort");
+		wsdl11Definition.setLocationUri("/ws");
+		wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
+		wsdl11Definition.setSchema(countriesSchema);
+		return wsdl11Definition;
+	}
+
+	@Bean
+	public XsdSchema countriesSchema() {
+		return new SimpleXsdSchema(new ClassPathResource("countries.xsd"));
+	}
+}

+ 51 - 0
src/main/java/com/galaxis/manatee/webservice/CountryEndpoint.java

@@ -0,0 +1,51 @@
+package com.galaxis.manatee.webservice;
+
+import io.spring.guides.gs_producing_web_service.GetCountryRequest;
+import io.spring.guides.gs_producing_web_service.GetCountryResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.ws.server.endpoint.annotation.Endpoint;
+import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
+import org.springframework.ws.server.endpoint.annotation.RequestPayload;
+import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
+
+@Endpoint
+public class CountryEndpoint {
+	private static final String NAMESPACE_URI = "http://spring.io/guides/gs-producing-web-service";
+
+	private CountryRepository countryRepository;
+
+	@Autowired
+	public CountryEndpoint(CountryRepository countryRepository) {
+		this.countryRepository = countryRepository;
+	}
+
+//	@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCountryRequest")
+//	@ResponsePayload
+//	public GetCountryResponse getCountry(@RequestPayload GetCountryRequest request) {
+//		GetCountryResponse response = new GetCountryResponse();
+//		response.setCountry(countryRepository.findCountry(request.getName()));
+//		return response;
+//	}
+
+	public String GetSchema(String schemaCode)
+	{
+		return null;
+	}
+
+	public String GetSchemaList()
+	{
+		return null;
+	}
+
+	public String GetList(String userCode, String schemaCode, String filter)
+	{
+		return null;
+	}
+
+    //氚云后端调用的方法名
+	public String Invoke(String userCode, String schemaCode, String methodName, String param)
+	{
+        //书写调用第三方接口方法
+		return null;
+	}
+}

+ 47 - 0
src/main/java/com/galaxis/manatee/webservice/CountryRepository.java

@@ -0,0 +1,47 @@
+package com.galaxis.manatee.webservice;
+
+import javax.annotation.PostConstruct;
+import java.util.HashMap;
+import java.util.Map;
+
+import io.spring.guides.gs_producing_web_service.Country;
+import io.spring.guides.gs_producing_web_service.Currency;
+import org.springframework.stereotype.Component;
+import org.springframework.util.Assert;
+
+@Component
+public class CountryRepository {
+	private static final Map<String, Country> countries = new HashMap<>();
+
+	@PostConstruct
+	public void initData() {
+		Country spain = new Country();
+		spain.setName("Spain");
+		spain.setCapital("Madrid");
+		spain.setCurrency(Currency.EUR);
+		spain.setPopulation(46704314);
+
+		countries.put(spain.getName(), spain);
+
+		Country poland = new Country();
+		poland.setName("Poland");
+		poland.setCapital("Warsaw");
+		poland.setCurrency(Currency.PLN);
+		poland.setPopulation(38186860);
+
+		countries.put(poland.getName(), poland);
+
+		Country uk = new Country();
+		uk.setName("United Kingdom");
+		uk.setCapital("London");
+		uk.setCurrency(Currency.GBP);
+		uk.setPopulation(63705000);
+
+		countries.put(uk.getName(), uk);
+	}
+
+	public Country findCountry(String name) {
+		Assert.notNull(name, "The country's name must not be null");
+		return countries.get(name);
+	}
+}

+ 36 - 0
src/main/resources/countries.xsd

@@ -0,0 +1,36 @@
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://spring.io/guides/gs-producing-web-service"
+           targetNamespace="http://spring.io/guides/gs-producing-web-service" elementFormDefault="qualified">
+
+    <xs:element name="getCountryRequest">
+        <xs:complexType>
+            <xs:sequence>
+                <xs:element name="name" type="xs:string"/>
+            </xs:sequence>
+        </xs:complexType>
+    </xs:element>
+
+    <xs:element name="getCountryResponse">
+        <xs:complexType>
+            <xs:sequence>
+                <xs:element name="country" type="tns:country"/>
+            </xs:sequence>
+        </xs:complexType>
+    </xs:element>
+
+    <xs:complexType name="country">
+        <xs:sequence>
+            <xs:element name="name" type="xs:string"/>
+            <xs:element name="population" type="xs:int"/>
+            <xs:element name="capital" type="xs:string"/>
+            <xs:element name="currency" type="tns:currency"/>
+        </xs:sequence>
+    </xs:complexType>
+
+    <xs:simpleType name="currency">
+        <xs:restriction base="xs:string">
+            <xs:enumeration value="GBP"/>
+            <xs:enumeration value="EUR"/>
+            <xs:enumeration value="PLN"/>
+        </xs:restriction>
+    </xs:simpleType>
+</xs:schema>