Page 1 of 1

model.fields.merge.MailMerger not working in jboss AS7

PostPosted: Tue Aug 05, 2014 3:40 am
by Ruwen
Hello,

after some research I could run the 'HelloMavenCentral' example in my jboss 7.1.1 Final (as normal Java Application it was straight foreward).

However, I was not able to get the MailMerger running. Seems like there is a problem with the JAXBContext. I played around with different setups recommanded on stackoverflow an also tried the moxy implementation (which gives some different error output, but complaining about the totally same lines of code).

Here is my stacktrace, if you need further implementations details please let me know.

Code: Select all
18:28:14,762 INFO  [org.docx4j.model.fields.merge.MailMerger] (http--0.0.0.0-8080-1) Found 4 fields
18:28:14,801 ERROR [org.docx4j.model.fields.FieldRef] (http--0.0.0.0-8080-1) TODO: extract field name from org.docx4j.model.fields.FieldRef
18:28:14,810 ERROR [stderr] (http--0.0.0.0-8080-1) java.lang.RuntimeException: javax.xml.bind.JAXBException: class org.docx4j.model.fields.FieldRef nor any of its super class is known to this context.

18:28:14,812 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.docx4j.XmlUtils.marshaltoString(XmlUtils.java:575)

18:28:14,813 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.docx4j.XmlUtils.marshaltoString(XmlUtils.java:507)

18:28:14,814 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.docx4j.model.fields.FieldRef.getFldName(FieldRef.java:304)

18:28:14,814 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.docx4j.model.fields.FieldsPreprocessor.preserveResult(FieldsPreprocessor.java:235)

18:28:14,815 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.docx4j.model.fields.FieldsPreprocessor.handleRun(FieldsPreprocessor.java:485)

18:28:14,816 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.docx4j.model.fields.FieldsPreprocessor.handleContent(FieldsPreprocessor.java:180)

18:28:14,817 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.docx4j.model.fields.FieldsPreprocessor.canonicaliseInstance(FieldsPreprocessor.java:142)

18:28:14,818 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.docx4j.model.fields.FieldsPreprocessor.canonicalise(FieldsPreprocessor.java:128)

18:28:14,819 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.docx4j.model.fields.merge.MailMerger.performOnInstance(MailMerger.java:479)

18:28:14,821 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.docx4j.model.fields.merge.MailMerger.performMerge(MailMerger.java:388)

18:28:14,822 ERROR [stderr] (http--0.0.0.0-8080-1)    at com.ruwen.docx.FieldsMailMerge.saveDoc(FieldsMailMerge.java:90)

18:28:14,823 ERROR [stderr] (http--0.0.0.0-8080-1)    at com.ruwen.rest.DocRestService.getWordDoc(DocRestService.java:57)

18:28:14,823 ERROR [stderr] (http--0.0.0.0-8080-1)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

18:28:14,824 ERROR [stderr] (http--0.0.0.0-8080-1)    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

18:28:14,825 ERROR [stderr] (http--0.0.0.0-8080-1)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

18:28:14,826 ERROR [stderr] (http--0.0.0.0-8080-1)    at java.lang.reflect.Method.invoke(Unknown Source)

18:28:14,826 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:155)

18:28:14,827 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257)

18:28:14,828 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222)

18:28:14,829 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211)

18:28:14,829 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525)

18:28:14,830 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502)

18:28:14,830 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)

18:28:14,831 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)

18:28:14,831 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)

18:28:14,832 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)

18:28:14,833 ERROR [stderr] (http--0.0.0.0-8080-1)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

18:28:14,833 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)

18:28:14,834 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)

18:28:14,835 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)

18:28:14,835 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)

18:28:14,836 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)

18:28:14,836 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)

18:28:14,837 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

18:28:14,837 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

18:28:14,838 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)

18:28:14,839 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)

18:28:14,839 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)

18:28:14,840 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)

18:28:14,841 ERROR [stderr] (http--0.0.0.0-8080-1)    at java.lang.Thread.run(Unknown Source)

18:28:14,841 ERROR [stderr] (http--0.0.0.0-8080-1) Caused by: javax.xml.bind.JAXBException: class org.docx4j.model.fields.FieldRef nor any of its super class is known to this context.

18:28:14,842 ERROR [stderr] (http--0.0.0.0-8080-1)    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:588)

18:28:14,842 ERROR [stderr] (http--0.0.0.0-8080-1)    at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:486)

18:28:14,843 ERROR [stderr] (http--0.0.0.0-8080-1)    at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:323)

18:28:14,843 ERROR [stderr] (http--0.0.0.0-8080-1)    at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:251)

18:28:14,844 ERROR [stderr] (http--0.0.0.0-8080-1)    at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:95)

18:28:14,845 ERROR [stderr] (http--0.0.0.0-8080-1)    at org.docx4j.XmlUtils.marshaltoString(XmlUtils.java:563)

18:28:14,845 ERROR [stderr] (http--0.0.0.0-8080-1)    ... 39 more


This is the relevant line of code where all the trouble begins (taken from the examples, and working outside of jboss)

Code: Select all
org.docx4j.model.fields.merge.MailMerger.performMerge(wordMLPackage, thismap, true);


For the full consol please check http://pastebin.com/pmp8iupi

Thank you very much in advance for any hint how to solve this problem.

Ruwen

Re: model.fields.merge.MailMerger not working in jboss AS7

PostPosted: Tue Aug 05, 2014 4:24 pm
by jason
Could you please attach a sample docx which causes the issue?

Also, try using http://www.docx4java.org/docx4j/docx4j- ... 140805.jar
and posting the log output? This nightly should shed some light on the issue.

Re: model.fields.merge.MailMerger not working in jboss AS7

PostPosted: Tue Aug 05, 2014 10:18 pm
by Ruwen
Shame on me. I played around with the template file and then forgot about it. It contained fields/conditions that are not supported by docx4j, so it couldn't work. Fixing the template fixed the whole problem.

I post an example just in case someone wants to produce a docx file via template an make it accessible via REST.

Loading the template and replace mergefields.
Code: Select all
public class FieldsMailMerge {
      public ByteArrayOutputStream createDoc() throws Exception {
      
      WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(
         new java.io.File(System.getProperty("user.dir") + "/template.docx")
      );
      
      Map<DataFieldName, String> map = new HashMap<DataFieldName, String>();
      map.put( new DataFieldName("Vorname"), "Jon");
      map.put( new DataFieldName("Name"), "Doe");
      map.put(new DataFieldName("Nummer"), "2");
       
        org.docx4j.model.fields.merge.MailMerger.performMerge(wordMLPackage, map, true);
   
        OpcPackage pkg = wordMLPackage.getPackage();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Save save = new Save(pkg);
        save.save(baos);

        return baos;

   }
}


Creating the relevant REST resource
Code: Select all
   
    @GET
    @Path("docCopy")
    @Produces({"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})
    public Response getWordDocCopy() {
       FieldsMailMerge fmm = new FieldsMailMerge(); 
       ByteArrayOutputStream out = new ByteArrayOutputStream();
       
       try {
          out = fmm.createDoc();
       }
       catch(Exception e) {
          e.printStackTrace();
       }
              
       return Response.ok(out.toByteArray()).build();
    }


Thanks for the help and your great work in general!

Ruwen