我已按照本指南使用我的第一个网络服务:https://spring.io/guides/gs/consuming-web-service/
没关系,正常工作。
但现在我需要添加另一个webservice。我尝试创建另一个Marshaller配置文件,但是当springboot启动时,它只加载一个marshall配置。
任何人都知道如何使用多个marshaller?
我尝试使用与下面相同的Marshal配置文件: package checkverification.atmncn;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
@Configuration
public class AtmNcnClientConfiguration {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPaths("checkverification.atmncn.wsdl.test", "checkverification.atmncn.wsdl.live");
return marshaller;
}
@Bean
public AtmNcnLiveClient atmNcnLiveClient(Jaxb2Marshaller marshaller) {
AtmNcnLiveClient client = new AtmNcnLiveClient();
client.setDefaultUri("https://ws.paymentsgateway.net/pg");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
@Bean
public AtmNcnTestClient atmNcnTestClient(Jaxb2Marshaller marshaller) {
AtmNcnTestClient client = new AtmNcnTestClient();
client.setDefaultUri("https://ws.paymentsgateway.net/pgtest");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
}
但是当我试图使用客户端时,我收到了一个强制转换异常:
[Internal Server Error]
checkverification.atmncn.wsdl.live.ExecuteSocketDelimitedQueryResponse cannot be cast to
checkverification.atmncn.wsdl.test.ExecuteSocketDelimitedQueryResponse
所以我认为我只需要一名编组人员并为这个编组人员配置多个网络服务......但我无法弄清楚我该怎么做......
PS:两个web服务具有相同的方法和类,但有不同的URL(一个用于测试,另一个用于生产)。所以也许它会导致演员异常...
我的工人阶级是一个控制器,它很长,所以我只会粘贴主要代码:
@RestController
@RequestMapping("/cvapi")
public class TransactionApiController {
@Autowired
AtmNcnTestClient atmNcnTestClient;
@Autowired
AtmNcnLiveClient atmNcnLiveClient;
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Object> submit(@RequestBody @Valid Transaction transaction, HttpServletRequest request) {
// a lot of code with the controller logic...
// Do a Test Post
if(as.getTestMode() || licenseNumberType == VerifyType.TEST) {
checkverification.atmncn.wsdl.test.ExecuteSocketDelimitedQueryResponse res =
atmNcnTestClient.executeSocketDelimitedQueryResponseTest(params); // ---->>> ERROR IN THIS LINE
atmNcnResultWrapper = AtmNcnParameterBuilder.getResult(
res.getExecuteSocketDelimitedQueryResult());
} else {
// Live Post
checkverification.atmncn.wsdl.live.ExecuteSocketDelimitedQueryResponse res =
atmNcnLiveClient.executeSocketDelimitedQueryLive(params);
atmNcnResultWrapper = AtmNcnParameterBuilder.getResult(
res.getExecuteSocketDelimitedQueryResult());
}
// a lot of code to generate the response
} // end of method
}