Transport dt_socket 8787 already in use - java

I am trying to run a Server and Client application in Jetty server on my Ubuntu 12.04 machine. The server starts without any problem and I used the following command
$ mvn jetty:run
on issuing this command the first line was
Listening for transport dt_socket at address: 8787
But when I launched the client I got the following error
ERROR: transport error 202: bind failed: Address already in use
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:690]
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
Aborted
Looks something to do with transport dt_socket. I have no understanding what it is and how to use another address for Client?
Edit 1
jetty-maven-plugin from pom.xml for client looks like this
<build>
<plugins>
<!-- Specific jetty-maven-plugin configuration for running Jetty during
development. None of its goals are run in a normal build lifecycle. -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-maven-plugin.version}</version>
<configuration>
<webAppConfig>
<contextPath>/</contextPath>
<extraClasspath>${basedir}/src/test/resources/</extraClasspath>
</webAppConfig>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>${servlet.port}</port>
<host>0.0.0.0</host>
</connector>
</connectors>
<reload>manual</reload>
<useTestClasspath>true</useTestClasspath>
</configuration>
</plugin>
</plugins>
</build>
My assumption is some Jetty is starting in debug mode and trying to attach the debugger at port 8787 which is already bound to debugger of Server.

Jetty does NOT automatically starts the debugger. You most likely have set the MAVEN_OPTS environment variable to include -Xdebug parameters. Check with 'echo $MAVEN_OPTS' and you will see something like:
-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
You can't run two maven processes which both try to debug on port 8787. So change your global MAVEN_OPTS (in .bash_profile when running on osx) or change your MAVEN_OPTS for your second terminal session:
export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=512M"

Enter the below command in terminal / command prompt
killall -9 java
It will kill all the java processes. You will be able to use the port then.

Try this configuration inside jetty plugin
<configuration>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>9090</port>
</connector>
</connectors>
</configuration>
Or alternatively, run jetty from command line this way
mvn -Djetty.port=9090 jetty:run

Related

Wildfly Maven Plugin - commands seem to have no effect

I am using the Wildfly Maven Plugin and it is working, in that it turns on, runs web application, however I am having trouble with my custom configurations, namely:
Setting the Root logger and Console logger to debug mode
Allowing connections from 0.0.0.0:8080 or something other than localhost.
Here is my set up:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.0.2.Final</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<java-opts>
<java-opt>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044</java-opt>
</java-opts>
<commands>
<!-- **These are the commands that aren't going through** -->
<command>/subsystem=logging/root-logger=ROOT:write-attribute(name="level", value="DEBUG") </command>
<command>/subsystem=logging/console-handler=CONSOLE:write-attribute(name="level", value="DEBUG")</command>
<command>/subsystem=logging/file-handler=debug:add(level=DEBUG,autoflush=true,file={"relative-to"=>"jboss.server.log.dir", "path"=>"debug.log"})</command>
<command>/subsystem=logging/logger=org.jboss.as:add(level=DEBUG,handlers=[debug])</command>
<command>/subsystem-----Enable Remote access here?</command>
</commands>
<add-user>
<users>
<user>
<username>admin</username>
<password>admin.1234</password>
</user>
<user>
<username>admin-user</username>
<password>user.1234</password>
<groups>
<group>admin</group>
<group>user</group>
</groups>
<application-user>true</application-user>
</user>
<user>
<username>default-user</username>
<password>user.1234</password>
<groups>
<group>user</group>
</groups>
<application-user>true</application-user>
</user>
</users>
</add-user>
</configuration>
</plugin>
I know when starting from terminal, one would use this: ./standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0 However I am running demos straight from Maven and need to access my webapp from a separate machine.
Note - from within the Wildfly Management page, I can manually set the Root Logger and Console Logger to debug mode and then the proper debug logs will flow out.
For example, manually I could go here: http://127.0.0.1:9990/console/index.html#logging-configuration and then manually change the logging from the default INFO level to DEBUG:
So my question is, along with allowing remote access, is how to change the logging level as a command into the maven wildfly plugin.
You'd need to upgrade the plugin version to 2.1.0.Beta1 to get that to work. The 2.0.x versions do no have the ability to execute CLI commands from the run or deploy goals.
If you need to stick with the version you're using you'd need to define the execute-commands goal. Then you could use the embedded server to configure the server.
<commands>
<!-- **These are the commands that aren't going through** -->
<command>embed-server</command>
<command>/subsystem=logging/root-logger=ROOT:write-attribute(name="level", value="DEBUG") </command>
<command>/subsystem=logging/console-handler=CONSOLE:write-attribute(name="level", value="DEBUG")</command>
<command>/subsystem=logging/file-handler=debug:add(level=DEBUG,autoflush=true,file={"relative-to"=>"jboss.server.log.dir", "path"=>"debug.log"})</command>
<command>/subsystem=logging/logger=org.jboss.as:add(level=DEBUG,handlers=[debug])</command>
<command>/subsystem-----Enable Remote access here?</command>
<command>stop-embedded-server</command>
</commands>

How can I set a custom SSLSocketFactory on a Heroku app?

I'd like to control which public IP addresses my app can connect to, so that I can blacklist a small set of IPs for outgoing connections for the entire app.
Deploying a Tomcat Java app to Heroku, I've specified a custom Java security configuration by overriding "java.security.properties"
web: java $JAVA_OPTS -Djava.security.properties=java.security -jar target/dependency/webapp-runner.jar --port $PORT target/*.war
In that config, I've given a custom SSLSocketFactory class
ssl.SocketFactory.provider=security.MyCustomSocketFactory
This allows MyCustomSocketFactory to examine every IP address and host for outgoing connections in a small sample app. However, it's not working for my full application after I deploy to Heroku. The class isn't found, even though it is packaged into the .war file.
Caused by: java.lang.ClassNotFoundException: security.MyCustomSocketFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
at java.base/javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:105)
at java.base/javax.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory(HttpsURLConnection.java:335)
at java.base/javax.net.ssl.HttpsURLConnection.<init>(HttpsURLConnection.java:292)
I think I have to specify that my single class is class-loaded differently, because my application is initialized by webapp-runner.jar. Is there a different approach I should be taking?
I know my class is available to some classloader, because I can call Class.forName() from my own code, without getting an exception. But it's just not able to be loaded from SSLSocketFactory.getDefault().
As codefinger suggested in a comment, I needed to include MyCustomSocketFactory on the classpath outside of the war file.
I moved MyCustomSocketFactory to a separate Maven project, and built it as a separate jar.
Then, I added a built step on my main project to copy the JAR into the same directory as webapp-runner.jar.
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-socketblocker</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/dependency</outputDirectory>
<resources>
<resource>
<directory>jars</directory>
<includes>socketblocker-1.0.jar</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Finally, I modified my Procfile to use wildcard matching, and add both webapp-runner.jar and my custom JAR as classpath entries.
web: java $JAVA_OPTS -Djava.security.properties=java.security -cp "target/dependency/*" webapp.runner.launch.Main --port $PORT target/*.war

Windows 7, JDK 1.8, Spring Boot application JAR takes up lot of time for method Security.getProviders() to return

I am executing a Spring Boot application which takes up lot of time to create a SSL context.
Initial debugging points to method Security.getProviders() not returning the list of providers for around 8 minutes.
Provider[] providers = Security.getProviders();
This happens when I execute the JAR using below command on command prompt. But it does not take time when executed as Java Application via Eclipse of STS.
"Command to run Application"
java -DkeystoreFile=<Certificate File Name> -DkeystorePassword=<Password> -jar aws-sqs-consumer-0.0.1-SNAPSHOT.jar <QueueName> localhost false <proxy IP> <proxy Port>
Maven Pom.xml, uses spring boot maven plugin to build the application:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

Can I redeploy to remote Tomcat instance and start local testing instance

I'd like to start a new local Tomcat instance for testing purposes during the Maven's pre-integration-test phase (on different port) and run tests there. Then if the tests pass I'd like to do a cargo:redeploy to a remote Tomcat instance. I'm having issues with getting this right though. If I do
mvn org.codehaus.cargo:cargo-maven2-plugin:run -Dcargo.maven.containerId=tomcat8x -Dcargo.maven.containerUrl=https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.36/bin/apache-tomcat-8.0.36.zip -Dcargo.maven.type=standalone
I get
[ERROR] Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.4.19:run (default-cli) on project atf-relay-server: Execution default-cli of goal org.co
dehaus.cargo:cargo-maven2-plugin:1.4.19:run failed: Cannot create configuration. There's no registered configuration for the parameters (container [id = [tomcat
8x], type = [installed]], configuration type [runtime]). Valid types for this configuration are:
[ERROR] - standalone
[ERROR] - existing
[ERROR] -> [Help 1]
My pom.xml for cargo is (specifying only remote instance):
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.19</version>
<configuration>
<container>
<containerId>tomcat8x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.hostname>localhost</cargo.hostname>
<cargo.servlet.port>9990</cargo.servlet.port>
<cargo.remote.username>user</cargo.remote.username>
<cargo.remote.password>pass</cargo.remote.password>
</properties>
</configuration>
<deployer>
<type>remote</type>
</deployer>
</configuration>
</plugin>
What's the correct way to achieve this?
Ok, seems it's quite easy to achieve after getting familiar with Maven profiles.
I have now one profile controlling remote Tomcat instance and doing the cargo:redeploy and other profile just creating local Tomcat, running it, deploying app there and running the tests.

What is needed to configure Jetty to run Spring MVC application?

I am working on Spring MVC web-abblication and I need it to work on Jetty server (Jetty should be Servlet Cobtainer).
I addded Jetty server to my app by "Edit run configuration".
Edit Run Config
Here are application server settings:
App server settings
But, when I launch my application IDEA gives me this:
"C:\Program Files\Java\jdk1.8.0_65\bin\java" -DSTOP.PORT=0 -Dcom.sun.management.jmxremote= -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -DOPTIONS=jmx -Didea.launcher.port=7535 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 15.0.4\bin" -Dfile.encoding=windows-1251 -classpath "D:\jetty-distribution-9.3.7.v20160115\start.jar;C:\Program Files\Java\jdk1.8.0_65\lib\tools.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 15.0.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.eclipse.jetty.start.Main --module=jmx C:\Windows\Temp\context4config\jetty-contexts.xml
[2016-03-03 07:17:55,511] Artifact DVDExchange:war exploded: Server is not connected. Deploy is not available.
Detected server http port: 8080
java.nio.file.AccessDeniedException: C:\Windows\Temp\context4config\jetty-contexts.xml
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:90)
at sun.nio.fs.WindowsLinkSupport.getRealPath(WindowsLinkSupport.java:259)
at sun.nio.fs.WindowsPath.toRealPath(WindowsPath.java:836)
at sun.nio.fs.WindowsPath.toRealPath(WindowsPath.java:44)
at org.eclipse.jetty.start.FS.toRealPath(FS.java:165)
at org.eclipse.jetty.start.StartArgs.addUniqueXmlFile(StartArgs.java:217)
at org.eclipse.jetty.start.StartArgs.resolveExtraXmls(StartArgs.java:1123)
at org.eclipse.jetty.start.Main.processCommandLine(Main.java:342)
at org.eclipse.jetty.start.Main.main(Main.java:74)
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:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Usage: java -jar start.jar [options] [properties] [configs]
java -jar start.jar --help # for more information
Disconnected from server
Process finished with exit code -9
Maybe one of the reasons is epmpty jetty-web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
</Configure>
But actually how Should I make jetty work with Spring web-app in proper way.
Could someone give complete list if things I have to do. Well structured and detailed tutorial would the best answer. I really need to handle that jetty.
Thanks in advance!
This question would suffice your needs,
Debug web app in IntelliJ, webapp built by maven, run by jetty
You need to add the embedded maven-jetty plugin to your pom.xml and run the maven goals to start the jetty server, mvn jetty:run
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.8.v20121106</version>
<configuration>
<contextPath>/</contextPath>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<!--<port>8085</port>-->
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<stopKey>stop</stopKey>
<stopPort>8089</stopPort>
</configuration>
</plugin>
</plugins>
</build>

Categories