StringBuffer msg = new StringBuffer();
msg.append( checkNull( event.getRepositoryId() ) ).append( DELIM );
msg.append( event.getUserId() ).append( DELIM );
- msg.append( event.getRemoteIP() ).append( DELIM );
+ msg.append( checkNull( event.getRemoteIP() ) ).append( DELIM );
msg.append( '\"' ).append( checkNull( event.getResource() ) ).append( '\"' ).append( DELIM );
msg.append( '\"' ).append( event.getAction() ).append( '\"' );
import java.util.List;\r
import java.util.Map;\r
\r
+import javax.servlet.http.HttpServletRequest;\r
+\r
import org.apache.maven.archiva.repository.audit.AuditEvent;\r
import org.apache.maven.archiva.repository.audit.AuditListener;\r
import org.apache.maven.archiva.repository.audit.Auditable;\r
protected void triggerAuditEvent( String repositoryId, String resource, String action )\r
{\r
AuditEvent event = new AuditEvent( repositoryId, getPrincipal(), resource, action );\r
- event.setRemoteIP( ServletActionContext.getRequest().getRemoteAddr() );\r
+ event.setRemoteIP( getRemoteAddr() );\r
\r
for ( AuditListener listener : auditListeners )\r
{\r
protected void triggerAuditEvent( String resource, String action )\r
{\r
AuditEvent event = new AuditEvent( getPrincipal(), resource, action );\r
- event.setRemoteIP( ServletActionContext.getRequest().getRemoteAddr() );\r
+ event.setRemoteIP( getRemoteAddr() );\r
\r
for ( AuditListener listener : auditListeners )\r
{\r
protected void triggerAuditEvent( String action )\r
{\r
AuditEvent event = new AuditEvent( getPrincipal(), action );\r
- event.setRemoteIP( ServletActionContext.getRequest().getRemoteAddr() );\r
+ event.setRemoteIP( getRemoteAddr() );\r
\r
for ( AuditListener listener : auditListeners )\r
{\r
}\r
}\r
\r
+ private String getRemoteAddr()\r
+ {\r
+ HttpServletRequest request = ServletActionContext.getRequest();\r
+ return request != null ? request.getRemoteAddr() : null;\r
+ }\r
+\r
@SuppressWarnings( "unchecked" )\r
protected String getPrincipal()\r
{\r