Friday Aug 03, 2012

Issue dev'ing RESTful JSON services on NetBeans

Here is a tricky issue that you may find if you are developing RESTful services with Java EE on NetBeans and GlassFish or WebLogic. If you want to support the JSON format but need to access some implementation classes like @JsonIgnore, you need to add the JAX-RS RI, Jersey, to your project's Libraries definition. How to add the RI? You will probably do this:

  1. Open project's Properties (right click on the project)
  2. Go to Libraries
  3. Click on 'Add Library'
  4. Select 'Jersey 1.8 (JAX-RS RI)

But you won't have your service running fine. You may find these exceptions: (added here so Google can help future users)

1 - If you try to access your RESTful service to get a JSON format of it, you will get this exception:

com.sun.jersey.spi.inject.Errors$ErrorMessagesException
  at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
  at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)

2 - If you try to access your RESTful service to get an XML format, you will get this exception:

java.lang.RuntimeException: javax.naming.NameNotFoundException: Unable to resolve 'com.sun.jersey.config.CDIExtension'. Resolved 'com.sun.jersey.config'; remaining name 'CDIExtension'
  at com.sun.jersey.server.impl.cdi.CDIExtension.getInitializedExtension(CDIExtension.java:177)
  at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactory.(CDIComponentProviderFactory.java:92)
  at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer.initialize(CDIComponentProviderFactoryInitializer.java:75)
  at com.sun.jersey.spi.container.servlet.WebComponent.configure(WebComponent.java:576)
  at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.configure(ServletContainer.java:311)

 If you look at your server's log, (in my case, I was using WebLogic 12c) you may find this message somewhere:

WARNING: 
**********
The application is using ServletContainerInitializer class com.sun.jersey.server.impl.container.servlet.JerseyServletContainerInitializer that is loaded from:file:/labs/wls1211/modules/com.sun.jersey.server_1.1.0.0_1-9.jar. This initializer overrides the one available in the system.
**********

When you added Jersey to your library, the "package" checkbox was checked by default. So the JAR ended up going into WEB-INF/lib of your project, conflicting to the already provided by the container. 

So, how to fix this issue? Follow these steps:

  1. Open project's Properties (right click on the project)
  2. Go to Libraries
  3. Uncheck the checkbox 'Package' for Jersey 1.8 (JAX-RS RI)
  4. Click on 'OK'
  5.  Clean & Build (right click on the project) ---> remember to clean and rebuild your project
  6. (re)Deploy application

Done! :_)

 

Thursday Aug 02, 2012

Enable WebLogic 12c FastSwap with NetBeans

Hey everyone, this is my first post, and although I have been working at Oracle since July 2nd, I wanted it to have valuable information, not just a "Hey look, I joined Oracle". So this is it, welcome to my blog!

 How to enable WebLogic 12c FastSwap when developing Java EE applications with NetBeans? Very simple!

  1. Open the file WEB-INF/weblogic.xml
    1. If your application is an EAR, open weblogic-application.xml
  2. Enable FastSwap
    <fast-swap>
        <enabled>true</enabled>
    </fast-swap>
  3. Now open the Properties dialog for your project
  4. Navigate to Run
  5. Disable the checkbox "Deploy on Save"
  6. Close the Properties dialog
  7. Re-deploy your application

Done! Now give it a try. Modify some Java code and refresh the web page that access that code. Remember you don't need to re-deploy your application anymore. NetBeans already deploys it as exploded WAR/EAR. Faster than the re-deploy feature!

Also, FastSwap is a feature that is built-in to WebLogic 12c and there's no need to install anything. For more information about FastSwap, follow this link (for WebLogic 12.1.1).

Was this a valuable information for you? Sure it was for me :-) 

About


Bruno has been having fun working with Java since 2000 and now helps Oracle on sharing the technology accross all Latin America. Also plays videogames, does trekking and loves beer.

Follow me on Twitter! @brunoborges

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today