[JERSEY-3158] Need com.sun.jersey.server.impl.cdi package to be exported and imported for glassfish Created: 23/Aug/16  Updated: 25/Aug/16  Resolved: 24/Aug/16

Status: Resolved
Project: jersey
Component/s: osgi
Affects Version/s: 1.11
Fix Version/s: 1.19.2

Type: Bug Priority: Blocker
Reporter: kdevaras Assignee: Pavel Bucek
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Due to an upgrade in weld we are seeing a NoClassDefFoundError for Jersey classes in GlassFish 3.1.2.15.

From my analysis, com.sun.jersey.server.impl.cdi package needs to be added to jersey-gf-servlet.jar(for export) and to jersey-gf-server.jar(for import).

So, could you please provide us with the modified jars.

Appreciate your quick response as 3.1.2.15 has already been released and this has become an urgent issue.

We are currently using Jersey 1.11.3 version.



 Comments   
Comment by kdevaras [ 23/Aug/16 ]

I've checked the code for 1.x Jersey. I can see where the export and import tags need to be added in pom.xml for glassfish.

But there's glassfish/v3-packages and glassfish/v3.2-packages under jersey-1.x-master. I'm not sure which pom to pick.

Comment by kdevaras [ 25/Aug/16 ]

We are seeing a new issue with the new jersey jars:

[#|2016-08-25T10:36:27.559+0530|WARNING|oracle-glassfish3.1.2|ServiceLoader|_ThreadID=68;_ThreadName=admin-thread-pool-4848(1);|Could not instantiate service class com.sun.jersey.server.impl.cdi.CDIExtension
java.lang.NoClassDefFoundError: javax/ws/rs/core/Context
	at java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2413)
	at java.lang.Class.getConstructor0(Class.java:2723)
	at java.lang.Class.getDeclaredConstructor(Class.java:2004)
	at org.jboss.weld.util.ServiceLoader.prepareInstance(ServiceLoader.java:233)
	at org.jboss.weld.util.ServiceLoader.loadService(ServiceLoader.java:209)
	at org.jboss.weld.util.ServiceLoader.loadServiceFile(ServiceLoader.java:177)
	at org.jboss.weld.util.ServiceLoader.reload(ServiceLoader.java:149)
	at org.jboss.weld.util.ServiceLoader.iterator(ServiceLoader.java:292)
	at org.glassfish.weld.DeploymentImpl.getExtensions(DeploymentImpl.java:365)
	at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:324)
	at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:177)
	at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:128)
	at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:277)
	at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:460)
	at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
	at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
	at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
	at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
	at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
	at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
	at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:348)
	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:189)
	at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:850)
	at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:747)
	at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1032)
	at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:231)
	at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
	at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
	at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
	at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
	at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
	at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
	at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
	at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.core.Context not found by com.sun.jersey.glassfish.v3.osgi.jersey-gf-servlet [219]
	at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1460)
	at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:72)
	at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1843)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
	... 43 more
|#]




[JERSEY-1653] @BeanParam with proxy client does not work Created: 16/Jan/13  Updated: 24/Aug/16  Resolved: 11/Jan/16

Status: Resolved
Project: jersey
Component/s: core
Affects Version/s: 2.0-m11
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: aaronjwhiteside Assignee: Stepan Vavra
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Glassfish 4.0 b72


Sprint: Team Drosera

 Description   

@BeanParam with proxy client does not work

It does not send through the @HeaderParam's in the request... and the SmsResponse from the proxy method call is null.

For example...

@Path( "/" )
public interface ZengMessagingService
{
    @GET
    @Path( "/sms" )
    @BeanParam
    SmsResponse sendSms( @BeanParam SmsRequest request );

}

public class SmsRequest
extends OneTimePasswordRequest
{
    @HeaderParam( "delivery-mode" )
    private int deliveryMode;

    @HeaderParam( "categ" )
    private String subscriptionCategory;

...

public class SmsResponse
extends OneTimePasswordResponse
{
    @HeaderParam( "provisioning-code" )
    private String provisioningCode;

...

Client client = ClientFactory.newClient();
WebTarget target = client.target( "http://localhost:" + port + "/" );
ZengMessagingService zengMessagingService = WebResourceFactory.newResource( ZengMessagingService.class, target );
SmsResponse smsResponse = zengMessagingService.sendSms( smsRequest );


 Comments   
Comment by aaronjwhiteside [ 16/Jan/13 ]

Probably related to JERSEY-1654

Comment by aaronjwhiteside [ 16/Jan/13 ]

Even if I change the sendSms() method from @GET to @POST in my example, it still does not pass through the @HeaderParam's in SmsRequest.

Comment by walec51 [ 14/Apr/15 ]

@BeanParam support is simply not implemented yet in Jersey Proxy Client
https://github.com/jersey/jersey/blob/master/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java

generally Jersey Proxy Client seams pretty week compared to RESTEasy's Client framework and adding @BeanParam will require a big refactoring of that WebResourceFactory

Comment by Stepan Vavra [ 11/Jan/16 ]

Hi,
while it seems to be a valid issue, it is not critical to core functionality and we do not plan to dedicate resources to fixing the issue at the moment. In case you feel strongly about the issue, please consider contributing a fix by submitting a Github pull request.

Thanks!
Stepan

Comment by lucastsa [ 24/Aug/16 ]

I implemented this functionality on pull request https://github.com/jersey/jersey/pull/235
Not really sure if it will get merged, but you can use it to build your `jersey-proxy-client` artifact.





[JERSEY-2907] Concurrent invocations of ContainerRequestContext#abortWith(..) cause server to hang Created: 09/Jul/15  Updated: 22/Aug/16  Resolved: 06/Aug/15

Status: Resolved
Project: jersey
Component/s: None
Affects Version/s: 2.17
Fix Version/s: None

Type: Bug Priority: Major
Reporter: gjwiley Assignee: Stepan Vavra
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

JSE 1.8 u45, others
Ubuntu 14.04, Amazon Linux
Amazon EC2 and Asus i7



 Description   

The following filter is meant to authorize any request for which a principal has been computed and reject all others. Requests that do not cause the invocation of abortWith(..) run fine. The server can handle many such requests simultaneously.

When requests that do cause the invocation of abortWith(..) are invoked in succession, there is no problem. However if two or more such requests arrive at about the same time, none of them receives any data and the connection hangs. After a request hangs, all further requests, including those advised by the filter that do not invoke abortWith(..) and those that bypass the filter entirely, also hang.

Both log statements are always invoked meaning the method itself does not block. Further, serializing the invocation with a synchronized block on the static LOG monitor does not solve the problem.

I have tried this with the Grizzly2 and JDK containers. Both exhibit the same behavior.

@Priority(Priorities.AUTHORIZATION)
public class RequirePrincipalFilter implements ContainerRequestFilter {

    private static final Logger LOG = LoggerFactory
            .getLogger(RequirePrincipalFilter.class);

    @Override
    public void filter(final ContainerRequestContext requestContext)
            throws IOException {
        if (requestContext.getSecurityContext() == null
                || requestContext.getSecurityContext().getUserPrincipal() == null) {
            LOG.debug("No Principal");
            requestContext.abortWith(Response
                    .status(Status.UNAUTHORIZED)
                    .entity(new ErrorRepresentation(Status.UNAUTHORIZED
                            .getStatusCode(), "Authorization required"))
                    .header("WWW-Authenticate", "Bearer").build());
            LOG.debug("Request Aborted");
        }
    }
}


 Comments   
Comment by gjwiley [ 11/Jul/15 ]

Verified that this is also a problem using Jersey 2.19.

Comment by Stepan Vavra [ 06/Aug/15 ]

Hi,
I was unable to reproduce the problem you reported. Any chance you could sent as a fully reproducible example? If so, please don't hesitate to reopen this ticket!
I tried it on Jetty and Grizzly, with thousands of requests per second and everything worked just fine.

Thanks!
Stepan

Comment by damir_kadyrov [ 22/Aug/16 ]

Hi @svavra,

I have the same problem in OSGi environment (equinox).
If I sent correct auth token, application work well. But if I send incorrect token, I will receive only first responce. The second and another requests do not give the correct responces.

MyBundleActivator.java
@Component
public class MyBundleActivator {
private AuthService authService;
@Activate
    public void start(BundleContext bundleContext) {
        MyResource myResource = new MyResource();
        ResourceConfig resourceConfig = new ResourceConfig(JacksonFeature.class, AppExceptionMapper.class);
        resourceConfig.register(myResource);
        resourceConfig.register(new TokenFilter(authService));
        server = GrizzlyHttpServerFactory.createHttpServer(new URI("http://localhost:9999/"), resourceConfig);
	server.start();
    }
	@Reference(service = AuthService.class)
	public void bindAuthService(AuthService authService) {
		this.authService = authService;
	}
	public void unbindAuthService(AuthService authService) {
		this.authService = null;
	}
}
TokenFilter.java
public class TokenFilter implements ContainerRequestFilter {

	@Context
	private ResourceInfo resourceInfo;

	private final AuthService authService;

	public TokenFilter(AuthService authService) {
		this.authService = authService;
	}

	private static final String AUTHORIZATION_PROPERTY = "X-ACCESS-TOKEN";
	
	private static final Response ACCESS_DENIED = Response.status(Response.Status.UNAUTHORIZED)
			.type(MediaType.APPLICATION_JSON)
			.entity("You cannot access this resource ")
			.encoding("UTF-8")
//			.cacheControl(CacheControl.valueOf("private, max-age=0, no-cache"))
			.build();
	
	
	private static final Response ACCESS_FORBIDDEN = Response.status(Response.Status.FORBIDDEN)
			.type(MediaType.APPLICATION_JSON)
			.entity(ErrorMessage.message("Access blocked for all users !!", Response.Status.FORBIDDEN))
			.encoding("UTF-8")
//			.cacheControl(CacheControl.valueOf("private, max-age=0, no-cache"))
			.build();

	@Override
	public void filter(ContainerRequestContext requestContext) {
		Method method = resourceInfo.getResourceMethod();
		// Access allowed for all
		if (!method.isAnnotationPresent(PermitAll.class)) {
			// Access denied for all
			if (method.isAnnotationPresent(DenyAll.class)) {
				requestContext.abortWith(ACCESS_FORBIDDEN);
				return;
			}
			// Get request headers
			final MultivaluedMap<String, String> headers = requestContext.getHeaders();
			// Fetch authorization header
			final List<String> authorization = headers.get(AUTHORIZATION_PROPERTY);
			// If no authorization information present; block access
			if (authorization == null || authorization.isEmpty()) {
				requestContext.abortWith(ACCESS_DENIED);
				return;
			}

			// Get user token
			final String authToken = authorization.get(0).trim();

			User admin = authService.getUserByToken(authToken);

			if (admin == null) {
				requestContext.abortWith(ACCESS_DENIED);
			}
		}
	}
}
MyResource.java
@Path("/myres")
@Produces(ApplicationMediaType.APPLICATION_JSON_UTF8)
@Consumes(ApplicationMediaType.APPLICATION_JSON_UTF8)
public class MyResource {
private AuthService authService;
        @GET
	@Path("")
	public DataItem getData() {
		DataItem item = new DataItem();
		item.setName("test");
		return item;
	}
}
2016-08-22 16:08:23 [grizzly-http-server-1] ERROR o.g.j.server.ServerRuntime$Responder - An I/O error has occurred while writing a response message entity to the container output stream.
java.lang.IllegalStateException: The output stream has already been closed.
	at org.glassfish.jersey.message.internal.CommittingOutputStream.setStreamProvider(CommittingOutputStream.java:147) ~[com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.message.internal.OutboundMessageContext.setStreamProvider(OutboundMessageContext.java:803) ~[com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.server.ContainerResponse.setStreamProvider(ContainerResponse.java:372) ~[com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:694) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:444) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:434) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:329) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.internal.Errors.process(Errors.java:315) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.internal.Errors.process(Errors.java:297) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.internal.Errors.process(Errors.java:267) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:384) [org.glassfish.jersey.containers.jersey-container-grizzly2-http_2.22.2.jar:na]
	at org.glassfish.grizzly.http.server.HttpHandler$1.run(HttpHandler.java:224) [org.glassfish.grizzly.http-server_2.3.23.jar:na]
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591) [org.glassfish.grizzly.framework_2.3.23.jar:na]
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571) [org.glassfish.grizzly.framework_2.3.23.jar:na]
	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_77]
2016-08-22 16:08:23 [grizzly-http-server-1] ERROR o.g.j.server.ServerRuntime$Responder - Error while closing the output stream in order to commit response.
java.lang.NullPointerException: null
	at org.glassfish.grizzly.http.server.NIOOutputStreamImpl.flush(NIOOutputStreamImpl.java:90) ~[na:na]
	at org.glassfish.jersey.message.internal.CommittingOutputStream.flush(CommittingOutputStream.java:292) ~[com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.message.internal.OutboundMessageContext.close(OutboundMessageContext.java:838) ~[com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.server.ContainerResponse.close(ContainerResponse.java:412) ~[com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:784) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:444) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:434) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:329) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.internal.Errors.process(Errors.java:315) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.internal.Errors.process(Errors.java:297) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.internal.Errors.process(Errors.java:267) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) [com.eclipsesource.jaxrs.jersey-all_2.22.2.jar:na]
	at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:384) [org.glassfish.jersey.containers.jersey-container-grizzly2-http_2.22.2.jar:na]
	at org.glassfish.grizzly.http.server.HttpHandler$1.run(HttpHandler.java:224) [org.glassfish.grizzly.http-server_2.3.23.jar:na]
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591) [org.glassfish.grizzly.framework_2.3.23.jar:na]
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571) [org.glassfish.grizzly.framework_2.3.23.jar:na]
	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_77]




Generated at Sat Aug 27 05:14:25 UTC 2016 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.