Server did not recognize the value of HTTP Header SOAPAction 解决
当出现如标题的exception时,恰好你正在使用https://spring.io/guides/gs/consuming-web-service/ 进行soap对接,不要慌。我刚踩过这个坑。
首先用wsdl生成各种类:
然后引入dependency
<dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-ws-core</artifactId> </dependency>
引入plugin
<plugin> <groupId>org.jvnet.jaxb2.maven2</groupId> <artifactId>maven-jaxb2-plugin</artifactId> <version>0.12.3</version> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> <configuration> <schemaLanguage>WSDL</schemaLanguage> <generatePackage>com.wuxiapptec.givenchy.email</generatePackage> <schemas> <schema> <fileset> <!-- Defaults to schemaDirectory. --> <directory>${basedir}/src/main/resources/schemas</directory> <!-- Defaults to schemaIncludes. --> <includes> <include>*.wsdl</include> </includes> <!-- Defaults to schemaIncludes --> <!--<excludes>--> <!--<exclude>*.xs</exclude>--> <!--</excludes>--> </fileset> <!--<url>http://localhost:8080/ws/countries.wsdl</url>--> </schema> </schemas> </configuration> </plugin>
配置web service
@Configuration public class EmailClientConfig { @Bean public Jaxb2Marshaller marshaller() { Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); // this package must match the package in the <generatePackage> specified in // pom.xml marshaller.setContextPath("com.wuxiapptec.givenchy.email"); return marshaller; } @Bean public EmailClient emailClient(Jaxb2Marshaller marshaller) { EmailClient client = new EmailClient(); client.setDefaultUri("http://w01app39.pharmatechs.com/ServiceCenter/MailCenter.asmx"); client.setMarshaller(marshaller); client.setUnmarshaller(marshaller); return client; } 封装调用方法:
public class EmailClient extends WebServiceGatewaySupport {
private static final Logger log = LoggerFactory.getLogger(EmailClient.class);
public SendMailResponse sendEmail(SendMail request) {
log.info("Requesting location for " + request);
WebServiceTemplate template = getWebServiceTemplate();
SendMailResponse response = (SendMailResponse) template
.marshalSendAndReceive(request,
new SoapActionCallback(
"http://service.pharmatechs.sh.cn/sendMail"));
return response;
}
}
注意加红部分,是导致异常的原因。这个action url从哪里来的呢?
看生成wsdl的链接。
保证action 和红框一致即可。