Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal character entity: expansion character (code 0xe

I am using CXF to connect the SOAP web service. Some times while requesting the server i am getting Illegal character entity: expansion character code 0xe exception.

I found that due to illegal character in Xml this exception occurs. Also i found the solution for this

  XMLOutputFactory f = new WstxOutputFactory();
  f.setProperty(WstxOutputProperties.P_OUTPUT_INVALID_CHAR_HANDLER,
    new InvalidCharHandler.ReplacingHandler(' '));
  XMLStreamWriter sw = f.createXMLStreamWriter(...);

But i dont know how to apply this in CXF. Can someone tell me where i have to use this code in CXF.Thanks in advice.

like image 487
SANN3 Avatar asked Oct 30 '13 10:10

SANN3


1 Answers

You could use an incoming interceptor on the server or and outgoing on the client and clean the xml before the unmarshalling occurs.

Incoming Phases

------------------------------------------------------------------------------
|Phase                    | Functions                                        |
------------------------------------------------------------------------------
|RECEIVE                  | Transport level processing                       |
|(PRE/USER/POST)_STREAM   | Stream level processing/transformations          |
|READ |                   | This is where header reading typically occurs    |
|(PRE/USER/POST)_PROTOCOL | Protocol processing, such as JAX-WS SOAP handlers|
|UNMARSHAL                | Unmarshalling of the request                     |
|(PRE/USER/POST)_LOGICAL  | Processing of the umarshalled request            |
|PRE_INVOKE               | Pre invocation actions                           |
|INVOKE                   | Invocation of the service                        |
|POST_INVOKE              | Invocation of the outgoing chain if there is one |
------------------------------------------------------------------------------

Outgoing Phases

---------------------------------------------------------------------------------------
|Phase                    | Functions                                                 |
---------------------------------------------------------------------------------------
|SETUP                    | Any set up for the following phases                       |
|(PRE/USER/POST)_LOGICAL  | Processing of objects about to marshalled                 |
|PREPARE_SEND             | Opening of the connection                                 |
|PRE_STREAM               |                                                           |
|PRE_PROTOCOL             | Misc protocol actions                                     |
|WRITE                    | Writing of the protocol message, such as the SOAP Envelope|
|MARSHAL                  | Marshalling of the objects                                |
|(USER/POST)_PROTOCOL     | Processing of the protocol message                        |
|(USER/POST)_STREAM       | Processing of the byte level message                      |
|SEND                     |                                                           |
---------------------------------------------------------------------------------------

Keep in mind that you will have to do it before unmarshaling (incoming) or after marshalling (outgoing).

Here you can find all the details, plus the necessary examples for using inteceptors.

Update

After some more research I've found these:

  1. Solution with spring
  2. Solution without spring

Copy and paste from the second link (the first is SO answer)

package tmp;

public class MyWstxOutputFatory extends WstxOutputFactory {
    public MyWstxOutputFatory() {
        setProperty(com.ctc.wstx.api.WstxOutputProperties.P_OUTPUT_INVALID_CHAR_HANDLER,
                    new
com.ctc.wstx.api.InvalidCharHandler.ReplacingHandler(' '));
    }
}

and use it in your jaxws configuration

   <bean id="outStaxFactory" class="tmp.MyWstxOutputFatory"/>

   <!-- jaxws:client or server -->
       ...
       <jaxws:properties>
           <entry key="javax.xml.stream.XMLOutputFactory">
               <ref bean="outStaxFactory"/>
           </entry>
       </jaxws:properties>
       ...
like image 141
Alkis Kalogeris Avatar answered Oct 12 '22 20:10

Alkis Kalogeris