gpt4 book ai didi

java - 如何在soaphandler中访问@PersistenceUnit私有(private)EntityManagerFactory emf

转载 作者:行者123 更新时间:2023-12-01 15:51:14 25 4
gpt4 key购买 nike

我已经实现了 SOAPHandler,现在在我的 handleMessage 方法中我想将 SoapHeader 保存到 oracle 数据库中。

我得到了如下的soapHeader

@覆盖 公共(public) boolean handleMessage(SOAPMessageContext上下文){

    Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

if (outboundProperty.booleanValue()) {

System.out.println("\nOutbound message:");

} else {

System.out.println("\nInbound message:");

try {
SOAPMessage soapMessage = context.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPHeader soapHeader = soapEnvelope.getHeader();

SOAPBody soapBody = soapEnvelope.getBody();

}

要使用JPA将soapheader保存在数据库中,我需要soaphandler类中的entitymanagerfactory。我尝试使用@persistenceunit,但它给出了错误:在网络应用程序中找不到我的soaphandler类。

问候,伊姆兰

最佳答案

您可以将 XML 消息存储在上下文中,然后将其加载并保存到 WebService 中的数据库中:

处理程序:

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
context.getMessage().writeTo(outputStream);
context.put("XML_MESSAGE_PARAM", outputStream.toString());
context.setScope("XML_MESSAGE_PARAM", Scope.APPLICATION);

网络服务:

@Resource
WebServiceContext webContext;
String xmlMessage = (String) webContext.getMessageContext().get("XML_MESSAGE_PARAM");

关于java - 如何在soaphandler中访问@PersistenceUnit私有(private)EntityManagerFactory emf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5989331/

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