I have a standalone client that I do not want to deploy on my Glassfish server. With the client I want to post message via the Point to Point communication pattern. I found this great tutorial, which uses annotations I cannot use because I have a standalone client. I found the following solution on stackoverflow:
Context jndiContext;
private ConnectionFactory connectionFactory;
private static Queue queue;
public TweetSender() throws NamingException{
jndiContext = new InitialContext();
connectionFactory = (ConnectionFactory) jndiContext.lookup("JMS/KwetterConnectionFactory");
queue = (Queue) jndiContext.lookup("JMS/KwetterQueue");
}
I also found out that I had to import some libraries from the glassfish directory. So I did:
I get the following error:
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.impl.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.impl.SerialInitContextFactory]
What am I doing wrong?
EDIT
I found a temporary solution for the problem though I feel it's not the right one (I think I might get problems when I want to migrate the project. I removed the libraries which I retrieved from the Glassfish lib folder and added them using the "Absolute path".
A solution can be packing your standalone client application in a jar file, eg: myclient.jar.
And run it as an application client using appclient utility of GlassFish:
applcient -client myclient.jar
The appclient utility can be found here: [glassfish home dir]/glassfish/bin.
Related
I have this exception when I lookup jndi datasource from weblogic from spring boot application...only after one successful deployment...I mean from the second deployment on.If I restart the container, it will work fine for the first deployment only.
Caused by: javax.naming.NameNotFoundException: Unable to resolve 'jdbc.payment'. Resolved 'jdbc'; remaining name 'payment'
the datasource with the same name and attached to the admin server.
I use docker image : store/oracle/weblogic:12.2.1.4-dev with environment variable PRODUCTION_MODE=dev
update : if I deattach the data source from the server then reattche it again then start the war, It runs successfully for one time againز
update : switched to local installation of weblogic not dockerized any more and the behavior still happens
It's a spring issue...has nothing to do with weblogic.
In the war shutdown, Spring remove the data source form the server JNDI tree, however the data source still up and running on the server.
The action of recreating or even reattaching the data source to target server, add it again to the JNDI tree.
The workaround to solve this behavior is to prevent spring from calling the destroy method of the data source bean
#Primary
#Bean(name = "dataSource",destroyMethod = "")
#Profile("weblogic")
public DataSource dataSourceWeblogic() throws NamingException {
JndiTemplate jndiTemplate = new JndiTemplate();
InitialContext ctx = (InitialContext) jndiTemplate.getContext();
return (javax.sql.DataSource) ctx.lookup(jndi);
}
I am following this fundamentals of JEE tutorial which provides instruction to create a minimal EJB deployment.
I have gone through the steps in the tutorials but made changes to the following command line invocations
>set CLASSPATH=.;E:\wildfly-10.1.0\wildfly-10.1.0.Final\bin\client\jboss-client.jar; (Changed from the long list in the tutorial)
>jar -cvf SimpleSessionApp.ear beans*.java (Changed file extention to .ear from .ejb3)
copy SimpleSessionApp.ear E:\wildfly-10.1.0\wildfly-10.1.0.Final\standalone\deployments (Copied to the wildfly deployment directory)
I started the server and I did not get any errors. However, I did not get set of standard names the server log outputs when a bean is deployed.
I ran the client application using the following command as in tutorial
>java -D java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -D java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces -D java.naming.provider.url=localhost client.SimpleSessionClient Now is the time for all good men
I get the following error as the output
Error: Could not find or load main class java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
I know the tutorial caters for an older version of Java and JBoss. However, I modified the old references to point to the newer environment as mentioned above. So I assume versioning is not a issue here? BTW I'm just starting to learn EJB. Any insights would be great.
My Environment
Java 1.8.0.212
Wildfly 10.1.0.Final
Notepad
You should look at the reference documentation https://docs.wildfly.org/17/Developer_Guide.html#JNDI_Remote_Reference as it seems your are passing wrong configuration parameters.
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
// the property below is required ONLY if there is no ejb client configuration loaded (such as a
// jboss-ejb-client.properties in the class path) and the context will be used to lookup EJBs
env.put("jboss.naming.client.ejb.context", true);
InitialContext remoteContext = new InitialContext(env);
RemoteCalculator ejb = (RemoteCalculator) remoteContext.lookup("wildfly-http-remoting-ejb/CalculatorBean!"
+ RemoteCalculator.class.getName());
I need desperate help to figure out the reason for the failure in creating the service.
My application is developed using Eclipse tool and it runs well there. It uses cxf-3.1.7 library collection. A console program that initializes the process to create the service to the API. Everything looks good and fine.
I am trying to deploy the code in another machine. I installed the necessary jre and other files. I created a batch file with all the necessary path and classpath settings. I need to run the batch file on a daily base, so that it pulls the data regularly. But, when I run the batch file, it fails to create the service with the above error message.
Can someone suggest me the reason if I am going wrong somewhere or any solution to get the service created. This is the batch file I have:
set path=C:\Program Files\Java\jdk1.8.0_91\bin
set classpath=cxf-core-3.1.7.jar;cxf-rt-frontend-simple-3.1.7.jar;sqljdbc42.jar;cxf-rt-frontend-jaxws-3.1.7.jar;wsdl4j-1.6.3.jar;cxf-rt-wsdl-3.1.7.jar;xmlschema-core-2.2.1.jar;lib*.jar;.
java com.strongmail.services.v2.MailingService_MailingServicePort_Client
pause
Thanks in advance.
I've created java classes from wsdl with org.apache.cxf.tools.wsdlto.WSDLToJava. While creating an instance of the service, I had exact same exception at runtime:
org.apache.cxf.service.factory.ServiceConstructionException: Failed to
create service
Previous code:
URL wsdlURL = new URL("http://example.com/my_service.asmx");
MyWS mailWS = new MyWS(wsdlURL); // Exception is thrown here
Solution was weird. I've just added ?wsdl next to service address:
URL wsdlURL = new URL("http://example.com/my_service.asmx?wsdl");
MyWS mailWS = new MyWS(wsdlURL);
I'm learning how to deploy a web app with Tomcat and SQL Server. I'm using the jTDS driver to connect to MS SQL Server (jtds-1.3.1.jar), but I keep running into errors when I try to create a connection to the database. The program can't seem to find the jTDS driver classes. I know there's been several questions related to this on SE, but none of the solutions seem to work.
First, I'll describe how my project is set up. TOMCAT_HOME refers to the root directory of the Tomcat server. Here's a portion of my Tomcat directory:
TOMCAT_HOME\
-lib\
-jtds-1.3.1.jar
-many other default jar files
-webapps\
-TestSite\
-index.jsp
-login.jsp
-WEB-INF\
-classes\
-com\
-testsite\
-LoginServlet.class
-ConnectionManager.class
-UserDAO.class
-UserBean.class
-lib\
-web.xml
The package for the class files are com.testsite, hence the subdirectories within the classes folder. Reading the Tomcat documentation, placing jar files in the root lib folder will allow all web apps to access them. (I've also tried putting the jar files in the webapps\TestSite\WEB-INF\lib\ directory, but get the same error).
In my web application, I'm registering the jTDS with the DriverManager in one of my classes, which is called from a servlet.:
package com.testsite;
import java.sql.*;
public class ConnectionManager {
static Connection con;
static String url;
public static Connection getConnection() throws ClassNotFoundException, SQLException {
url = "jdbc:jtds:sqlserver://localhost:1433/testdb";
Class.forName("net.sourcefourge.jtds.jdbc.Driver");
con = DriverManager.getConnection(url,"username","password");
return con;
}
}
When I start up the Tomcat server, I'm able to successfully navigate to the starting page, but when I try to login (which calls the getConnection() method), it gives the following error. Why can it not see it in the lib\ folder? How can I fix it?
java.lang.ClassNotFoundException: net.sourcefourge.jtds.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClas
sLoaderBase.java:1305)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClas
sLoaderBase.java:1157)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.trainingsite.ConnectionManager.getConnection(ConnectionManager.ja
va:22)
I realized the error was due to a hard-to-see typo. I originally misspelled sourceforge:
Class.forName("net.sourcefourge.jtds.jdbc.Driver");
It should be:
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Another common typo, apparently, is mixing up jdbc and jbdc in the name.
Everything works as expected after fixing that.
I create web service
#WebService(serviceName = "DynamipsService2")
#Stateless()
public class DynamipsService2 {
#WebMethod(operationName = "StartSession")
public static String StartSession(#WebParam(name = "key") String key) {
try {
return "100-Session started";
} catch (Exception ex) {
return null;
}
}
}
I want to test but on the page
http://localhost:8080/DynamipsService2/DynamipsService2?Tester crash bug
Error generating artifacts for the
following WSDL
http://localhost:8080/DynamipsService2/DynamipsService2?WSDL
Possible causes can be invoking https
when the application is not configured
for security
I created other Web services in the same assembly and it works.
I just experienced this problem as well. The solution for me was to use my hostname rather than localhost in the URL for the Tester.
So in my case, the following, which is what NetBeans/Glassfish did by default when I clicked Test Web Service in the NetBeans UI, did not work:
http://localhost:8080/Calculator/Calculator?Tester
However, when I paste the following into a browser, it does work:
http://david-pc:8080/Calculator/Calculator?Tester
I couldn't figure out how to change the hostname that NetBeans uses for the built-in Test dialog (nor could I cut+paste the URL from the error dialog). So I had to visually copy the URL from the error message into a browser, replacing the hostname along the way.
I had the same problem and the reason apeared in the Server's log. I'm useing Glassfish 3.1 with netBeans 7. And the error I got in the Glassfish output was:
INFO: [ERROR] com.sun.tools.javac.Main is not available in the classpath, requires Suns JDK version 5.0 or latter.
I googled a bit and it appeared to be because the glassfish server was working with the openjdk that came with ubuntu. If your problem is the same the solution I found was to remove the openjdk jre, like this:
sudo apt-get remove openjdk-6-jre
sudo apt-get autoremove
Hope this is useful.
PS: I assigned /usr/lib/jvm/java-6-sun/bin/java in the java tab at the servers configuration wizard in netBeans but don't know if that was part of the solution (I'm afraid to change it back :p)
I had the same problem with Glassfish
but it was more compilcated because of the NAT
I have GF in NAT - do MYDOMAIN and port is redirected to internal machine
the problem in GF is that it tries to connect to itself by the domain name which again redirects to inside network
(the ?wsdl works properly)
I have made temp solution adding to /etc/hosts (127.0.0.1 domainname)
be aware that it's only a temp solution
try to check if you have "localhost" in your hosts file (in windows c:/windows/system32/drivers/etc/hosts )
and ping localhost
I will add GF log - maybe someone in future will search it by google :) :)
moreover I looked GF logs there was something like ->
Connection timed out
Failed to read the WSDL document: http://MYDOMAIN:8080/MYSERVICE?WSDL, because 1) could not find the document; /2) the document could not be read; 3) the root element of the document is not <wsdl:definitions>.
failed.noservice=Could not find wsdl:service in the provided WSDL(s):
At least one WSDL with at least one service definition needs to be provided.
Failed to parse the WSDL.
Which web server do you use? If you use glassfish you can open server admin page and select Configurations===>server-config===>Security
and make Security Manager enabled
Check your domains/{YOUR_DOMAIN}/config/domain.xml
If you setup Glassfish using Eclipse, all will be done for you automatically.
Now I am surprised if I start the domain from the command line, it gave me that error, but starting Glassfish 4 from Eclipse, it is not showing any problem.
One cause could be that you don't have correctly configured the environment variable JAVA_HOME (with the correct path) and the JAVA_HOME/bin directory added to global PATH environment variable as well. For some processes the glassfish look for the classpath of the JDK installed.
Hope this help.
I had the exact same problem and it is because you have a static method, I realised after debugging for some while. Just remove static from the method and it should work.
#WebMethod(operationName = "StartSession")
public String StartSession(#WebParam(name = "key") String key) {
try {
return "100-Session started";
} catch (Exception ex) {
return null;
}
}