Java 使用Spring将数据推送到Soap Web服务
嗨,我在使用SOAP Web服务时提到了这个。 但我不确定如何调用客户机方法 请在下面找到我的代码: ClientConfig.javaJava 使用Spring将数据推送到Soap Web服务,java,spring,web-services,spring-mvc,soap,Java,Spring,Web Services,Spring Mvc,Soap,嗨,我在使用SOAP Web服务时提到了这个。 但我不确定如何调用客户机方法 请在下面找到我的代码: ClientConfig.java package com.exclusively.unicommerce.service; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframe
package com.exclusively.unicommerce.service;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
@Configuration
public class ClientConfig {
@Bean
public Jaxb2Marshaller marshaller()
{
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("com.unicommerce.wsdl");
return marshaller;
}
@Bean
public SaleOrderClient saleorderclient(Jaxb2Marshaller marshaller) {
SaleOrderClient client = new SaleOrderClient();
client.setDefaultUri("https://link.com/services/soap/?version=1.6");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
}
SaleOrderClient.java
public class SaleOrderClient extends WebServiceGatewaySupport{
private static final String uri = "https://link.com/services/soap/?version=1.6";
public String createSaleOrder(Suborder suborder)
{
SaleOrder saleorder = new SaleOrder();
saleorder = setSaleOrderObject(suborder);
CreateSaleOrderRequest request = new CreateSaleOrderRequest();
request.setSaleOrder(saleorder);
//PLEASE NOTE THIS Line of CODE.
this.getWebServiceTemplate().marshalSendAndReceive(uri,request);
return "Pushed to Unicommerce";
}
public SaleOrder setSaleOrderObject(Suborder suborder)
{
SaleOrder saleorder = new SaleOrder();
saleorder.setAdditionalInfo(null);
saleorder.setAddresses(null);
saleorder.setCashOnDelivery(null);
saleorder.setCFormProvided(null);
saleorder.setChannel(null);
saleorder.setCode(null);
saleorder.setCurrencyCode(null);
saleorder.setCustomerCode(null);
saleorder.setDisplayOrderCode(null);
saleorder.setNotificationEmail(null);
saleorder.setNotificationMobile(null);
saleorder.setVerificationRequired(null);
return saleorder;
}
}
SuborderController.java
@Controller
public class SuborderController {
private String currentStatus, finalStatus,status,response;
@Autowired
private SuborderService suborderservice;
@RequestMapping(value = "/orders/add", method = RequestMethod.POST)
@ResponseBody
public String addOrders(@RequestBody Suborder order) {
if(order.getSuborderId() == null || order.getSuborderId().isEmpty())
return "BAD REQUEST";
suborderservice.addOrders(order);
//**CALL To createSaleorder(order)**
//response = saleorderclient.createSaleorder(order);
return response;
}
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ClientConfig.class);
ctx.refresh();
SaleOrderClient saleorderclient = ctx.getBean(SaleOrderClient.class);
这里需要注意的是,webservice提供了请求类,但没有响应类。第二次我试了
@Autowired
SaleOrderClient saleorderclient;
但它抛出了bean not found异常
我无法理解如何访问此方法。
请帮忙。TIA。我通过在SuborderController.java中添加以下提到的行来解决我的问题
@Controller
public class SuborderController {
private String currentStatus, finalStatus,status,response;
@Autowired
private SuborderService suborderservice;
@RequestMapping(value = "/orders/add", method = RequestMethod.POST)
@ResponseBody
public String addOrders(@RequestBody Suborder order) {
if(order.getSuborderId() == null || order.getSuborderId().isEmpty())
return "BAD REQUEST";
suborderservice.addOrders(order);
//**CALL To createSaleorder(order)**
//response = saleorderclient.createSaleorder(order);
return response;
}
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ClientConfig.class);
ctx.refresh();
SaleOrderClient saleorderclient = ctx.getBean(SaleOrderClient.class);
如果未找到bean,则不会读取配置。另外,您的类是
SaleOrderClient
而不是SaleOrderClient
…我需要做哪些更改?请确保使用了@Configuration
类。剩下的我不知道,因为你的帖子中没有这些信息。我如何确保使用我的配置类?你还需要什么样的信息?如果你必须问这个问题,你可能想先阅读参考指南(关于事物如何运作的第3节)。将其作为bean添加到其他配置中,或者确保组件扫描正在扫描配置类所在的包。