Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong CDI-SE context is requested using jersey-media-jaxb versions 3.1.2 and higher running in a weld/grizzly container #5539

Open
jsikkes opened this issue Feb 19, 2024 · 2 comments

Comments

@jsikkes
Copy link

jsikkes commented Feb 19, 2024

When using jersey 3.1.5 in combination with JAXB in a Weld Grizzly container it fails to parse application/xml content because it tries to create a SAX parser within a Threadscoped CDI context that does not exist.

org.jboss.weld.contexts.ContextNotActiveException: WELD-001303: No active contexts for scope type org.jboss.weld.environment.se.contexts.ThreadScoped
org.jboss.weld.environment.se.contexts.ThreadScoped\n\tat org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:628)\n\tat org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:89)\n\tat org.jboss.weld.bean.ContextualInstance.getIfExists(ContextualInstance.java:63)\n\tat org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:87)\n\tat org.jboss.weld.bean.proxy.ProxyMethodHandler.getInstance(ProxyMethodHandler.java:131)\n\tat org.jboss.weld.generated.proxiesx.xml.parsers.SAXParserFactory$Proxy$_$$_WeldClientProxy.newSAXParser(Unknown Source)\n\tat org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getSAXSource(AbstractJaxbProvider.java:304)\n\t... 72 common frames omitted\n",

Which makes some sense as only ApplicationScoped; RequestScoped or Dependent contexts are active (by default).

Unfortunately I am not able to pinpoint the exact location for the cause of this issue.

  • Downgrading jersey-media-jaxb to 3.1.1 currently solves it for now.

Relevant project dependencies:

Jersey 3.1.5:

  • jersey-client
  • jersey-proxy-client
  • jersey-cdi2-se
  • jersey-media-jaxb *
  • jersey-apache-connector
  • jersey-server
  • jersey-container-grizzly2-http

Grizzly 4.0.2

  • grizzly-http-server
  • grizzly-http2
  • grizzly-npn-bootstrap

Jaxb 3.0.2:

  • jaxb-core
  • jaxb-xjc
  • jaxb-runtime

Weld 5.1.2-Final:

  • weld-se-core
@jansupol
Copy link
Contributor

AbstractJaxbProvider has a bit different constructor. Do you happen to extend from it?
Can you provide some reproducer?

@jsikkes
Copy link
Author

jsikkes commented Feb 19, 2024

I'm not extending any code provided by the libraries. The Jersey Jaxb media feature is used as-is (autoloaded) and the CDI managed Jersey client is produced using the following code:

Client producer

public class WebApiClientProducer {

    @ConfigProperty(name = "xxxx.url")
    @Inject
    private String webApiUrl;

    @ConfigProperty(name = "yyyy.user")
    @Inject
    private String webApiUsername;

    @ConfigProperty(name = "zzzz.password")
    @Inject
    private String webApiPassword;

    @Produces
    @ApplicationScoped
    public WebApiClient produceWebApiClient(HttpClientConnectionManager connectionManager) {
       ClientConfig config = new ClientConfig();
       config.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);
       config.register(HttpAuthenticationFeature.basic(username, password));
       config.connectorProvider(new ApacheConnectorProvider());
       Client client = JerseyClientBuilder.newClient(config);
       WebTarget target = client.target(url);
       return WebResourceFactory.newResource(WebApiClient.class, target);
    }
}

WebResourceFactory proxy interface:

public interface WebApiClient {

    @GET
    @Path("api/Master/{name}")
    @Produces(MediaType.APPLICATION_XML)
    Envelope getMaster(@PathParam("name") String name);


	/* ... */
	
}

Jaxb annotated response class

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "header",
    "body"
})
@XmlRootElement(name = "envelope")
public class Envelope {

    @XmlElement(required = true)
    protected Header header;
    @XmlElement(required = true)
    protected Envelope.Body body;

	/* ... */

}

I'll try to build & publish some reproduction code tomorrow during office hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants