Mule error: more than one JAXBContext

We are facing one issue in our Mule adapter related to JAXB context, need to view the same We use xpath to evaluate some expressions in select boxes in our adapter like below,

<choice doc:name="Choice">
<when expression="//env:abc/env:Body/ref:dataelement/ref:/ref:element" evaluator="xpath">
        ......
</when>

      

Now this works great in our application, but the problem occurs when one of the other commands uses this adapter as a jar in their application.

When they try to use this adapter, they get below error,

Message : More than one object of type class javax.xml.bind.JAXBContext registered but only one expected. 
Type : org.mule.api.registry.RegistrationException 
Code : MULE_ERROR--2 
JavaDoc : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/registry /RegistrationException.html.

      

After debugging with loggers etc. we've narrowed it down to the select box used above, which is causing this particular problem. Also, googled a bit and found one of the posts pointing to the same problem.

Also, to confirm that we commented out the select block with the xpath expression and the stream went ahead but broke again where the xpath was used in some other way.

https://www.mulesoft.org/jira/browse/MULE-5926

Can anyone suggest any suitable ways to solve this problem?

+3


source to share


3 answers


I agree with you. This is an unresolved issue in Mule.

One of the solutions we have implemented does not define the jaxb context in the config you provide in the jar file.

Along with the jar file, provide instructions for the target application, using it to include JAXB packages in your JAXB context object definition.



This way there will only be one JAXB context and it will run smoothly.

Hope it helps.

+1


source


It's a little late, but the solution that worked was

<mulexml:jaxb-context name="JAXB_Context" packageNames="org.example.test1:org.example.test2" doc:name="JAXB Context1" />

      



Please note that there should be no spaces between package names.

Thanks to: http://dominikbial.de/quicktipp-working-with-more-than-one-package-name-in-a-jaxb-context-config-in-mule-esb/

0


source


Currently, we cannot add more than one JAXBContext to a mule. Alternatively, you can write your own transformer.

I have implemented something like

public interface MyAppJaxbObj2XmlComponent<I,O> extends 
MyAppComponent<I,O>,Callable {  
  public O marshal(I input) throws Exception;
}

      

Transformer Abstart

public abstract class AbstractMyAppJaxbObj2XmlComponent<I,O> implements 
 MyAppJaxbObj2XmlComponent<I,O>{
  private Class<I> inputType;   
    public AbstractMyAppJaxbObj2XmlComponent(){
    this.inputType = (Class<I>) new TypeToken<I>(getClass()) 
 {}.getRawType();
 }

 public AbstractMyAppJaxbObj2XmlComponent(Class<I> type){
    this.inputType = type;
 }

@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
    I input = eventContext.getMessage().getPayload(inputType);
    O output = marshal(input);
    return output;
 }
}

      

Your flow transformer will load your required jaxb at startup time.

@Component
public class MyFlowJaxbObj2XmlComponent extends 
AbstractMyAppJaxbObj2XmlComponent<RequestPayloadType,String> {
@PostConstruct
 public void init() {
  //Load your schema during startup
 }
}

      

Alternatively, you can also use a liquid interface for this.

0


source







All Articles