2016-06-21 19 views
0

У меня есть конечная точка в Спринг примененияSOAP Spring WSDL ссылка

package hello; 

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; 

import io.spring.guides.gs_producing_web_service.GetCountryRequest; 
import io.spring.guides.gs_producing_web_service.GetCountryResponse; 

@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; 
    } 
} 

и WebService конфигурации

package hello; 

import org.springframework.boot.context.embedded.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")); 
    } 
} 

Я бегу это как приложение пружины загрузки с помощью сервера Tomcat поместить его и он запускается нормально

у меня также есть тест, который проходит нормально

/* 
* Copyright 2014-2015 the original author or authors. 
* 
* Licensed 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 hello; 

import static org.junit.Assert.assertNotNull; 
import io.spring.guides.gs_producing_web_service.GetCountryRequest; 

import org.junit.Before; 
import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.springframework.beans.factory.annotation.Value; 
import org.springframework.boot.test.SpringApplicationConfiguration; 
import org.springframework.boot.test.WebIntegrationTest; 
import org.springframework.oxm.jaxb.Jaxb2Marshaller; 
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 
import org.springframework.util.ClassUtils; 
import org.springframework.ws.client.core.WebServiceTemplate; 

@RunWith(SpringJUnit4ClassRunner.class) 
@SpringApplicationConfiguration(classes = Application.class) 
@WebIntegrationTest(randomPort = true) 
public class ApplicationTests { 

    private Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); 

    @Value("${local.server.port}") 
    private int port = 0; 

    @Before 
    public void init() throws Exception { 
     marshaller.setPackagesToScan(ClassUtils.getPackageName(GetCountryRequest.class)); 
     marshaller.afterPropertiesSet(); 
    } 

    @Test 
    public void testSendAndReceive() { 
     GetCountryRequest request = new GetCountryRequest(); 
     request.setName("Spain"); 
     assertNotNull(new WebServiceTemplate(marshaller).marshalSendAndReceive("http://localhost:" 
       + port + "/ws", request)); 
    } 

} 

Теперь я хочу получить wsdl, чтобы иметь возможность сделать клиента. Я уже пробовал много ссылок, но все они не работают. кто-нибудь может что-то посоветовать?

+0

Я использовал пример по этой ссылке: https://spring.io/guides/gs/producing-web-service/ – VadOs

ответ