Equivalent to WebApplicationException(String message, int status) in JavaEE6 - java-ee-6

I know that the method is introduced in Java EE 7 with JAX-RS 2.0.
I want to throw such exception with detailMessage included in Java EE 6.
In Java EE 7 I could simply do:
throw new WebApplicationException("My Error Msg", statusCode);
But how can I do this with Java EE 6?
http://docs.oracle.com/javaee/7/api/javax/ws/rs/WebApplicationException.html
http://docs.oracle.com/javaee/6/api/javax/ws/rs/WebApplicationException.html

Related

Scalatra throwing null pointer exception with java 8

I am running a web application with Scala version 2.9.0 and Scalatra version 2.1.0-SNAPSHOT. I build the application with Java 1.6. It runs fine when I run it with Java 1.7 but fails when ran with Java 1.8 with this error. What can be the issue?
It is important for me to run with java 1.8 is because I have some third party jars used in my application which are complied with java 1.8. I have other scala applications with I have built with java 1.6 and run fine with java 1.8 but I am only facing this issue with applications using scalatra.
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.fusesource.scalate.TemplateException
org.fusesource.scalate.TemplateEngine.compileAndLoad(TemplateEngine.scala:834)
org.fusesource.scalate.TemplateEngine.compileAndLoadEntry(TemplateEngine.scala:691)
org.fusesource.scalate.TemplateEngine.liftedTree1$1(TemplateEngine.scala:411)
org.fusesource.scalate.TemplateEngine.load(TemplateEngine.scala:405)
org.fusesource.scalate.TemplateEngine.load(TemplateEngine.scala:475)
org.scalatra.scalate.ScalateSupport$class.renderScalateErrorPage(ScalateSupport.scala:140)
org.scalatra.scalate.ScalateSupport$class.handle(ScalateSupport.scala:131)
root cause
java.lang.NullPointerException
scala.tools.nsc.Global$Run.compileLate(Global.scala:1043)
scala.tools.nsc.symtab.SymbolLoaders$SourcefileLoader.doComplete(SymbolLoaders.scala:303)
scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:111)
scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:85)
scala.tools.nsc.symtab.Symbols$Symbol.info(Symbols.scala:732)
The release notes for Scala 2.9 list it's dependencies: "It requires the Java runtime version 1.6 or 1.7." Scala 2.11.1 announced support for Java 8 but called that "experimental." The experimental adjective was dropped from the release notes in Scala 2.11.2, but I've had problems with Java 8 in projects using later versions of Scala (probably 2.11.7).

How get the version of an EAR module at runtime in Java EE 6 (JBoss AS 7)?

I have a EAR module with some sub modules (using Maven). I would like to display in the Web application (one of the sub modules) the version of the EAR.
How do I get the version of EAR in runtime?
I'm using JavaEE 6 and JBoss AS 7.1.1.Final
I get the name of my app by calling this code from my EJB bean:
String appName = (String) (new InitialContext()).lookup( "java:app/AppName" );
In our project we get a hold of the ear /META-INF/MANIFEST.MF (java.util.jar.Manifest)
Then we can do
manifest.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION);

constructor Service in class javax.xml.ws.Service cannot be applied to given types

I have created a web service with apache-cxf-2.7.4.
I entered the classes produced in my project.
the libraries I have in my project are:
math3-commons-3.2.jar
XStream-1.4.4.jar
jaxws-api-2.2.5.jar
I have the following error:
constructor Service in class javax.xml.ws.Service cannot be applied to given types;
required: java.net.URL,javax.xml.namespace.QName
found: java.net.URL,javax.xml.namespace.QName,javax.xml.ws.WebServiceFeature[]
reason: actual and formal argument lists differ in length
The problem is the version of JAX-WS API. The classloader for your application first loaded the version included in Java SE or Java EE.
For Java SE 6 or Java EE 5, JAX-WS API 2.1. The constructors in javax.xml.ws.Service:
javax.xml.ws.Service.Service(URL, QName)
For Java SE 7 or Java EE 6, JAX-WS API 2.2. The constructors in javax.xml.ws.Service:
javax.xml.ws.Service.Service(URL, QName)
javax.xml.ws.Service.Service(URL, QName, WebServiceFeature...) // You need this!
There are three possible solutions (depends on whether it is a web application or standalone application):
Use Java SE 7 or Java EE 6.
Re-run wsdl2java with argument -frontend jaxws21 to generate JAX-WS 2.1 compliant code instead.
Change the classloader for load first the classes included in the application.
If using Maven to build you should add this to the execution configuration
<defaultOptions>
<extraargs>
<extraarg>-frontend</extraarg>
<extraarg>jaxws21</extraarg>
</extraargs>
</defaultOptions>
(thanks to Paul Vargas for pointing me in the right direction).
wsimport -help tells us about the -target option. It says:
Generate code as per the given JAXWS spec version. Defaults to 2.2, Accepted values are 2.0, 2.1 and 2.2
If you are using jdk wsimport tool, then just add the -target argument like below.
wsimport -keep -d \myDirToStoreExtractedClientCode -target 2.1 \myWSDLlocation\mineNotYours.wsdl
(Thanks Paul Vargas for helping out, old post but still helpful.)

testing java ee 6 with junit 3

I have a short question: Can I test java ee 6 with junit 3, or do I have to use JUnit 4?
No, JUnit version 3.8 and earlier supports Java up to version 1.4.
Source: http://www.methodsandtools.com/tools/tools.php?junit

Install the GlassFish 3 server adapter with Eclipse Helios 3.6, I got a problem

When I install the GlassFish 3 server adapter with Eclipse Helios 3.6 SR1 by here.
(Take care the third answer, I got the same problem.)
I got the wrong message:
Cannot complete the install because one or more required items could not be found.
Software being installed: GlassFish Java EE 5, Java EE 6 1.0.54 (com.sun.enterprise.jst.server.sunappsrv.feature.feature.group 1.0.54)
Missing requirement: GlassFish Java EE 5, Java EE 6 1.0.54 (com.sun.enterprise.jst.server.sunappsrv.feature.feature.group 1.0.54) requires 'org.eclipse.platform.feature.group [3.5.0,3.6.0)' but it could not be found
The main message is requires 'org.eclipse.platform.feature.group [3.5.0,3.6.0)', just like the third answer the way I followed.
Any suggestion ? Thank you.