springboot 使用cfx作为服务端,axis1.4作为客户端,遇到的问题

1、提示java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

这是传递参数中带有特殊字符串,解决如下:

第一种:

@Configuration
public class WebMvcConfigurerAdapter implements WebMvcConfigurer {

    @Bean
    public ServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory fa = new TomcatServletWebServerFactory();
        fa.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> connector.setProperty("relaxedQueryChars", "|{}?&[]"));
        return fa;
    }
}

第二种:

@Component
public class WebServerCustomizer implements WebServerFactoryCustomizer {
    @Override
    public void customize(WebServerFactory factory) {
        ((TomcatServletWebServerFactory)factory).addConnectorCustomizers(connector -> {
            connector.setProperty("relaxedQueryChars", "|{}?&[]");
        });
    }
}

2、服务端忽略webservice的命名空间

public class ServerNameSpaceInterceptor extends AbstractPhaseInterceptor {

    public ServerNameSpaceInterceptor(){
        super(Phase.RECEIVE);
    }

    @Override
    public void handleMessage(Message message) throws Fault {
        for (ServiceInfo si : message.getExchange().getService().getServiceInfos()) {
            si.setProperty("soap.force.doclit.bare",true);
        }
    }
}
@Configuration
public class CxfConfigFor4A {
     /**
     * 注意这个方法名 网上好多用dispatcherServlet启动会报错
     */
    @Bean
    public ServletRegistrationBean getDispatcherServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/cxf/*");// 发布服务名称 localhost:8080/cxf
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    public Endpoint updateAppSoap() {
        EndpointImpl endpoint = new EndpointImpl(springBus(),beanName);
        endpoint.publish("/updateAppSoap"); // 接口访问地址
        endpoint.getInInterceptors().add(new ServerNameSpaceInterceptor());
        return endpoint;
    }

}

 

你可能感兴趣的:(SpringBoot)