【问题标题】:Spring-WS SOAP Endpoint 405 Method not allowed不允许使用 Spring-WS SOAP 端点 405 方法
【发布时间】:2017-10-09 13:09:45
【问题描述】:

您好,我正在尝试创建 @endpoint SOAP 服务,但是当我尝试获取 WSDL 时,我得到了 405 Method Not Allowed。

有我的服务端点:

@Endpoint
public class SubscribeMemberService {

        public static final String NAMESPACE_URI = "urn:v1.webservice.subscription.test.org";

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "subscribe")
    @ResponsePayload
    public SubscribeMemberResponse subscribe(@RequestPayload  SubscribeMemberRequest request) throws SubscribeMemberFault_Exception {
        LOG.info("request received: LastName:" + request.getName().getLastName());

            SubscribeMemberResponse response = new SubscribeMemberResponse();
            response.setInfoMessage("Subscription of  " + request.getName().getLastName());
            LOG.info("sending response:" + request.getName().getLastName());
            return response;

    }

}

还有我的 WS 配置:

@EnableWs
@Configuration
@ComponentScan("org.test")
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 = "subscribeMember")
        public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema subscribeMember) {
                DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
                wsdl11Definition.setPortTypeName("subscribeMemberPort");
                wsdl11Definition.setLocationUri("/ws");
                wsdl11Definition.setTargetNamespace(SubscribeMemberService.NAMESPACE_URI);
                wsdl11Definition.setSchema(subscribeMember);
                return wsdl11Definition;
        }

        @Bean
        public XsdSchema subscribeMemberSchema() {
                return new SimpleXsdSchema(new ClassPathResource("META-INF/wsdl/subscribeMember.xsd"));
        }
}

是否可以链接到 WebSecurityConfigurerAdapter?因为在 /ws/* 上我没有 404 not found ,但我得到 405 not allowed 。有什么想法吗?

注意:WebSecurityConfigurerAdapter 类中的安全过滤器是

protected void configure(HttpSecurity http) throws Exception {
        http.httpBasic()
                .and()
                .authorizeRequests()
                .anyRequest().hasRole("mySuperRole").and()
                .csrf().disable();
}

【问题讨论】:

  • 也许我发现了问题“使用浏览器访问 SOAP 服务时(即通过 GET)获取 405(不允许的方法)错误代码实际上是正确的行为:所有 SOAP HTTP 访问都是通过一个 POST,而不是一个 GET。您可以尝试将 SOAP 客户端指向 WSDL(例如 SoapUI),看看是否可以代替。 stackoverflow.com/questions/27198987/…我会用 SoapUI 测试一下
  • 不,它不适用于 SOAP UI:“加载时出错 [localhost:8080/subscription-webservice/v1/ws/…: org.apache.xmlbeans.XmlException: org.apache.xmlbeans.XmlException: 错误:nul 后文件意外结束。”无论如何,应该可以通过 GET 访问 wsdl 文件。

标签: spring-boot spring-security spring-ws


【解决方案1】:

我找到了解决办法:

  1. 我禁用了 WebSecurityConfigurerAdapter 以确保这不是来自安全性的问题。
  2. 我在日志中发现了一个问题:“SAAJ0511:无法从给定来源创建信封”
  3. 为了解决这个问题,我决定使用官方教程 (https://spring.io/guides/gs/producing-web-service/#_generate_domain_classes_based_on_an_xml_schema) 中的 maven 插件“jaxb2-maven-plugin”代替“jaxws-maven-plugin”。我将 wsdl 文件移动到 /resources 中。
  4. 我使用本教程转换了我的 SOAP 异常:http://memorynotfound.com/spring-ws-add-detail-soapfault-exception-handling/
  5. 我重新启用了 WebSecurityConfigurerAdapter

【讨论】:

    猜你喜欢
    • 2014-09-19
    • 2015-08-14
    • 2022-01-07
    • 2016-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-15
    • 1970-01-01
    相关资源
    最近更新 更多