【问题标题】:How to access @PersistenceUnit private EntityManagerFactory emf in soaphandler如何在soaphandler中访问@PersistenceUnit私有EntityManagerFactory emf
【发布时间】:2011-05-13 08:37:48
【问题描述】:

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

我得到了如下的soapHeader

@覆盖 公共布尔句柄消息(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 在 DB 中保存soapheader,我需要在soaphandler 类中使用 entitymanagerfactory。我尝试使用@persistenceunit,但它给出的错误是我的soaphandler 类在Web 应用程序中找不到。

问候, 伊姆兰

【问题讨论】:

  • 您的问题信息不足

标签: java jpa soap


【解决方案1】:

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

处理程序:

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");

【讨论】:

    【解决方案2】:

    在处理程序中进行数据库操作不是一个好主意,我只是解析soapheader并让它进入webservice并在其中执行数据库任务。

    问候, 伊姆兰

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-19
      • 2013-01-26
      • 1970-01-01
      • 1970-01-01
      • 2011-05-21
      • 1970-01-01
      • 2012-04-29
      相关资源
      最近更新 更多