Weblogic Jaxws deployment - class does not support JDK1.5 - weblogic

WebLogic Server Version: 10.3.6.0
Spring version: 3.2.1.RELEASE
Java JDK 1.6
I am trying to deploy a Spring application as WAR that uses jaxws into a Weblogic server.
The application works well with Jetty. However when deploying(I mean starting deployed app) Weblogic following exception occurs:
Caused By: java.lang.UnsupportedOperationException: This class does not support JDK1.5
at weblogic.xml.jaxp.RegistryTransformerFactory.setFeature(RegistryTransformerFactory.java:317)
at com.sun.xml.ws.util.xml.XmlUtil.newTransformerFactory(XmlUtil.java:392)
at com.sun.xml.ws.util.xml.XmlUtil.newTransformerFactory(XmlUtil.java:400)
at com.sun.xml.ws.util.xml.XmlUtil.<clinit>(XmlUtil.java:233)
at org.jvnet.jax_ws_commons.spring.SpringService.getObject(SpringService.java:36
.
maven pom.xml
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.10</version>
</dependency>
<dependency>
<groupId>org.jvnet.jax-ws-commons.spring</groupId>
<artifactId>jaxws-spring</artifactId>
<version>1.9</version>
</dependency>
Weblogic.xml
<weblogic-web-app>
<context-root>/MyApp</context-root>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
<show-archived-real-path-enabled>true</show-archived-real-path-enabled>
</container-descriptor>
</weblogic-web-app>

It is being fixed by changing weblogic.xml
<container-descriptor>
<prefer-web-inf-classes>false</prefer-web-inf-classes>
<show-archived-real-path-enabled>true</show-archived-real-path-enabled>
<prefer-application-packages>
<package-name>com.sun.xml.ws.server.*</package-name>
</prefer-application-packages>
</container-descriptor>
And in init servlet (if you use the old style) you should change the way you acquire the context as:
private static WebApplicationContext context;
#Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext sc = sce.getServletContext();
this.context = WebApplicationContextUtils.getWebApplicationContext(sc);
...
}
public static WebApplicationContext getApplicationContext(){
return context;
}
That fixes it

Related

Jax-WS Axis2 Proxy over SSL error using ProxySelector

In my project I have the following project structure:
I have a module that is producing a war file and can be deployed inside a Tomcat application server. This module has dependencies on Axis2 libraries:
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-webapp</artifactId>
<type>war</type>
</dependency>
And this class contains an axis2.xml file in the conf folder under WEB-INF.
Now this module has a dependency on a unit module, that has the package type of a jar.
Now in my web-module, in the code for my stub I have following code:
GazelleObjectValidator.getInstance().validateObject();
The XcpdValidationService is a class in the jar module (dependency) and this method calls an external web service over SSL and using a proxy.
This web service client is generated by JAX WS RI
BUT this class doesn't use the axis2.xml configuration from the parent module and uses it's own axis configuration, being the default one, where my proxy is not configured...
#WebEndpoint(name = "GazelleObjectValidatorPort")
public GazelleObjectValidator getGazelleObjectValidatorPort() {
return super.getPort(new QName("http://ws.validator.sch.gazelle.ihe.net/", "GazelleObjectValidatorPort"), GazelleObjectValidator.class);
}
The method itself looks like this:
#WebMethod
#WebResult(name = "validationResult", targetNamespace = "")
#RequestWrapper(localName = "validateObject", targetNamespace = "http://ws.validator.sch.gazelle.ihe.net/", className = "net.ihe.gazelle.schematron.ValidateObject")
#ResponseWrapper(localName = "validateObjectResponse", targetNamespace = "http://ws.validator.sch.gazelle.ihe.net/", className = "net.ihe.gazelle.schematron.ValidateObjectResponse")
public String validateObject(
#WebParam(name = "base64ObjectToValidate", targetNamespace = "")
String base64ObjectToValidate,
#WebParam(name = "xmlReferencedStandard", targetNamespace = "")
String xmlReferencedStandard,
#WebParam(name = "xmlMetadata", targetNamespace = "")
String xmlMetadata)
throws SOAPException_Exception
;
My GazelleObjectValidatorService is generated by following plugin:
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-aar-maven-plugin</artifactId>
<version>${axis2.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>package-aar</id>
<phase>prepare-package</phase>
<goals>
<goal>aar</goal>
</goals>
</execution>
</executions>
<configuration>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/resources/wsdl</directory>
<outputDirectory>META-INF</outputDirectory>
<includes>
<include>**/*.xsd</include>
</includes>
</fileSet>
</fileSets>
<servicesXmlFile>${project.build.outputDirectory}/axis2/services.xml</servicesXmlFile>
<wsdlFile>${project.build.outputDirectory}/wsdl/ClientConnectorService.wsdl</wsdlFile>
</configuration>
</plugin>
I tried to override the transportSender in my axis2.xml configuration with my own defined MyCommonsHttpTransportSender:
<transportSender name="http"
class="eu.epsos.pt.cc.MyCommonsHTTPTransportSender">
<parameter name="PROTOCOL">HTTP/1.1</parameter>
<parameter name="Transfer-Encoding">chunked</parameter>
and
<transportSender name="https"
class="eu.epsos.pt.cc.MyCommonsHTTPTransportSender">
<parameter name="PROTOCOL">HTTP/1.1</parameter>
<parameter name="Transfer-Encoding">chunked</parameter>
</transportSender>
that knows about the proxy.
but unfortunately since the web service client is inside the jar that is a dependency of the war, it doesn't seem to use my axis2.xml configuration, but uses it's own axis configuration, which doesn't know about the proxy.
This causes the following error where you see clearly that it uses the default CommonsHTTPTransportSender and therefore throwing the error:
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:140)
at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:130)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.execute(AxisInvocationController.java:578)
at org.apache.axis2.jaxws.core.controller.impl.AxisInvocationController.doInvoke(AxisInvocationController.java:127)
at org.apache.axis2.jaxws.core.controller.impl.InvocationControllerImpl.invoke(InvocationControllerImpl.java:93)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:373)
... 40 common frames omitted
Is there a way to let the WS client in the child jar make use of the same axis2 configuration of the parent module (that is a deployable war and has the axis2 dependencies?)
UPDATE:
My WAR file has an axis2 configuration, from the source code of this war, a service generated with wsimport is called which is in a JAR that is a dependency of the parent WAR. This service calls an external WebService and this happens over Axis (although doesn't use the axis2.xml configuration file, since this one is in the WEB-INF folder of the JAR.
Wouldn't there be any possibility to make the external WebService call in the JAR without Axis and use just JAXWS? This would solve my problems...
Axis2 provides a convenient method to configure the HTTP Transport. So, following from your sample code:
HttpTransportProperties.ProxyProperties proxyProperties = new HttpTransportProperties.new ProxyProperties();
proxyProperties.setProxyHostName("hostName");
proxyProperties.setProxyPort("hostPort");
proxyProperties.setUsername("User");
proxyProperties.setPassword("pw");
//set the properties
objectValidatorService.getServiceClient().getOptions().setProperty(HttpConstants.PROXY, proxyProperties);
The above wouldn't work for you because you're using the stock JAX-WS implementation, not the Axis2-specific client.
Based on your stacktrace, it appears you're connecting to a TLS-secured endpoint. There's a solution for that
I've done a lot of research, and there's no access to the underlying HTTPUrlConnection using stock JAX-WS. What we do have, is a way to set a custom SSLContextFactory. So we start by creating a custom factory, that will connect to the proxy first:
public class CustomSocketFactory extends SSLProtocolSocketFactory {
private static final CustomSocketFactory factory = new CustomSocketFactory();
static CustomSocketFactory getSocketFactory(){
return factory;
}
public CustomSocketFactory() {
super();
}
#Override
public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort) {
Socket socket = null;
try {
int proxyPort = 1000;
InetSocketAddress proxyAddr = new InetSocketAddress("proxyAddr", proxyPort);
Socket proxyConn = new Socket(new Proxy(Proxy.Type.SOCKS, proxyAddr));
proxyConn.connect(new InetSocketAddress("endHost", 443));
socket = (SSLSocket) super.createSocket(proxyConn, "proxyEndpoint", proxyPort, true);
} catch (IOException ex) {
Logger.getLogger(CustomSocketFactory.class.getName()).log(Level.SEVERE, null, ex);
}
return socket;
}
}
we'll now register this custom socket factory with the Apache HTTPClient runtime (Axis does not use the stock java HTTPUrlConnection, as is evidenced by your stacktrace):
Protocol.registerProtocol("https",new Protocol("https", new CustomSocketFactory(), 443));
This works only for TLS connections. (although, a custom socket factory is applicable to non-https endpoints also). You also need to set the timeout to 0 so we can guarantee that your overriden createSocket gets invoked

Spring Boot issues serializing java.time.LocalDateTime with Jackson to return ISO-8601 JSON timestamps?

I'm working on converting some models in a spring-boot REST API app to use java 8's java.time.LocalDateTime instead of joda's DateTime. I want the timestamps returned from API call to adhere to the ISO_8601 format. Motivation is to be forward compatible with Java 8's time (more here).
The part that's proving difficult is when it comes to serialize an object containing LocalDateTime to JSON.
For example, I have the following entity:
// ... misc imports
import java.time.LocalDateTime;
import java.time.ZoneOffset;
#Data
#Entity
#Table(name = "users")
public class User {
#Id #Column
private String id;
#Column
private String name;
#Column
private String email;
#Column
#JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss", timezone = "UTC")
private java.time.LocalDateTime createdAt;
public User(String name, String email) {
this.id = Utils.generateUUID();
this.createdAt = LocalDateTime.now(ZoneOffset.UTC);
}
}
I have also set my application.properties to turn off the dates as timestamp jackson feature:
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS = false
My maven deps:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.1.Final</version>
</dependency>
Finally, I try to retrieve the JSON representation via controller:
#RequestMapping("/users")
#RestController
public class UserController {
private UserService userService;
#Autowired
public UserController(UserService userService) {
this.userService = userService;
}
#RequestMapping(
value = "/{id}",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_UTF8_VALUE
)
public User getUser(#PathVariable("id") String id) {
return userService.findById(id);
}
}
When I actually make a call to this endpoint, I get the following exception:
java.lang.NoSuchMethodError:
com.fasterxml.jackson.datatype.jsr310.ser.JSR310FormattedSerializerBase.findFormatOverrides(Lcom/fasterxml/jackson/databind/SerializerProvider;Lcom/fasterxml/jackson/databind/BeanProperty;Ljava/lang/Class;)Lcom/fasterxml/jackson/annotation/JsonFormat$Value;
Alternately I also configured the app's ObjectMapper in the configuration class:
#Configuration
public class ServiceConfiguration {
#Bean
public ObjectMapper getJacksonObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.configure(
com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
false
);
return objectMapper;
}
}
Any leads will be greatly appreciated.
UPDATE:
Turns out it was a version mismatch between Spring Boot's Jackson version and the one I had in my pom.xml. As Miloš and Andy proposed, once I've set the correct version and run the app with spring.jackson.serialization.write_dates_as_timestamps=true, the issue was resolved, without needing to configure the ObjectMapper or adding annotations on my LocalDateTime model fields.
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.3.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
</dependencies>
The NoSuchMethodError is because you are mixing versions of Jackson. Spring Boot 1.3.6 uses Jackson 2.6.7 and you are using 2.8.1 of jackson-datatype-jsr310.
Spring Boot provides dependency management for Jackson, including jackson-datatype-jsr310, so you should remove the version from your pom. If you want to use a different version of Jackson, you should override the jackson.version property:
<properties>
<jackson.version>2.8.1</jackson.version>
</properties>
This will ensure that all your Jackson dependencies have the same version, thereby avoiding problems with mismatched versions.
You can also, if you wish, remove your Java code that's configuring the ObjectMapper. The Java Time module will be automatically registered when it's in the classpath and writing dates as timestamps can be configured in application.properties:
spring.jackson.serialization.write-dates-as-timestamps=false
Your ObjectMapper bean must be marked as #Primary in order to be picked up by Spring. Alternatively, you can just create a JavaTimeModule bean and it will get picked up by Spring and added to the default object mapper.
You've probably seen it already but take a look at the official documentation.
The error occurs because you mix versions of Jackson. You are using version 1.3.6.RELEASE of Spring Boot. If you would migrate to Spring Boot version 2.x.x.RELEASE then you can replace the com.fasterxml.jackson.datatype dependency by a spring-boot-starter-json dependency. In this way you let Spring Boot take care of the correct Jackson version.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</dependency>

Interceptor issue with Java EE7

I'm testing / switching to Java EE7 (Glassfish 4) and one of the issues I have is with Interceptors, whenever I try to run the project I am getting the following error.
SEVERE: Exception while loading the app : CDI deployment
failure:WELD-001417 Enabled interceptor class
com.xxxxxx.security.SecuredInterceptor in
file:/home/xxxxxx/xxxxxx/target/xxxxxx/WEB-INF/beans.xml#7 is neither
annotated #Interceptor nor registered through a portable extension
I'm looking at section 1.3.6 of the CDI 1.1 specification it doesn't look like anything has changed, so what am I doing wrong?
Here is the code I am using;
#InterceptorBinding
#Retention(RetentionPolicy.RUNTIME)
#Target({ElementType.TYPE, ElementType.METHOD})
public #interface Secured {}
#Secured
#Interceptor
public class SecuredInterceptor implements Serializable
{
#AroundInvoke
public Object interceptSecured(InvocationContext ic) throws Exception
{
// Do Stuff
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="annotated">
<interceptors>
<class>com.xxxxxx.security.SecuredInterceptor</class>
</interceptors>
</beans>
From section 12.1 of the CDI spec.
A bean archive which contains a beans.xml file with no version has a default bean discovery mode of all.
Your version 1.1 beans.xml has bean-discovery-mode="annotated". Change beans.xml to bean-discovery-mode="all" and my guess is it will work just like it does when you remove the version from beans.xml and use the old namespace, as in a CDI 1.0.
Seems to be Glassfish bug related to 1.1 version of beans.xml
https://java.net/jira/browse/GLASSFISH-20667

ProducerTemplate and Direct:start in camel

My camel route is :
from("direct:start")
.to("http://myhost/mypath");
I used :
ProducerTemplate template;
template.sendBody("direct:start", "This is a test message");
to send the exchange. I am getting following exception:
No consumers available on endpoint: Endpoint[direct://start].
How can i receive the same exchange in direct:start endpoint?
The reason you get this error is because you have not configured a Route that starts from direct:start.
If you have configured the Route, but did not mention it in your original query, then the next step to try is to first start the Camel Context, before calling the sendBody method.
camelContext.start();
template.sendBody("direct:start", "This is a test message");
Hope this resolves your issue.
I know this a very old question. But writing this for anyone who're still getting this kind of issue.
Scenario: During the process of a http GET method call, I am fetching some data from DB in the middle of the process and putting the data as message on to an artemis producer.
Firstly, if you're using camel with spring - you don't need to create any camel context at all. Because spring is smart enough to create camel context for you with below dependencies.
Few necessary dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-artemis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>2.24.2</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jaxb-starter</artifactId>
<version>2.24.2</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>2.24.2</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson-starter</artifactId>
<version>2.24.2</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.24.2</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-amqp</artifactId>
<version>2.24.2</version>
</dependency>
So to fix it, I created a class that extends RouteBuilder class from camel library. In this builder, I created a dummy consumer and used it to send message to an actual producer. My destination is an artemis producer endpoint.
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jackson.JacksonDataFormat;
import org.apache.camel.spi.DataFormat;
import org.springframework.stereotype.Component;
#Component
public class MyRouteBuilder extends RouteBuilder {
private DataFormat marshalDataFormat;
public MyRouteBuilder(ObjectMapper objectMapper) {
objectMapper.registerModule(new JavaTimeModule());
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
marshalDataFormat = new JacksonDataFormat(objectMapper, MyClass.class);
}
#Override
public void configure() throws Exception {
from("direct:imaginary-consumer")
.marshal(marshalDataFormat)
.log(LoggingLevel.INFO, "Message ready to send is ${body}")
.to("producer:message-data")
.log(LoggingLevel.INFO, "Message has been sent successfully to topic.");
}
}
Below snippet is in any implementation class that carries the message body. This method takes message data and send it to the imaginary/dummy consumer we created in MyRouteBuilder class. The router class gets invoked and sends the message to the destination (producer here). It can be to http endpoints as well.
#Autowired
private ProducerTemplate producerTemplate;
public void sendMessage(Map<String, MyClass> messageBody) {
producerTemplate.sendBody("direct:imaginary-consumer", messageBody);
}
This is also posted on the Apache Camel mailing list, where its active being discussed.
http://camel.465427.n5.nabble.com/ProducerTemplate-and-direct-start-in-camel-tp5730558.html

NullPointerException in InitialContext

NullPointerException in InitialContext
private void connect() {
try {
InitialContext ctx = new InitialContext();
IServerBean serverBean = (IServerBean)ctx.
lookup("java:global/applicationserver/ServerBean!
com.test.applicationserver.IServerBean");
} catch (NamingException e) {
logger.error(e.getMessage(), e);
}
}
I got this exception when try to execute client application through console java -cp cleint-0.0.1-SNAPSHOT-jar-with-dependencies.jar com.test.client.EJBClient:
java.lang.NullPointerException
at com.sun.enterprise.naming.impl.SerialContext.<init>(SerialContext.java:276)
at com.sun.enterprise.naming.impl.SerialContext.<init>(SerialContext.java:335)
at com.sun.enterprise.naming.impl.SerialInitContextFactory.createInitialContext
(SerialInitContextFactory.java:358)
at com.sun.enterprise.naming.impl.SerialInitContextFactory.getInitialContext
(SerialInitContextFactory.java:353)
at com.sun.enterprise.naming.SerialInitContextFactory.getInitialContext
(SerialInitContextFactory.java:69)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at com.test.client.EJBClient.connect(EJBClient.java:33)
at com.test.client.EJBClient.main(EJBClient.java:61)
This application connecting to remote EJB module.
But when I try to execute it in Eclipse, all's gone fine.
My configuration:
Java SE 1.7
GlassFish Server Open Source Edition 3.1.2.2 (build 5)
Eclipse Java EE IDE for Web Developers. Version: Juno Service Release
1 Build id: 20121004-1855
Maven dependencies:
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.4.2</version>
<scope>system</scope>
<systemPath>C:\Java\jdk1.7.0_11\lib\tools.jar</systemPath>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>javaee</artifactId>
<version>3.1.2.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.appclient</groupId>
<artifactId>gf-client</artifactId>
<version>3.1.1</version>
</dependency>
</dependencies>
I had the same problem.
Resolved :
You must add gf-client.jar and appserv-rt.jar not only in classpath of your project but also in runtime (With Eclipse, See Run As > Run configurations > Classpath > Add jars ) .
I solved this problem with this solution:
Adding this libraries to folder with application:
glassfish-embedded-all-3.1.1.jar hk2-core-1.6.9.jar
internal-api-3.1.2.2.jar
common-util-3.1.2.2.jar
glassfish-corba-internal-api-3.2.0-b005.jar
glassfish-naming-3.1.2.2.jar
And when running application, add this libraries to classpath:
java -cp glassfish-embedded.jar;hk2-core.jar;internal-api.jar;common-util.jar;glassfish-corba-internal-api.jar;glassfish-naming.jar;cleintconsole-0.0.1-SNAPSHOT-jar-with-dependencies.jar com.test.client.EJBClient