0

I have following code and my message is in xml formatted and it is huge data. I am not getting my message in and . Xml angle brackets are now transformed. I would like to have angle brackets rather than ampersand lt semicolon.

<createOrderRequestType xmlns:ns2="http://xmlns.oracle.com/communications/ordermanagement">
    <msg>&lt;head&gt;&lt;/head&gt;
&lt;/body&gt;
</msg>
</createOrderRequestType>

<msg>
<head> </head>
<body> </body>
</msg>

public CreateOrderResponseType createAncillariesBySoloOrderId(String soloOrderId) {
        String message = findOrderBySoloOrderId(soloOrderId);

        final Pattern pattern = Pattern.compile("<msg xmlns=\"\">(.+?)</msg>", Pattern.DOTALL);
        final Matcher matcher = pattern.matcher(message);
        matcher.find(); 
        String msgStr =  matcher.group(1) ;
        log.info("message = " + msgStr );
CreateOrderRequestType createOrderRequestType = new CreateOrderRequestType() ;      
        Document doc;
        try {
            doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
            Element msg = doc.createElement("msg");
            msg.setTextContent(msgStr);
            doc.appendChild(msg);
            createOrderRequestType.getAny().add((Element) doc.getFirstChild());

            StringWriter sw1 = new StringWriter();
            JAXB.marshal(createOrderRequestType, sw1);
            String xmlString = sw1.toString();
            log.info("xmlString = " + xmlString); 

        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }       
 return getOSMService(osmServiceUrl).createOrder(createOrderRequestType);
}   



public class CreateOrderRequestType {

    @XmlAnyElement(lax = true)
    protected List<Object> any;

public List<Object> getAny() {
        if (any == null) {
            any = new ArrayList<Object>();
        }
        return this.any;
    }

}

1 Answers1

0

It depends of XSD

But, i think it will be:

...
@XmlRootElement(name = "CreateOrderRequestType") // or probably (name = "CreateOrderRequest")
public class CreateOrderRequestType {
...

and for response too

...
@XmlRootElement(name = "CreateOrderResponseType") // or probably (name = "CreateOrderResponse")
public class CreateOrderResponseType{
...
  • CreateOrderRequestType and CreateOrderResponseType both are generated from WSDL. I don't think I can change them. – Bandita Pradhan Feb 19 '20 at 19:17
  • @BanditaPradhan Change it. I allow :) – Alexander Prisadkov Feb 19 '20 at 19:27
  • @BanditaPradhan It is simplest way. For different solution you can read https://stackoverflow.com/questions/819720/no-xmlrootelement-generated-by-jaxb – Alexander Prisadkov Feb 19 '20 at 19:33
  • I added @XmlRootElement in CreateOrderRequestType and CreateOrderResponseType and I am still getting the same error. I looked at the solutions from google search but my code didn't work. – Bandita Pradhan Feb 19 '20 at 20:24
  • @BanditaPradhan do you try CreateOrderRequest in quotes? And is it type really root? – Alexander Prisadkov Feb 19 '20 at 20:30
  • i used in both class . @XmlRootElement(name = "CreateOrderResponseType") public class CreateOrderResponseType {@XmlRootElement(name = "CreateOrderRequestType") public class CreateOrderRequestType { I don't have CreateOrderRequest class – Bandita Pradhan Feb 19 '20 at 20:35
  • @BanditaPradhan try this: @XmlRootElement(name = "CreateOrderResponse") public class CreateOrderResponseType{ ... @XmlRootElement(name = "CreateOrderRequest") public class CreateOrderRequestType { – Alexander Prisadkov Feb 20 '20 at 05:33
  • I tried but it added extra namespace after the message line. Yesterday, I changed my code and remove the XMLRootElement issue . But, I have probably one last issue. I am updating the question. I am not sure how to fix the issue. – Bandita Pradhan Feb 20 '20 at 17:41