I have the following config in my /users//settings.xml.
Under PluginsGroup:
<pluginGroup>org.apache.tomcat.maven</pluginGroup>
Under servers:
<server>
<id>localhost</id>
<username>tom</username>
<password>cat</password>
</server>
Under profiles:
<plugin>
<configuration>
<server>localhost</server>
<url>http://localhost:8080/manager/text</url>
<path>/</path>
</configuration>
</plugin>
I ran the maven command with -X options, and I see the following:
[DEBUG] Reading global settings from C:\Tools\apache-maven-3.1.1\bin\..\conf\settings.xml
[DEBUG] Reading user settings from C:\Users\<user>\.m2\settings.xml
I have the manager-script role in tomcat users xml file.
When I manually verify the access through browser, it works fine. But when I run mvn tomcat7:deploy I get the following:
Receiving response: HTTP/1.1 401 Unauthorized
User name and password are correct. I verified it manually. What else could be wrong?
Googling did not help much.
Edit: More details from Log.
HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
Cache-Control: private
Expires: Wed, 31 Dec 1969 18:00:00 CST
WWW-Authenticate: Basic realm="Tomcat Manager Application"
Set-Cookie: JSESSIONID=7320C7326C51E8F7FF9F4D23A39E6971; Path=/manager/; HttpOnly
Content-Type: text/html;charset=ISO-8859-1
Transfer-Encoding: chunked
Date: Thu, 24 Apr 2014 02:56:27 GMT
Cookie accepted: "[version: 0][name: JSESSIONID][value: 7320C7326C51E8F7FF9F4D23A39E6971]
[domain: localhost][path: /manager/][expiry: null]".
Connection can be kept alive indefinitely
Authentication required
localhost:8080 requested authentication
Authorization challenge processed
Authentication failed
Clearing cached auth scheme for http://localhost:8080
Edit:
Well, this is what I found out. When I pass username and password from mvn command, its working fine. But its not picking up from settings.xml.
Does it ring any bell? I tried moving the config stuff to MAVEN_HOME/config/settings.xml as well. (Deleted the user settings.xml). But still the same.
Any settings cache?
Edit:
I turned on the debugger with -X. Even though I deleted /user/.m2/settings.xml, it says its reading that file.
[DEBUG] Reading global settings from C:\Tools\apache-maven-3.1.1\bin\..\conf\settings.xml
[DEBUG] Reading user settings from C:\Users\<user>\.m2\settings.xml
How to flush?
The pluging configuration should be like that:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<server>text</server>
<url>http://localhost:8080/manager/text</url>
</configuration>
</plugin>
This should work
I am guessing that the application you want to deploy is named text. If it is not replace text with your web application name.
Also I would try removing the last <path>/</path> element to see if this helps or not...
Related
How to add custom metrics to /info endpoint in Spring Actuator 2.7.0?
Currently have the following related to actuator.
I have verified that info.app.version can retrieve the proper value from pom.xml using #Value.
pom.xml
<version>0.0.1-SNAPSHOT</version>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.7.0</version>
</dependency>
application.properties
info.app.version=#project.version#
management.endpoint.info.enabled=true
management.endpoints.web.exposure.include=info,health
But despite this I am only getting an empty response on /info.
Response header:
< HTTP/1.1 200
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: application/vnd.spring-boot.actuator.v3+json
< Transfer-Encoding: chunked
< Date: Wed, 15 Jun 2022 04:12:47 GMT
* Received 7 B chunk
* Received 5 B chunk
* Connection #26 to host localhost left intact
Response body :
{}
My understanding is any property under info is included in /info endpoint. Or does this not work on actuator v2+ ?
Source
From the Spring-Boot 2.6 release notes https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.6-Release-Notes#actuator-env-infocontributor-disabled-by-default
You need to enable the info env property:
management.info.env.enabled=true
Latest spring boot requires two things to be set up:
1- exposing the endpoint in application.properties file:
management.endpoints.web.exposure.include=info, health
You can use a wildcard and expose all endpoints if you want
management.endpoints.web.exposure.include=*
2- enabling info.env in application.properties:
management.info.env.enabled=true
I am trying to publish third-party private package directly to my Azure Artifacts feed with mvn deploy:deploy-file command like this:
mvn deploy:deploy-file -Dpackaging="jar" -DrepositoryId="PXXXXX-inccoming" -Durl="https://pkgs.dev.azure.com/XxxXxxxXxxx/XxxXxx/_packaging/PXXXXX-incoming/maven/v1" -DgroupId="pl.group.id" -DartifactId="artifact" -Dversion="0.0.2" -Dfile="C:\path\pl\group\id\0.0.2\artifact-0.0.2.jar"
But I am getting strange error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project CAST_2015: Failed to deploy artifacts: Could not transfer artifact pl.group.id:artifact:jar:0.0.2 from/to PXXXXX-inccoming (https://pkgs.dev.azure.com/XxxXxxxXxxx/XxxXxx/_packaging/PXXXXX-incoming/maven/v1): Transfer failed for https://pkgs.dev.azure.com/XxxXxxxXxxx/XxxXxx/_packaging/PXXXXX-incoming/maven/v1/pl/group/id/artifact/0.0.2/artifact-0.0.2.jar 401 Unauthorized ProxyInfo{host='proxy-host', userName='null', port=8080, type='http', nonProxyHosts='null'}
The provided user has full access for packaging in Azure.
Both proxy and server settings are actually in my setting.xml file.
What am I doing wrong?
Azure Artifacts deploy packages
When we receiving a 401 it is because maven is sending the wrong login credentials, or no credentials at all.
To resolve this issue, please add the following configuration to the <servers>...</servers> configuration node in the maven setting configuration file:
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
Note:
The id configured in setting.xml must be the same as the id
configured in pom.xml.
If you try to publish something to a releases repository and that
version already exists in the repository
If it not work for you, please check below thread for some more details:
Why am I getting a "401 Unauthorized" error in Maven?
I am using Maven Jib plugin to deploy my application to Gitlab docker registry. If I use docker login registry.gitlab.com and enter username and password I can log in to the gitlab registry successfully. I can see that ~/.docker/config.json contains the following information:
{
"auths": {
"https://registry.gitlab.com": {},
"registry.gitlab.com": {}
},
"HttpHeaders": {
"User-Agent": "Docker-Client/19.03.2 (darwin)"
},
"credsStore": "desktop",
"stackOrchestrator": "swarm"
}
Now if I try to run mvn -Djib.to.auth.username=${username} -Djib.to.auth.password=${password} compile jib:build it fails with the 401 Unauthorized exception. The reason I need to pass the username and password is I would like to run this command in my CICD pipeline and it is required to pass the username and password somehow. I have tested other approaches like setting credentials in the .m2/settings.xml or pom.xml. None of them works.
You can have the credential in the jib plugin section as follows
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<from>
<image>openjdk:8u171-alpine</image>
</from>
<to>
<image>registry.gitlab.com/${project.build.finalName}:${project.version}</image>
<auth>
<username>${jib.username}</username>
<password>${jib.password}</password>
</auth>
</to>
</configuration>
</plugin>
<plugins>
<build>
Have the jib.username and jib.password as properties in settings.xml.
Note: Adjust the from image as to you need.
I'm trying to deploy artifacts to a protected by Basic Auth repository.
I specify
<distributionManagement>
<repository>
<id>some.repo</id>
<name>Some Repository</name>
<url>https://foo.bar</url>
</repository>
</distributionManagement>
in pom.xml
And
<servers>
<server>
<id>some.repo</id>
<username>user</username>
<password>{encoded password}</password>
</server>
</servers>
in settings.xml
But when I run mvn deploy it fails with the error: Not authorized , ReasonPhrase:. -> [Help 1]
If I use
<server>
<id>some.repo</id>
<configuration>
<httpHeaders>
<property>
<name>Authorization</name>
<value>Basic (hash)</value>
</property>
</httpHeaders>
</configuration>
</server>
instead - it works.
After inspection with Wireshark I discovered that in the first scenario (with login/password) Maven doesn't add Authorization header to the HTTP request.
Is it correct behavior? Am I missing something in the configuration?
Well, in this case, it was not Maven, but the server-side problem: server was not sending Connection: keep-alive header. With this header, the authorization flow works.
maven will only send username/password on requests where server responds with a
status code:401
header: WWW-Authenticate: Basic.
Im trying to set up a cgi script for my RMI webserver, but it is giving me an HTTP 500 all the time.
My CGI script look like this.
# This class will support a QUERY_STRING of the form "forward=<port>"
# with a REQUEST_METHOD "POST". The body of the request will be
# forwarded (as another POST request) to the server listening on the
# specified port (must be >= 1024). The response from this forwarded
# request will be the response to the original request.
#
# CONFIGURATION:
#
# Fill in correct absolute path to Java interpreter below. For example,
# the "PATH=" line might be changed to the follow if the JDK is installed
# at the path "/home/peter/java":
#
# PATH=/home/peter/java/bin:$PATH
#
PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
exec java \
-DAUTH_TYPE="$AUTH_TYPE" \
-DCONTENT_LENGTH="$CONTENT_LENGTH" \
-DCONTENT_TYPE="$CONTENT_TYPE" \
-DGATEWAY_INTERFACE="$GATEWAY_INTERFACE" \
-DHTTP_ACCEPT="$HTTP_ACCEPT" \
-DPATH_INFO="$PATH_INFO" \
-DPATH_TRANSLATED="$PATH_TRANSLATED" \
-DQUERY_STRING="$QUERY_STRING" \
-DREMOTE_ADDR="$REMOTE_ADDR" \
-DREMOTE_HOST="$REMOTE_HOST" \
-DREMOTE_IDENT="$REMOTE_IDENT" \
-DREMOTE_USER="$REMOTE_USER" \
-DREQUEST_METHOD="$REQUEST_METHOD" \
-DSCRIPT_NAME="$SCRIPT_NAME" \
-DSERVER_NAME="$SERVER_NAME" \
-DSERVER_PORT="$SERVER_PORT" \
-DSERVER_PROTOCOL="$SERVER_PROTOCOL" \
-DSERVER_SOFTWARE="$SERVER_SOFTWARE" \
sun.rmi.transport.proxy.CGIHandler
In my access.log it says:
"POST /cgi-bin/java-rmi.cgi?forward=1099 HTTP/1.1" 500 415 "-" "Java/1.7.0"
In my error.log it says:
(104)Connection reset by peer: ap_content_length_filter: apr_bucket_read() failed
I am using RMISocketFactory.setSocketFactory(new sun.rmi.transport.proxy.RMIHttpToCGISocketFactory()); to force Http-to-cgi.
I can't figure out what i'm doing wrong..
I have put my java-rmi.cgi file in /usr/lib/cgi-bin/
Am i suppose to add something else to the script?
The java error i get is:
java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:
java.io.IOException: HTTP request failed
EDIT: Visiting my cgi script as a website it give me(maybe you can't do that):
Java RMI Client Error
invalid command.
I traced this into the CGICommandHandler.java and it returns invalid command when the handler is null.
This is the debug output when i run bash -x:
+ PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
+ exec java -DAUTH_TYPE= -DCONTENT_LENGTH= -DCONTENT_TYPE= -DGATEWAY_INTERFACE= -DHTTP_ACCEPT= -DPATH_INFO= -DPATH_TRANSLATED= -DQUERY_STRING= -DREM OTE_ADDR= -DREMOTE_HOST= -DREMOTE_IDENT= -DREMOTE_USER= -DREQUEST_METHOD= -DSCRIPT_NAME= -DSERVER_NAME= -DSERVER_PORT= -DSERVER_PROTOCOL= -DSERVER_S OFTWARE= sun.rmi.transport.proxy.CGIHandler
Status: 400 Bad Request: invalid command.
Content-type: text/html
<HTML><HEAD><TITLE>Java RMI Client Error</TITLE></HEAD><BODY>
<H1>Java RMI Client Error</H1>
invalid command.
</BODY></HTML>
And if i echo out my cgi i file i get this:
AUTH_TYPE=
CONTENT_LENGTH=
CONTENT_TYPE=
GATEWAY_INTERFACE=CGI/1.1 HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 PATH_INFO=
PATH_TRANSLATED=
QUERY_STRING=
REMOTE_ADDR=xx.xxx.x.xx
REMOTE_HOST=
REMOTE_IDENT=
REMOTE_IDENT REMOTE_USER=
REQUEST_METHOD=GET SCRIPT_NAME=/cgi-bin/java-rmi.cgi.sh
SERVER_NAME=xx.xxx.xxx.xxx
SERVER_PORT=80 SERVER_PROTOCOL=HTTP/1.1
SERVER_SOFTWARE=Apache/2.2.22 (Ubuntu) Status: 400 Bad Request: invalid command. Content-type: text/html
As you can see my many strings are empty...
EDIT 2: Now my acess log brings me this:
"POST http://xx.xxx.xxx.xxx/cgi-bin/java-rmi.cgi?forward=1099 HTTP/1.1" 500 415 "-" "Java/1.7.0"
Still HTTP 500, my error log gives my the same as before..
EDIT 3:
I now tried to implement the servlet of java-rmi.cgi and it's giving me errors.
My http.conf lookes like this:
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_ajp_module /usr/lib/apache2/modules/mod_proxy_ajp.so
<Location /cgi-bin/java-rmi.cgi>
ProxyPass ajp://localhost:8009/rmi/ServletHandler
</Location>
What should be the port and adress? In the guide it says localhost:8009(https://forums.oracle.com/message/4804030).
This is where i've placed ServletHandler.class:
/var/lib/tomcat7/webapps/rmi/WEB_INF/classes
My web.xml(inside WEB_INF) looks like this:
<servlet>
<servlet-name>ServletHandler</servlet-name>
<servlet-class>ServletHandler</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletHandler</servlet-name>
<url-pattern>/ServletHandler</url-pattern>
</servlet-mapping>
I've installed tomcat 7 properly.
My access log gives me the same but my error log now gives me(with localhost:8009 set in httpd.conf):
[Fri Nov 15 08:16:26 2013] [error] [client 127.0.0.1] Invalid method in request \x124\x01\xb2\x02\x02
[Fri Nov 15 08:16:26 2013] [error] ajp_check_msg_header() got bad signature 3c21
[Fri Nov 15 08:16:26 2013] [error] ajp_ilink_receive() received bad header
[Fri Nov 15 08:16:26 2013] [error] ajp_read_header: ajp_ilink_receive failed
[Fri Nov 15 08:16:26 2013] [error] (120007)APR does not understand this error code: proxy: read response failed from (null) (localhost)
Error log when setting my global ip and port 80 in http.conf:
[Fri Nov 15 08:13:26 2013] [error] [client xx.xxx.xxx.xxx] Invalid method in request \x124\x01\xb2\x02\x02
[Fri Nov 15 08:13:26 2013] [error] ajp_check_msg_header() got bad signature 3c21
[Fri Nov 15 08:13:26 2013] [error] ajp_ilink_receive() received bad header
[Fri Nov 15 08:13:26 2013] [error] ajp_read_header: ajp_ilink_receive failed
[Fri Nov 15 08:13:26 2013] [error] (120007)APR does not understand this error code: proxy: read response failed from (null) (xx.xxx.xxx.xxx)
EDIT 4:
Now it lookes like this:
web.xml:
<servlet>
<servlet-name>ServletHandler</servlet-name>
<servlet-class>rmiservlethandler.ServletHandler</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletHandler</servlet-name>
<url-pattern>/ServletHandler</url-pattern>
</servlet-mapping>
httpd.conf:
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_ajp_module /usr/lib/apache2/modules/mod_proxy_ajp.so
<Location /cgi-bin/java-rmi.cgi>
ProxyPass ajp://xx.xxx.xxx.xxx:8009/rmi/ServletHandler
</Location>
I tried localhost:8009 but that gives me error, entering my servers global adress makes my webserver to halt, HTTP 503. Stop responding.
My error log for localhost:
[Fri Nov 15 12:20:53 2013] [error] (111)Connection refused: proxy: AJP: attempt to connect to 127.0.0.1:8009 (localhost) failed
[Fri Nov 15 12:20:53 2013] [error] ap_proxy_connect_backend disabling worker for (localhost)
[Fri Nov 15 12:20:53 2013] [error] proxy: AJP: failed to make connection to backend: localhost
error log for global ip:
[Fri Nov 15 12:37:23 2013] [error] (110)Connection timed out: proxy: AJP: attempt to connect to xx.xxx.xxx.xxx:8009 (xx.xxx.xxx.xxx) failed
[Fri Nov 15 12:37:23 2013] [error] ap_proxy_connect_backend disabling worker for (xx.xxx.xxx.xxx)
[Fri Nov 15 12:37:23 2013] [error] proxy: AJP: failed to make connection to backend: xx.xxx.xxx.xxx
Tomcatlog gives me this:
My tomcatlog gives me this:
xx.xxx.x.xx - - [15/Nov/2013:13:32:14 +0000] "POST /rmi/ServletHandler?forward=1099 HTTP/1.1" 404 987
EDIT 5.
Didn't work, i get 404 for /rmi/ServletHandler.
Here is my httpd.conf(taking away .cgi):
<Location /cgi-bin/java-rmi> ProxyPass ajp://localhost:8009/rmi/ServletHandler </Location>
This is web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app> <servlet>
<servlet-name>ServletHandler</servlet-name>
<servlet-class>rmiservlethandler.ServletHandler</servlet-class>
<load-on-startup>1</load-on-startup> </servlet>
<servlet-mapping> <servlet-name>ServletHandler</servlet-name>
<url-pattern>/ServletHandler</url-pattern>
</servlet-mapping>
</web-app>
The folder setup is now:
/var/lib/tomcat7/webapps/rmi/WEB_INF.
WEB_INF contains web.xml and classes/rmiservlethandler/ where rmiservlethandler is where all my class files are(package structure).
Why isn't this working?
My /usr/lib/cgi-bin/ is empty that is should be right?
My servlet dosen't run...
Thanks!
Solved it!
My folder setup were correct(except WEB-INF instead of WEB_INF), the problem was that my localhost adress in ServletHandler wasn't resolved properly(my localhost name wasn't localhost..).
Other things like WEB_INF should be WEB-INF...
Following this gave my exceptions in tomcat catalina.out and local host log files.
So if you think your servlet is running properly, look there for exceptions. I modified my ServletHandler with logs so i could se everything that was going on.
This is what my POST from the client looks now inside tomcat logs:
xx.xxx.x.xx - - [18/Nov/2013:13:17:23 +0000] "POST /rmi/ServletHandler?forward=1099 HTTP/1.1" 200 1
My http.conf:
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_ajp_module /usr/lib/apache2/modules/mod_proxy_ajp.so
<Location /cgi-bin/java-rmi.cgi>
ProxyPass ajp://localhost:8009/rmi/ServletHandler
</Location>
My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
<servlet-name>ServletHandler</servlet-name>
<servlet-class>com.foo.bl.server.ServletHandler</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletHandler</servlet-name>
<url-pattern>/ServletHandler</url-pattern>
</servlet-mapping>
</web-app>
Folder structure:
/var/lib/tomcat7/webapps/rmi/WEB-INF/classes/
Inside classes you put the same folder structure you have in your java IDE.
Web.xml should be placed inside WEB-INF.
Any lib files needed should be placed in WEB-INF/lib.
Hope it helps someone out there!
Regards Gustav