gpt4 book ai didi

java - 具有空 URI 和 null Marshaller 的 Spring Web 服务请求

转载 作者:行者123 更新时间:2023-11-30 08:20:51 24 4
gpt4 key购买 nike

我已经使用 JABX 从 WSDL 生成域类并实现了以下客户端:

@Service
public class AccountEndpoint extends WebServiceGatewaySupport {

private static final Logger logger = Logger.getLogger(String.valueOf(AccountEndpoint.class));

public AccountEndpoint() {
}

public GetAccountResponse getAccount(long accountAgency, long accountNumber) {
GetAccountRequest request = new GetAccountRequest();
request.setAccountAgency(accountAgency);
request.setAccountNumber(accountNumber);

GetAccountResponse response = (GetAccountResponse)
getWebServiceTemplate().marshalSendAndReceive(request);

return response;
}
}

我是这样配置的:

@Configuration
@ComponentScan(basePackages = {"org.myco.mypro.core"})
public class WebServiceConfig {

@Bean
public Jaxb2Marshaller marshaller() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("org.myco.mypro.webservices");
return marshaller;
}

@Bean
public AccountEndpoint accountEndpoint(Jaxb2Marshaller marshaller) {
AccountEndpoint client = new AccountEndpoint();
client.setDefaultUri("http://localhost:11000/ws");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
}

和测试:

   @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = WebServiceConfig.class)
public class AccountEndpointTest extends TestCase {

@Autowired
private AccountEndpoint accountEndpoint;

public void setUp() throws Exception {
super.setUp();
}

@Test
public void testGetAccount() throws Exception {

accountEndpoint.setDefaultUri("http://localhost:11000/ws");
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("org.myco.mypro.webservices");
accountEndpoint.setMarshaller(marshaller);
accountEndpoint.setUnmarshaller(marshaller);

GetAccountResponse response = accountEndpoint.getAccount(12, 16);

assertNotNull(response);
}
}

如果我没有设置 URI,我会得到:java.lang.IllegalArgumentException: 'uri' must not be empty;

如果我没有设置编码器,我会得到:IllegalStateException:没有注册编码器。检查 WebServiceTemplate 的配置。

它就像 WebServiceConfig 中的配置不起作用,尽管 Autowiring 的 bean 不为空。

非常感谢任何帮助。谢谢。

最佳答案

您应该从 AccountEndpoint 中取出 @Service 注解。该 bean 在配置类中创建。

关于java - 具有空 URI 和 null Marshaller 的 Spring Web 服务请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25630395/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com