开发者

How to access @PersistenceUnit private EntityManagerFactory emf in soaphandler

I have implemented SOAPHandler, now in my handleMessage method i want to save SoapHeader into oracle database.

I got soapHeader like following

@Override public boolean handleMessage(SOAPMessageContext context) {

    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();
            SOAPEn开发者_开发问答velope    soapEnvelope    =   soapPart.getEnvelope();
            SOAPHeader      soapHeader      =   soapEnvelope.getHeader();

            SOAPBody        soapBody        =   soapEnvelope.getBody();

}

To save soapheader in DB using JPA i required entitymanagerfactory in soaphandler class. i try with @persistenceunit but it gives error that my soaphandler class not found in web application.

Regards, imran


You can store XML message in context, and then load it and save into DB in WebService:

Handler:

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

WebService:

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


Its not a good idea to do DataBase manipulation in handler, i just parse soapheader and let it go to webservice and did database tasks in it.

Regards, imran

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜