我需要更新客户&快速预订中的供应商,但我收到了错误。
//这里是我的代码
package com.company.product.wsai.qb.ws.endpoint;
import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import com.intuit.developer.SendRequestXML;
import com.intuit.developer.SendRequestXMLResponse;
import com.intuit.quickbooks.CurrencyAdd;
import com.intuit.quickbooks.CurrencyAddRqType;
import com.intuit.quickbooks.CustomerAdd;
import com.intuit.quickbooks.CustomerAddRqType;
import com.intuit.quickbooks.CustomerTypeAdd;
import com.intuit.quickbooks.CustomerTypeAddRqType;
import com.intuit.quickbooks.VendorAdd;
import com.intuit.quickbooks.QBXML;
import com.intuit.quickbooks.QBXMLMsgsRq;
import com.intuit.quickbooks.VendorAddRqType;
import com.company.product.wsai.qb.ws.conf.XmlConfig;
import com.company.product.wsai.qb.ws.util.XmlLogManager;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
@Endpoint
public class SendRequestXMLEndpoint {
// xml logging
private static final String SEND_REQUEST_XML = "sendRequestXML";
private static final String SEND_REQUEST_XML_RESPONSE = "sendRequestXMLResponse";
@Autowired
com.intuit.developer.ObjectFactory wsObjectFactory;
@Autowired
com.intuit.quickbooks.ObjectFactory qbObjectFactory;
@PayloadRoot(localPart = "sendRequestXML", namespace = XmlConfig.QB_WC_NAMESPACE)
@ResponsePayload
public SendRequestXMLResponse sendRequestXML(@RequestPayload SendRequestXML sendRequestXML) {
String sessionTicket = sendRequestXML.getTicket();
String strCompanyFileName = sendRequestXML.getStrCompanyFileName();
// log request
XmlLogManager.logSendRequestXMLEnpoint(sendRequestXML, SEND_REQUEST_XML, sessionTicket);
SendRequestXMLResponse sendRequestXMLResponse = wsObjectFactory.createSendRequestXMLResponse();
//SendRequestXMLResponse sendRequestXMLResponseforCurrency = wsObjectFactory.createSendRequestXMLResponse();
sendRequestXMLResponse.setSendRequestXMLResult(getCustomer());
// log response
XmlLogManager.logSendRequestXMLEnpoint(sendRequestXMLResponse, SEND_REQUEST_XML_RESPONSE, sessionTicket);
return sendRequestXMLResponse;
}
@PayloadRoot(localPart = "sendRequestXML", namespace = XmlConfig.QB_WC_NAMESPACE)
@ResponsePayload
public SendRequestXMLResponse sendRequestXMLforVendor(@RequestPayload SendRequestXML sendRequestXML) {
String sessionTicket = sendRequestXML.getTicket();
String strCompanyFileName = sendRequestXML.getStrCompanyFileName();
// log request
XmlLogManager.logSendRequestXMLEnpoint(sendRequestXML, SEND_REQUEST_XML, sessionTicket);
SendRequestXMLResponse sendRequestXMLResponseforVendor = wsObjectFactory.createSendRequestXMLResponse();
sendRequestXMLResponseforVendor.setSendRequestXMLResult(getVendor());
// log response
XmlLogManager.logSendRequestXMLEnpoint(sendRequestXMLResponseforVendor, SEND_REQUEST_XML_RESPONSE, sessionTicket);
return sendRequestXMLResponseforVendor;
}
private String getCustomer() {
StringWriter stringWriter = new StringWriter();
stringWriter.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
stringWriter.append("<?qbxml version=\"13.0\"?>");
try {
CustomerAdd customerAdd = qbObjectFactory.createCustomerAdd();
customerAdd.setName("ZZhhaarraa");
customerAdd.setFirstName("Zhara");
customerAdd.setLastName("User");
CustomerAddRqType customerAddRqType = qbObjectFactory.createCustomerAddRqType();
customerAddRqType.setCustomerAdd(customerAdd);
customerAddRqType.setRequestID("1");
QBXMLMsgsRq qbxmlMsgsRq = qbObjectFactory.createQBXMLMsgsRq();
qbxmlMsgsRq.setOnError("stopOnError");
qbxmlMsgsRq.getHostQueryRqOrCompanyQueryRqOrAccountAddRq().add(customerAddRqType);
QBXML qbxml = qbObjectFactory.createQBXML();
qbxml.setQBXMLMsgsRq(qbxmlMsgsRq);
JAXBContext jaxbContext = JAXBContext.newInstance(QBXML.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marshaller.marshal(qbxml, stringWriter);
} catch (JAXBException e) {
e.printStackTrace();
}
return stringWriter.toString();
}
private String getVendor() {
StringWriter stringWriter = new StringWriter();
stringWriter.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
stringWriter.append("<?qbxml version=\"13.0\"?>");
try {
VendorAdd vendorAdd = qbObjectFactory.createVendorAdd();
vendorAdd.setName("TEST4");
vendorAdd.setCompanyName("ABC45 PVT LTD");
vendorAdd.setEmail("yasa67@jkcsworld.com");
vendorAdd.setNotes("Test Description2");
vendorAdd.setFirstName("Miketr");
vendorAdd.setLastName("Da");
VendorAddRqType vendorAddRqType = qbObjectFactory.createVendorAddRqType();
vendorAddRqType.setVendorAdd(vendorAdd);
vendorAddRqType.setRequestID("2");
QBXMLMsgsRq qbxmlMsgsRq = qbObjectFactory.createQBXMLMsgsRq();
qbxmlMsgsRq.setOnError("stopOnError");
qbxmlMsgsRq.getHostQueryRqOrCompanyQueryRqOrCompanyActivityQueryRq().add(vendorAddRqType);
QBXML qbxml = qbObjectFactory.createQBXML();
qbxml.setQBXMLMsgsRq(qbxmlMsgsRq);
JAXBContext jaxbContext = JAXBContext.newInstance(QBXML.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marshaller.marshal(qbxml, stringWriter);
} catch (JAXBException e) {
e.printStackTrace();
}
return stringWriter.toString();
}
}
//这是我错误的堆栈跟踪
版本: 不是由服务提供
消息: 身份验证失败
描述: QBWC1012:由于以下错误消息,身份验证失败。 客户发现响应内容类型为“text / html; charset = utf-8”,但预期为“text / xml”。
Apache Tomcat / 7.0.47 - 错误报告
类型异常报告
消息 Servlet ws的Servlet.init()抛出异常
描述服务器遇到一个内部错误,阻止了它履行此请求。
异常
javax.servlet.ServletException: Servlet.init() for servlet ws threw exception org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) java.lang.Thread.run(Unknown Source)
根本原因
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping#0': Initialization of bean failed; nested exception is org.springframework.context.ApplicationContextException: Cannot map endpoint [public com.intuit.developer.SendRequestXMLResponse com.company.product.wsai.qb.ws.endpoint.SendRequestXMLEndpoint.sendRequestXMLforVendor(com.intuit.developer.SendRequestXML)] on registration key [{http://developer.intuit.com/}sendRequestXML]: there's already endpoint [public com.intuit.developer.SendRequestXMLResponse com.company.product.wsai.qb.ws.endpoint.SendRequestXMLEndpoint.sendRequestXML(com.intuit.developer.SendRequestXML)] mapped org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703) org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) javax.servlet.GenericServlet.init(GenericServlet.java:160) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) java.lang.Thread.run(Unknown Source)
根本原因
org.springframework.context.ApplicationContextException: Cannot map endpoint [public com.intuit.developer.SendRequestXMLResponse com.company.product.wsai.qb.ws.endpoint.SendRequestXMLEndpoint.sendRequestXMLforVendor(com.intuit.developer.SendRequestXML)] on registration key [{http://developer.intuit.com/}sendRequestXML]: there's already endpoint [public com.intuit.developer.SendRequestXMLResponse com.company.product.wsai.qb.ws.endpoint.SendRequestXMLEndpoint.sendRequestXML(com.intuit.developer.SendRequestXML)] mapped org.springframework.ws.server.endpoint.mapping.AbstractMethodEndpointMapping.registerEndpoint(AbstractMethodEndpointMapping.java:97) org.springframework.ws.server.endpoint.mapping.AbstractMethodEndpointMapping.registerMethods(AbstractMethodEndpointMapping.java:150) org.springframework.ws.server.endpoint.mapping.AbstractAnnotationMethodEndpointMapping.initApplicationContext(AbstractAnnotationMethodEndpointMapping.java:72) org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:120) org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:74) org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:119) org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:94) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:407) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1545) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703) org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) javax.servlet.GenericServlet.init(GenericServlet.java:160) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) java.lang.Thread.run(Unknown Source)
注意 Apache Tomcat / 7.0.47日志中提供了根本原因的完整堆栈跟踪。
答案 0 :(得分:0)
在我看来,您正在映射相同的端点两次:
已有端点[public com.intuit.developer.SendRequestXMLResponse com.company.product.wsai.qb.ws.endpoint.SendRequestXMLEndpoint.sendRequestXML(com.intuit.developer.SendRequestXML)] mapped
来到这里:
@PayloadRoot(localPart = "sendRequestXML", namespace = XmlConfig.QB_WC_NAMESPACE)
@ResponsePayload
public SendRequestXMLResponse sendRequestXML(@RequestPayload SendRequestXML sendRequestXML) {
一旦到了:
@PayloadRoot(localPart = "sendRequestXML", namespace = XmlConfig.QB_WC_NAMESPACE)
@ResponsePayload
public SendRequestXMLResponse sendRequestXMLforVendor(@RequestPayload SendRequestXML sendRequestXML) {
将SOAP端点映射两次真的没有意义。任何SOAP客户端如何确定哪个端点是正确的端点?
您应该有一个端点。然后,一个端点可以调用其他方法来生成CustomerAdd
请求或VendorAdd
请求(或者如果您愿意,可以将它们两者捆绑到一个qbXML文档中)。