Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 370364 - ClassCastException at HttpServerManager.createHttpConnector
Summary: ClassCastException at HttpServerManager.createHttpConnector
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Server-Side (show other bugs)
Version: 3.8.0 Juno   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: Juno M6   Edit
Assignee: Thomas Watson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-01 14:01 EST by Cristiano Gaviao CLA
Modified: 2012-02-22 17:27 EST (History)
5 users (show)

See Also:


Attachments
Fixed class (12.58 KB, application/octet-stream)
2012-02-01 14:30 EST, Cristiano Gaviao CLA
no flags Details
HttpServerManager (13.73 KB, application/octet-stream)
2012-02-02 22:11 EST, Cristiano Gaviao CLA
no flags Details
this is the patch from git (4.01 KB, patch)
2012-02-06 07:23 EST, Cristiano Gaviao CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Cristiano Gaviao CLA 2012-02-01 14:01:51 EST
Build Identifier: I20120127-1145

!ENTRY org.eclipse.equinox.cm 4 0 2012-02-01 15:28:07.818
!MESSAGE java.lang.String cannot be cast to java.lang.Integer
!STACK 0
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
	at org.eclipse.equinox.http.jetty.internal.HttpServerManager.createHttpConnector(HttpServerManager.java:134)
	at org.eclipse.equinox.http.jetty.internal.HttpServerManager.updated(HttpServerManager.java:72)
	at org.eclipse.equinox.internal.cm.ManagedServiceFactoryTracker$2.run(ManagedServiceFactoryTracker.java:190)
	at org.eclipse.equinox.internal.cm.SerializedTaskQueue$1.run(SerializedTaskQueue.java:36)
15:28:07.824 [com.c4biz.osgiutils.logging.reader.OsgiLogListener@831fb31] ERROR org.eclipse.equinox.cm - java.lang.String cannot be cast to java.lang.Integer
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
	at org.eclipse.equinox.http.jetty.internal.HttpServerManager.createHttpConnector(HttpServerManager.java:134) ~[na:na]
	at org.eclipse.equinox.http.jetty.internal.HttpServerManager.updated(HttpServerManager.java:72) ~[na:na]
	at org.eclipse.equinox.internal.cm.ManagedServiceFactoryTracker$2.run(ManagedServiceFactoryTracker.java:190) ~[na:na]
	at org.eclipse.equinox.internal.cm.SerializedTaskQueue$1.run(SerializedTaskQueue.java:36) ~[na:na]

Reproducible: Always

Steps to Reproduce:
1. create a bundle with a Configuration Manager update

properties = getJettyProperties();
configuration = configurationAdmin.createFactoryConfiguration(
                   "org.eclipse.equinox.http.jetty.config", null);
configuration.update(properties);

2. start the org.eclipse.equinox.http.jetty bundle using automatic activation

3. start the bundle with the new configuration
Comment 1 Cristiano Gaviao CLA 2012-02-01 14:30:06 EST
Created attachment 210399 [details]
Fixed class

I've used the "import plugin as source" to be able to fix it in a proper time to my job. So I'm sending it instead a patch.
Comment 2 Cristiano Gaviao CLA 2012-02-01 14:48:19 EST
please, forget the attached class.. I can't remove it. :(
It doesn't resolve the problem since values of Dictionary could be others than Strings.
Comment 3 Hugues Malphettes CLA 2012-02-01 21:49:25 EST
Hi Cristiano, than ks fr the report and the fix.
It looks like a change in org.eclipse.equinox.http.jetty.internal.HttpServerManager: not specific to OSGi.
If could post a diff it would really help to figure what you had to change.
Comment 4 Hugues Malphettes CLA 2012-02-01 23:10:15 EST
Read the message on the mailing list:
The change is here: Integer httpsPort = (Integer) dictionary.get(JettyConstants.HTTPS_PORT);
        if (httpsPort == null)
            return null;

Unfortunately this code lives at equinox:
org.eclipse.equinox.http.jetty.internal.HttpServerManager

Have you tried setting up the system property as an integer instead of a string:
System.setProperty("org.eclipse.equinox.http.jetty."
                + JettyConstants.HTTP_PORT, "8080");
set as:
System.setProperty("org.eclipse.equinox.http.jetty."
                + JettyConstants.HTTP_PORT, 8080);
Comment 5 Cristiano Gaviao CLA 2012-02-02 08:47:24 EST
The system settings is not the problem because this code (@ Activator.java) treat the casting properly:

// HTTP Port
		String httpPortProperty = context.getProperty(PROPERTY_PREFIX + JettyConstants.HTTP_PORT);
		if (httpPortProperty == null)
			httpPortProperty = context.getProperty(ORG_OSGI_SERVICE_HTTP_PORT);

		int httpPort = 80;
		if (httpPortProperty != null) {
			try {
				httpPort = Integer.parseInt(httpPortProperty);
			} catch (NumberFormatException e) {
				//(log this) ignore and use default
			}
		}

The problem occurs if you try to modify the configuration using CM and do not use the right type, as you state.

Unfortunately, my configuration data is coming from a properties file, so everything is a string...
Comment 6 Cristiano Gaviao CLA 2012-02-02 22:11:51 EST
Created attachment 210486 [details]
HttpServerManager

New class that added type tests to avoid casting errors.
Comment 7 Cristiano Gaviao CLA 2012-02-04 15:55:39 EST
(In reply to comment #3)
> Hi Cristiano, than ks fr the report and the fix.
> It looks like a change in
> org.eclipse.equinox.http.jetty.internal.HttpServerManager: not specific to
> OSGi.
> If could post a diff it would really help to figure what you had to change.


Please, could you tell me where is the repository containing the source? there are so many that i have no idea where could be this project...

thanks
Comment 8 Hugues Malphettes CLA 2012-02-04 18:59:26 EST
(In reply to comment #7)
> (In reply to comment #3)
> > Hi Cristiano, than ks fr the report and the fix.
> > It looks like a change in
> > org.eclipse.equinox.http.jetty.internal.HttpServerManager: not specific to
> > OSGi.
> > If could post a diff it would really help to figure what you had to change.
> 
> 
> Please, could you tell me where is the repository containing the source? there
> are so many that i have no idea where could be this project...
> 
> thanks

It is here: http://git.eclipse.org/c/equinox/rt.equinox.bundles.git/tree/bundles
mirrored on github if you prefer that:
https://github.com/eclipse/rt.equinox.bundles
Comment 9 Cristiano Gaviao CLA 2012-02-06 07:23:52 EST
Created attachment 210571 [details]
this is the patch from git

I couldn't find the org.eclipse.equinox.http.jetty folder, so I've supposed that could be this one:
org.eclipse.equinox.http.jetty8
Comment 10 Hugues Malphettes CLA 2012-02-06 20:22:28 EST
Hi Cristiano, I have moved this bug to the equinox project because this code is not part of the jetty code.
Comment 11 Thomas Watson CLA 2012-02-07 09:25:54 EST
I don't think this is a bug.  Configuration types are not restricted to be of type String only.  The org.eclipse.equinox.http.jetty (8) bundle specifies the types expected with metatype xml (which can be inspected with the MetaTypeService).


http://git.eclipse.org/c/equinox/rt.equinox.bundles.git/tree/bundles/org.eclipse.equinox.http.jetty8/OSGI-INF/metatype/config.xml

I am not dead set against making this easier to use, but I also don't want to give you the impression that all configuration types are restricted to type string.  Simon, what do you think about this change?
Comment 12 Cristiano Gaviao CLA 2012-02-07 10:31:05 EST
Thomas,

I'm not inferring that all configuration are/should be String, but if you can't use metatype (as is the case where the configuration comes from System Properties) it should be properly treated.
This is what was used in the Activator class to do that:

// HTTP Port
        String httpPortProperty = context.getProperty(PROPERTY_PREFIX +
JettyConstants.HTTP_PORT);
        if (httpPortProperty == null)
            httpPortProperty = context.getProperty(ORG_OSGI_SERVICE_HTTP_PORT);

        int httpPort = 80;
        if (httpPortProperty != null) {
            try {
                httpPort = Integer.parseInt(httpPortProperty);
            } catch (NumberFormatException e) {
                //(log this) ignore and use default
            }
        } 


So, the same should be applied to HttpServerManager, because are cases where you can't use metatype, mainly when you are getting configuration from a properties file. Treat each property from the property file doesn't make sense. It is much easier to treat the string.
Comment 13 Thomas Watson CLA 2012-02-08 09:54:45 EST
I chatted with Simon briefly about this.  We agreed that this is an enhancement request since you are not configuring the system in the original way it was designed.  But the good news is that we don't see the harm in supporting your patch and will release it for Juno.

Thanks for the contribution.
Comment 15 Cristiano Gaviao CLA 2012-02-22 14:19:32 EST
Hi Thomas,  could you tell me if there are any p2 repository that contains the latest changes in equinox/rt bundles that I could point my project to ?

cheers
Comment 16 Thomas Watson CLA 2012-02-22 17:27:47 EST
(In reply to comment #15)
> Hi Thomas,  could you tell me if there are any p2 repository that contains the
> latest changes in equinox/rt bundles that I could point my project to ?
> 
> cheers

you can download the p2 repo from our latest I-Build at http://download.eclipse.org/equinox/drops/I20120221-1514/index.php

We used to include this content in the eclipse 3.8 I-Build repos (http://wiki.eclipse.org/Eclipse_Project_Update_Sites) but the equinox content does not seem to be included anymore.  Kim, I think you still had an open issue on this?