You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@wink.apache.org by vareshbe <va...@gmail.com> on 2011/07/25 11:55:35 UTC

Unable to register MediaTypeFactory

Hi All,

I am unable to register a MediaTypeFactory. It is giving me
ClassNotFoundException.

Following is the error I am receiving. 
Could you kindly assist in resolving the same?

[7/25/11 14:57:19:026 IST] 0000001e DeploymentCon E
org.apache.wink.server.internal.DeploymentConfiguration initMediaTypeMapper
com.test.controller.handlers.MediaTypeFactory is not a class or the class
has unresolved dependencies. Ignoring.
                                 java.lang.ClassNotFoundException:
com.test.controller.handlers.MediaTypeFactory
	at java.lang.Class.forNameImpl(Native Method)
	at java.lang.Class.forName(Class.java:130)
	at
org.apache.wink.server.internal.DeploymentConfiguration.initMediaTypeMapper(DeploymentConfiguration.java:334)
	at
org.apache.wink.server.internal.DeploymentConfiguration.init(DeploymentConfiguration.java:145)
	at
org.apache.wink.server.internal.servlet.RestServlet.getDeploymentConfiguration(RestServlet.java:128)

*MediaTypeFactory.java*
public class MediaTypeFactory extends MediaTypeMapperFactory{
	public MediaTypeFactory() {
		super();
	}
	@Override
	public List<? extends MediaTypeMappingRecord> getMediaTypeMappings() {
		ArrayList<MediaTypeMappingRecord> mediaTypeMappingRecord = new
ArrayList<MediaTypeMappingRecord>();
		mediaTypeMappingRecord.add(new MediaTypeRecord());
		return mediaTypeMappingRecord;
	}

}

*MediaTypeRecord.java*
public class MediaTypeRecord implements MediaTypeMappingRecord{
	public MediaType match(HttpHeaders requestHeaders,
			MediaType responseMediaType) {
		return MediaType.APPLICATION_JSON_TYPE;
	}
}

I am however, able to register the RequestHandlers properly. 
In the code (DeploymentConfiguration.java), I see different logic to lookup
the class for handlersFactory and MediaTypesFactory.
Can someone please explain the rational behind this.

Regards.


--
View this message in context: http://apache-wink-users.3471013.n2.nabble.com/Unable-to-register-MediaTypeFactory-tp6617708p6617708.html
Sent from the Apache Wink Users mailing list archive at Nabble.com.

Re: Unable to register MediaTypeFactory

Posted by vareshbe <va...@gmail.com>.
I think I have found the reason for it not working in my J2EE environment.

The issue is mentioned over here. 
https://issues.apache.org/jira/browse/WINK-226 Issue WINK-226 

I assume this needs to be corrected for MediaType Factory also.

Can someone suggest a workaround on how to bypass this for the time being?

--
View this message in context: http://apache-wink-users.3471013.n2.nabble.com/Unable-to-register-MediaTypeFactory-tp6617708p6621825.html
Sent from the Apache Wink Users mailing list archive at Nabble.com.

Re: Unable to register MediaTypeFactory

Posted by vareshbe <va...@gmail.com>.
I am using the wink as a JAR and not a project and hence am not able to
perform the changes there. I will see if that is possible.

However, I tried to use both ways for getting class instance and it worked.
(I tried the instantiation in my request handler init method and was able to
do it using both Class.forName and ClassUtils.getClass methods).

I also observed one thing, that in Version 1.0, the initHandler method was
using Class.forName and this was modified after that... So there seems to be
some reason behind the change.

Regards,
Varesh

--
View this message in context: http://apache-wink-users.3471013.n2.nabble.com/Unable-to-register-MediaTypeFactory-tp6617708p6621745.html
Sent from the Apache Wink Users mailing list archive at Nabble.com.

Re: Unable to register MediaTypeFactory

Posted by Bryant Luk <br...@gmail.com>.
I think the code for doing the handlersFactory vs MediaTypesFactory
was just written at 2 different times. If you patched the code to
perform similar object instantiations in the media type mappers, does
it work?

On Mon, Jul 25, 2011 at 4:55 AM, vareshbe <va...@gmail.com> wrote:
> Hi All,
>
> I am unable to register a MediaTypeFactory. It is giving me
> ClassNotFoundException.
>
> Following is the error I am receiving.
> Could you kindly assist in resolving the same?
>
> [7/25/11 14:57:19:026 IST] 0000001e DeploymentCon E
> org.apache.wink.server.internal.DeploymentConfiguration initMediaTypeMapper
> com.test.controller.handlers.MediaTypeFactory is not a class or the class
> has unresolved dependencies. Ignoring.
>                                 java.lang.ClassNotFoundException:
> com.test.controller.handlers.MediaTypeFactory
>        at java.lang.Class.forNameImpl(Native Method)
>        at java.lang.Class.forName(Class.java:130)
>        at
> org.apache.wink.server.internal.DeploymentConfiguration.initMediaTypeMapper(DeploymentConfiguration.java:334)
>        at
> org.apache.wink.server.internal.DeploymentConfiguration.init(DeploymentConfiguration.java:145)
>        at
> org.apache.wink.server.internal.servlet.RestServlet.getDeploymentConfiguration(RestServlet.java:128)
>
> *MediaTypeFactory.java*
> public class MediaTypeFactory extends MediaTypeMapperFactory{
>        public MediaTypeFactory() {
>                super();
>        }
>        @Override
>        public List<? extends MediaTypeMappingRecord> getMediaTypeMappings() {
>                ArrayList<MediaTypeMappingRecord> mediaTypeMappingRecord = new
> ArrayList<MediaTypeMappingRecord>();
>                mediaTypeMappingRecord.add(new MediaTypeRecord());
>                return mediaTypeMappingRecord;
>        }
>
> }
>
> *MediaTypeRecord.java*
> public class MediaTypeRecord implements MediaTypeMappingRecord{
>        public MediaType match(HttpHeaders requestHeaders,
>                        MediaType responseMediaType) {
>                return MediaType.APPLICATION_JSON_TYPE;
>        }
> }
>
> I am however, able to register the RequestHandlers properly.
> In the code (DeploymentConfiguration.java), I see different logic to lookup
> the class for handlersFactory and MediaTypesFactory.
> Can someone please explain the rational behind this.
>
> Regards.
>
>
> --
> View this message in context: http://apache-wink-users.3471013.n2.nabble.com/Unable-to-register-MediaTypeFactory-tp6617708p6617708.html
> Sent from the Apache Wink Users mailing list archive at Nabble.com.
>