merge for release 4.13
git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/branches/common/common-smartgears/2.1@176609 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1b60aa2d44
commit
55d3199615
|
@ -1,4 +1,9 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset component="common-smartgears-2.1.7" date="2017-01-16">
|
||||
<Change>Added Proxy Address to Application Configuration</Change>
|
||||
<Change>Added protocol to Container Configuration (http by default)</Change>
|
||||
<Change>Changed the logs in accounting handler to log error or success and eventually error code</Change>
|
||||
</Changeset>
|
||||
<Changeset component="common-smartgears-2.1.5" date="2017-07-18">
|
||||
<Change>Added ThreadLocal InnerMethodName to set method name from application</Change>
|
||||
</Changeset>
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-smartgears</artifactId>
|
||||
<version>2.1.6-SNAPSHOT</version>
|
||||
<version>2.1.7-SNAPSHOT</version>
|
||||
<name>SmartGears</name>
|
||||
|
||||
<dependencyManagement>
|
||||
|
|
|
@ -20,17 +20,7 @@ public interface ApplicationConfiguration {
|
|||
*/
|
||||
Mode mode();
|
||||
|
||||
/**
|
||||
* Returns true if the application is secure (accessible only in https).
|
||||
* @return secure or not
|
||||
*/
|
||||
boolean secure();
|
||||
|
||||
/**
|
||||
* Returns true if the application is behind a proxy.
|
||||
* @return secure or not
|
||||
*/
|
||||
ApplicationConfiguration proxied(boolean proxied);
|
||||
|
||||
/**
|
||||
* Returns the context path of the application
|
||||
|
@ -53,9 +43,7 @@ public interface ApplicationConfiguration {
|
|||
* @return this configuration
|
||||
*/
|
||||
ApplicationConfiguration mode(Mode mode);
|
||||
|
||||
|
||||
ApplicationConfiguration secure(boolean value);
|
||||
|
||||
/**
|
||||
* Returns the name of the application.
|
||||
|
@ -110,6 +98,9 @@ public interface ApplicationConfiguration {
|
|||
*/
|
||||
ApplicationConfiguration description(String description);
|
||||
|
||||
ProxyAddress proxyAddress();
|
||||
|
||||
ApplicationConfiguration proxyAddress(ProxyAddress proxyaddress);
|
||||
|
||||
/**
|
||||
* Returns the tokens in which the application operates when it first starts.
|
||||
|
@ -173,5 +164,4 @@ public interface ApplicationConfiguration {
|
|||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -42,9 +42,6 @@ public class BridgedApplicationConfiguration implements ApplicationConfiguration
|
|||
log.trace("setting persistence location for {} @ {}",application.name(), dir.getAbsolutePath());
|
||||
}
|
||||
|
||||
if (container.proxyAddress()==null)
|
||||
application.proxied(false);
|
||||
|
||||
}
|
||||
|
||||
public ApplicationConfiguration inner() {
|
||||
|
@ -92,6 +89,10 @@ public class BridgedApplicationConfiguration implements ApplicationConfiguration
|
|||
public String description() {
|
||||
return application.description();
|
||||
}
|
||||
|
||||
public ProxyAddress proxyAddress() {
|
||||
return application.proxyAddress();
|
||||
}
|
||||
|
||||
public ApplicationConfiguration description(String description) {
|
||||
return application.description(description);
|
||||
|
@ -130,15 +131,6 @@ public class BridgedApplicationConfiguration implements ApplicationConfiguration
|
|||
application.merge(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean secure() {
|
||||
return application.secure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration secure(boolean value) {
|
||||
return application.secure(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> startTokens() {
|
||||
|
@ -150,10 +142,6 @@ public class BridgedApplicationConfiguration implements ApplicationConfiguration
|
|||
return application.startTokens(tokens);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration proxied(boolean proxied) {
|
||||
return application.proxied(proxied);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean proxied() {
|
||||
|
@ -170,5 +158,10 @@ public class BridgedApplicationConfiguration implements ApplicationConfiguration
|
|||
return application.includes(includes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration proxyAddress(ProxyAddress proxyaddress) {
|
||||
return application.proxyAddress(proxyaddress);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -37,16 +37,10 @@ public class DefaultApplicationConfiguration implements ApplicationConfiguration
|
|||
|
||||
@XmlAttribute
|
||||
private Mode mode = Mode.online;
|
||||
|
||||
@XmlAttribute(name="isSecure")
|
||||
private boolean secure = false;
|
||||
|
||||
@XmlAttribute(name="context")
|
||||
String context;
|
||||
|
||||
@XmlAttribute(name="proxied")
|
||||
private boolean proxied = true;
|
||||
|
||||
|
||||
@XmlElement(name="name" , required=true)
|
||||
@NotNull
|
||||
String name;
|
||||
|
@ -65,6 +59,10 @@ public class DefaultApplicationConfiguration implements ApplicationConfiguration
|
|||
@XmlElement(name="description")
|
||||
String description="";
|
||||
|
||||
@XmlElementRef
|
||||
@IsValid
|
||||
ProxyAddress proxyAddress;
|
||||
|
||||
@XmlElementRef
|
||||
Set<Exclude> excludes= new LinkedHashSet<Exclude>();
|
||||
|
||||
|
@ -79,6 +77,7 @@ public class DefaultApplicationConfiguration implements ApplicationConfiguration
|
|||
public Set<Exclude> excludes() {
|
||||
return excludes;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<Include> includes() {
|
||||
|
@ -91,11 +90,6 @@ public class DefaultApplicationConfiguration implements ApplicationConfiguration
|
|||
public Mode mode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean secure() {
|
||||
return secure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
|
@ -113,6 +107,10 @@ public class DefaultApplicationConfiguration implements ApplicationConfiguration
|
|||
return this;
|
||||
}
|
||||
|
||||
public ProxyAddress proxyAddress() {
|
||||
return proxyAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration excludes(Exclude ... excludes) {
|
||||
this.excludes=new HashSet<Exclude>(Arrays.asList(excludes));
|
||||
|
@ -135,17 +133,7 @@ public class DefaultApplicationConfiguration implements ApplicationConfiguration
|
|||
public String serviceClass() {
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean proxied() {
|
||||
return proxied;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration proxied(boolean proxied) {
|
||||
this.proxied = proxied;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration serviceClass(String group) {
|
||||
|
@ -186,7 +174,10 @@ public class DefaultApplicationConfiguration implements ApplicationConfiguration
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean proxied() {
|
||||
return proxyAddress!=null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Persistence persistence() {
|
||||
|
@ -198,10 +189,10 @@ public class DefaultApplicationConfiguration implements ApplicationConfiguration
|
|||
this.persistenceManager=manager;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration secure(boolean value) {
|
||||
this.secure=value;
|
||||
public ApplicationConfiguration proxyAddress(ProxyAddress proxyaddress) {
|
||||
this.proxyAddress = proxyaddress;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -243,89 +234,4 @@ public class DefaultApplicationConfiguration implements ApplicationConfiguration
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DefaultApplicationConfiguration [mode=" + mode + ", secure="
|
||||
+ secure + ", context=" + context + ", proxied=" + proxied
|
||||
+ ", name=" + name + ", group=" + group + ", version="
|
||||
+ version + ", tokens=" + tokens + ", description="
|
||||
+ description + ", excludes=" + excludes
|
||||
+ ", persistenceManager=" + persistenceManager + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((context == null) ? 0 : context.hashCode());
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((excludes == null) ? 0 : excludes.hashCode());
|
||||
result = prime * result + ((group == null) ? 0 : group.hashCode());
|
||||
result = prime * result + ((mode == null) ? 0 : mode.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((persistenceManager == null) ? 0 : persistenceManager.hashCode());
|
||||
result = prime * result + ((tokens == null) ? 0 : tokens.hashCode());
|
||||
result = prime * result + ((version == null) ? 0 : version.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
DefaultApplicationConfiguration other = (DefaultApplicationConfiguration) obj;
|
||||
if (context == null) {
|
||||
if (other.context != null)
|
||||
return false;
|
||||
} else if (!context.equals(other.context))
|
||||
return false;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (excludes == null) {
|
||||
if (other.excludes != null)
|
||||
return false;
|
||||
} else if (!excludes.equals(other.excludes))
|
||||
return false;
|
||||
if (group == null) {
|
||||
if (other.group != null)
|
||||
return false;
|
||||
} else if (!group.equals(other.group))
|
||||
return false;
|
||||
if (mode != other.mode)
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (persistenceManager == null) {
|
||||
if (other.persistenceManager != null)
|
||||
return false;
|
||||
} else if (!persistenceManager.equals(other.persistenceManager))
|
||||
return false;
|
||||
if (tokens == null) {
|
||||
if (other.tokens != null)
|
||||
return false;
|
||||
} else if (!tokens.equals(other.tokens))
|
||||
return false;
|
||||
if (version == null) {
|
||||
if (other.version != null)
|
||||
return false;
|
||||
} else if (!version.equals(other.version))
|
||||
return false;
|
||||
if (secure!=other.secure)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package org.gcube.smartgears.configuration.application;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.gcube.common.validator.annotations.NotNull;
|
||||
|
||||
@XmlRootElement(name="proxy")
|
||||
public class ProxyAddress {
|
||||
|
||||
|
||||
@XmlAttribute
|
||||
String protocol = "http";
|
||||
|
||||
@XmlElement
|
||||
@NotNull
|
||||
String hostname;
|
||||
|
||||
@XmlElement
|
||||
Integer port;
|
||||
|
||||
public String hostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public ProxyAddress hostname(String hostname) {
|
||||
this.hostname = hostname;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer port() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public ProxyAddress port(int port) {
|
||||
this.port = port;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String protocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public ProxyAddress protocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProxyAddress [protocol=" + protocol + ", hostname=" + hostname + ", port=" + port + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((hostname == null) ? 0 : hostname.hashCode());
|
||||
result = prime * result + ((port == null) ? 0 : port.hashCode());
|
||||
result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ProxyAddress other = (ProxyAddress) obj;
|
||||
if (hostname == null) {
|
||||
if (other.hostname != null)
|
||||
return false;
|
||||
} else if (!hostname.equals(other.hostname))
|
||||
return false;
|
||||
if (port == null) {
|
||||
if (other.port != null)
|
||||
return false;
|
||||
} else if (!port.equals(other.port))
|
||||
return false;
|
||||
if (protocol == null) {
|
||||
if (other.protocol != null)
|
||||
return false;
|
||||
} else if (!protocol.equals(other.protocol))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -42,28 +42,25 @@ public class ContainerConfiguration {
|
|||
private Mode mode = Mode.online;
|
||||
|
||||
@XmlElement
|
||||
@NotNull
|
||||
@NotNull @IsValid
|
||||
String hostname;
|
||||
|
||||
@XmlElement
|
||||
@NotNull
|
||||
Integer port;
|
||||
|
||||
@XmlElementRef
|
||||
@IsValid
|
||||
ProxyAddress proxyAddress;
|
||||
|
||||
@XmlElement(name ="authentication-endpoint")
|
||||
String authenticationEnpoint = null;
|
||||
|
||||
@XmlElement(name ="secure-port")
|
||||
Integer securePort;
|
||||
@XmlElement(name ="protocol")
|
||||
@NotNull @IsValid
|
||||
String protocol="http";
|
||||
|
||||
@XmlElement
|
||||
boolean authorizeChildrenContext = false;
|
||||
|
||||
@XmlElement
|
||||
@NotNull
|
||||
@NotNull@IsValid
|
||||
String infrastructure;
|
||||
|
||||
@XmlElement
|
||||
|
@ -186,6 +183,8 @@ public class ContainerConfiguration {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the host name of the container.
|
||||
* @return the host name;
|
||||
|
@ -217,8 +216,8 @@ public class ContainerConfiguration {
|
|||
* Returns the port at which the container is listening for requests.
|
||||
* @return the port
|
||||
*/
|
||||
public Integer securePort() {
|
||||
return securePort;
|
||||
public String protocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
|
||||
|
@ -241,8 +240,8 @@ public class ContainerConfiguration {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ContainerConfiguration securePort(int port) {
|
||||
this.securePort=port;
|
||||
public ContainerConfiguration protocol(String protocol) {
|
||||
this.protocol=protocol;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -276,15 +275,6 @@ public class ContainerConfiguration {
|
|||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProxyAddress proxyAddress() {
|
||||
return proxyAddress;
|
||||
}
|
||||
|
||||
public ContainerConfiguration setProxyaddress(ProxyAddress proxyaddress) {
|
||||
this.proxyAddress = proxyaddress;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the persistence manager of the container.
|
||||
|
@ -420,8 +410,6 @@ public class ContainerConfiguration {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -430,32 +418,18 @@ public class ContainerConfiguration {
|
|||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result
|
||||
+ ((allowedContext == null) ? 0 : allowedContext.hashCode());
|
||||
result = prime * result + ((allowedContext == null) ? 0 : allowedContext.hashCode());
|
||||
result = prime * result + ((apps == null) ? 0 : apps.hashCode());
|
||||
result = prime
|
||||
* result
|
||||
+ ((authenticationEnpoint == null) ? 0 : authenticationEnpoint
|
||||
.hashCode());
|
||||
result = prime * result + ((authenticationEnpoint == null) ? 0 : authenticationEnpoint.hashCode());
|
||||
result = prime * result + (authorizeChildrenContext ? 1231 : 1237);
|
||||
result = prime * result
|
||||
+ ((hostname == null) ? 0 : hostname.hashCode());
|
||||
result = prime * result
|
||||
+ ((infrastructure == null) ? 0 : infrastructure.hashCode());
|
||||
result = prime * result + ((hostname == null) ? 0 : hostname.hashCode());
|
||||
result = prime * result + ((infrastructure == null) ? 0 : infrastructure.hashCode());
|
||||
result = prime * result + ((mode == null) ? 0 : mode.hashCode());
|
||||
result = prime
|
||||
* result
|
||||
+ ((persistenceManager == null) ? 0 : persistenceManager
|
||||
.hashCode());
|
||||
result = prime * result + ((persistenceManager == null) ? 0 : persistenceManager.hashCode());
|
||||
result = prime * result + ((port == null) ? 0 : port.hashCode());
|
||||
result = prime * result
|
||||
+ ((properties == null) ? 0 : properties.hashCode());
|
||||
result = prime * result
|
||||
+ ((proxyAddress == null) ? 0 : proxyAddress.hashCode());
|
||||
result = prime * result
|
||||
+ (int) (publicationFrequency ^ (publicationFrequency >>> 32));
|
||||
result = prime * result
|
||||
+ ((securePort == null) ? 0 : securePort.hashCode());
|
||||
result = prime * result + ((properties == null) ? 0 : properties.hashCode());
|
||||
result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
|
||||
result = prime * result + (int) (publicationFrequency ^ (publicationFrequency >>> 32));
|
||||
result = prime * result + ((site == null) ? 0 : site.hashCode());
|
||||
result = prime * result + ((tokens == null) ? 0 : tokens.hashCode());
|
||||
return result;
|
||||
|
@ -514,18 +488,13 @@ public class ContainerConfiguration {
|
|||
return false;
|
||||
} else if (!properties.equals(other.properties))
|
||||
return false;
|
||||
if (proxyAddress == null) {
|
||||
if (other.proxyAddress != null)
|
||||
if (protocol == null) {
|
||||
if (other.protocol != null)
|
||||
return false;
|
||||
} else if (!proxyAddress.equals(other.proxyAddress))
|
||||
} else if (!protocol.equals(other.protocol))
|
||||
return false;
|
||||
if (publicationFrequency != other.publicationFrequency)
|
||||
return false;
|
||||
if (securePort == null) {
|
||||
if (other.securePort != null)
|
||||
return false;
|
||||
} else if (!securePort.equals(other.securePort))
|
||||
return false;
|
||||
if (site == null) {
|
||||
if (other.site != null)
|
||||
return false;
|
||||
|
@ -539,7 +508,13 @@ public class ContainerConfiguration {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ContainerConfiguration [mode=" + mode + ", hostname=" + hostname + ", port=" + port + ", authenticationEnpoint=" + authenticationEnpoint + ", protocol=" + protocol
|
||||
+ ", authorizeChildrenContext=" + authorizeChildrenContext + ", infrastructure=" + infrastructure
|
||||
+ ", site=" + site + ", tokens=" + tokens + ", allowedContext=" + allowedContext + ", apps=" + apps
|
||||
+ ", properties=" + properties + ", publicationFrequency=" + publicationFrequency
|
||||
+ ", persistenceManager=" + persistenceManager + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package org.gcube.smartgears.configuration.container;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.gcube.common.validator.annotations.NotNull;
|
||||
|
||||
@XmlRootElement(name="proxy")
|
||||
public class ProxyAddress {
|
||||
|
||||
@XmlAttribute
|
||||
boolean secure = false;
|
||||
|
||||
@XmlElement
|
||||
@NotNull
|
||||
String hostname;
|
||||
|
||||
@XmlElement
|
||||
@NotNull
|
||||
int port;
|
||||
|
||||
public String hostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public ProxyAddress hostname(String hostname) {
|
||||
this.hostname = hostname;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int port() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public ProxyAddress port(int port) {
|
||||
this.port = port;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean secure() {
|
||||
return secure;
|
||||
}
|
||||
|
||||
public ProxyAddress secure(boolean secure) {
|
||||
this.secure = secure;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -12,11 +12,15 @@ import org.gcube.common.resources.gcore.HostingNode;
|
|||
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
||||
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ProfileBuilder {
|
||||
|
||||
private static List<String> servletExcludes = Arrays.asList("default","jsp");
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ProfileBuilder.class);
|
||||
|
||||
private ApplicationContext context;
|
||||
|
||||
public ProfileBuilder(ApplicationContext context) {
|
||||
|
@ -43,18 +47,18 @@ public class ProfileBuilder {
|
|||
.status((context.lifecycle().state().remoteForm()));
|
||||
|
||||
endpoint.profile().endpoints().clear();
|
||||
|
||||
|
||||
String baseAddress;
|
||||
if (configuration.proxied()){
|
||||
String protocol = container.proxyAddress().secure()? "https://": "http://";
|
||||
int port = container.proxyAddress().port();
|
||||
String protocol = configuration.proxyAddress().protocol();
|
||||
String port = configuration.proxyAddress().port()!=null?":"+configuration.proxyAddress().port():"";
|
||||
|
||||
baseAddress=String.format("%s%s:%d%s", protocol , container.proxyAddress().hostname(), port,context.application().getContextPath());
|
||||
baseAddress=String.format("%s://%s%s%s", protocol , configuration.proxyAddress().hostname(), port,context.application().getContextPath());
|
||||
} else {
|
||||
String protocol = configuration.secure()? "https://": "http://";
|
||||
int port = configuration.secure()?container.securePort(): container.port();
|
||||
String protocol = container.protocol();
|
||||
int port = container.port();
|
||||
|
||||
baseAddress=String.format("%s%s:%d%s", protocol , container.hostname(), port,context.application().getContextPath());
|
||||
baseAddress=String.format("%s://%s:%d%s", protocol , container.hostname(), port,context.application().getContextPath());
|
||||
}
|
||||
|
||||
for (ServletRegistration servlet : context.application().getServletRegistrations().values())
|
||||
|
|
|
@ -69,19 +69,21 @@ public class RequestAccounting extends RequestHandler {
|
|||
String callerIp = e.request().getHeader("x-forwarded-for");
|
||||
if(callerIp==null)
|
||||
callerIp=e.request().getRemoteHost();
|
||||
|
||||
boolean success = e.response().getStatus()<400;
|
||||
|
||||
generateAccounting(caller,callerQualifier,callerIp==null?"UNKNOWN":callerIp , context);
|
||||
generateAccounting(caller,callerQualifier,callerIp==null?"UNKNOWN":callerIp , success, context);
|
||||
|
||||
log.info("REQUEST SERVED ON {}:{}({}) CALLED FROM {}@{} IN SCOPE {} FINISHED IN {} millis",
|
||||
log.info("REQUEST SERVED ON {}:{}({}) CALLED FROM {}@{} IN SCOPE {} {}(CODE {}) IN {} millis",
|
||||
context.configuration().name(),context.configuration().serviceClass(), InnerMethodName.instance.get(),
|
||||
caller, callerIp, ScopeProvider.instance.get(), System.currentTimeMillis()-startCallThreadLocal.get());
|
||||
caller, callerIp, ScopeProvider.instance.get(), success?"SUCCEDED":"FAILED", e.response().getStatus(), System.currentTimeMillis()-startCallThreadLocal.get());
|
||||
startCallThreadLocal.remove();
|
||||
InnerMethodName.instance.reset();
|
||||
if (resetScope)
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
void generateAccounting(String caller, String callerQualifier, String remoteHost, ApplicationContext context){
|
||||
void generateAccounting(String caller, String callerQualifier, String remoteHost, boolean success, ApplicationContext context){
|
||||
AccountingPersistenceFactory.setFallbackLocation(context.container().persistence().location());
|
||||
AccountingPersistence persistence = AccountingPersistenceFactory.getPersistence();
|
||||
ServiceUsageRecord serviceUsageRecord = new ServiceUsageRecord();
|
||||
|
@ -92,11 +94,11 @@ public class RequestAccounting extends RequestHandler {
|
|||
serviceUsageRecord.setScope(ScopeProvider.instance.get());
|
||||
serviceUsageRecord.setServiceClass(context.configuration().serviceClass());
|
||||
serviceUsageRecord.setServiceName(context.configuration().name());
|
||||
|
||||
|
||||
serviceUsageRecord.setHost(context.container().configuration().hostname()+":"+context.container().configuration().port());
|
||||
serviceUsageRecord.setCalledMethod(InnerMethodName.instance.get());
|
||||
serviceUsageRecord.setCallerHost(remoteHost);
|
||||
serviceUsageRecord.setOperationResult(OperationResult.SUCCESS);
|
||||
serviceUsageRecord.setOperationResult(success?OperationResult.SUCCESS:OperationResult.FAILED);
|
||||
serviceUsageRecord.setDuration(System.currentTimeMillis()-startCallThreadLocal.get());
|
||||
persistence.account(serviceUsageRecord);
|
||||
|
||||
|
|
|
@ -78,11 +78,11 @@ public class ApplicationManager {
|
|||
|
||||
context.configuration().validate();
|
||||
|
||||
if (context.configuration().secure() &&
|
||||
/* if (context.configuration().secure() &&
|
||||
container.configuration().securePort()==null)
|
||||
throw new IllegalStateException(
|
||||
String.format("Application %s cannot be managed because is declared as secure without a secure connector port declared in the container", context.application().getContextPath()));
|
||||
|
||||
*/
|
||||
|
||||
context.configuration().startTokens(generateTokensForApplication(container));
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import javax.servlet.ServletResponse;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.gcube.common.authorization.library.exception.AuthorizationException;
|
||||
import org.gcube.smartgears.configuration.application.Exclude;
|
||||
import org.gcube.smartgears.configuration.application.Include;
|
||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||
|
@ -27,6 +28,7 @@ import org.gcube.smartgears.handlers.application.RequestHandler;
|
|||
import org.gcube.smartgears.handlers.application.ResponseEvent;
|
||||
import org.gcube.smartgears.handlers.application.request.RequestError;
|
||||
import org.gcube.smartgears.handlers.application.request.RequestException;
|
||||
import org.gcube.smartgears.utils.Utils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -80,25 +82,27 @@ public class RequestManager implements Filter {
|
|||
|
||||
// create a per-request context with temporary properties
|
||||
ApplicationContext ctx = new DefaultApplicationContext(context);
|
||||
|
||||
|
||||
RequestEvent event = new RequestEvent(servlet, ctx, httprequest,httpresponse);
|
||||
|
||||
try {
|
||||
pipeline.forward(event);
|
||||
}
|
||||
catch(Throwable t) {
|
||||
log.error("error in doFilter, forward",t);
|
||||
handleError(httprequest,httpresponse,t);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try{
|
||||
// dispatch to other filters for this servlet
|
||||
chain.doFilter(request, response);
|
||||
}catch(Throwable t){
|
||||
t.printStackTrace();
|
||||
handleError(httprequest,httpresponse,t);
|
||||
}catch(ServletException t){
|
||||
log.error("error in doFilter",t.getRootCause());
|
||||
handleError(httprequest,httpresponse,t.getRootCause());
|
||||
}
|
||||
|
||||
|
||||
|
||||
ResponseEvent responseEvent = new ResponseEvent(servlet, ctx, httprequest, httpresponse);
|
||||
|
||||
try {
|
||||
|
@ -106,10 +110,11 @@ public class RequestManager implements Filter {
|
|||
pipeline.reverse().forward(responseEvent);
|
||||
}
|
||||
catch(Throwable t) {
|
||||
t.printStackTrace();
|
||||
log.error("error in doFilter, reverse",t);
|
||||
handleError(httprequest,httpresponse,t);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,7 +177,7 @@ public class RequestManager implements Filter {
|
|||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
return handlersToFilter;
|
||||
}
|
||||
|
||||
|
@ -241,22 +246,29 @@ public class RequestManager implements Filter {
|
|||
}*/
|
||||
|
||||
private void handleError(HttpServletRequest request, HttpServletResponse response,Throwable t) throws IOException {
|
||||
|
||||
if(t instanceof AuthorizationException) {
|
||||
|
||||
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
||||
response.getWriter().write("Error (Forbidden) : "+t.getMessage()+"\nStacktrace:\n");
|
||||
t.printStackTrace(response.getWriter());
|
||||
response.flushBuffer();
|
||||
|
||||
} else {
|
||||
|
||||
RequestError error = t instanceof RequestException?
|
||||
RequestException.class.cast(t).error():
|
||||
application_error;
|
||||
|
||||
if (error == application_error) {
|
||||
response.sendError(error.code(),error.message());
|
||||
}else {
|
||||
if (error == request_not_authorized_error){
|
||||
response.setHeader("WWW-Authenticate", "Basic realm=\"Smartgears\"");
|
||||
log.info("setting WWW-Authenticate to response header");
|
||||
}
|
||||
response.getWriter().write("Error ("+error.code()+") : "+error.message()+"\nStacktrace:\n");
|
||||
t.printStackTrace(response.getWriter());
|
||||
response.setStatus(error.code());
|
||||
}
|
||||
RequestError error = t instanceof RequestException?
|
||||
RequestException.class.cast(t).error():
|
||||
application_error;
|
||||
|
||||
response.resetBuffer();
|
||||
if (error == request_not_authorized_error){
|
||||
response.setHeader("WWW-Authenticate", "Basic realm=\"Smartgears\"");
|
||||
log.info("setting WWW-Authenticate to response header");
|
||||
}
|
||||
response.setStatus(error.code());
|
||||
response.getWriter().write("Error ("+error.code()+") : "+error.message()+"\nStacktrace:\n");
|
||||
t.printStackTrace(response.getWriter());
|
||||
response.flushBuffer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -217,5 +217,14 @@ public class Utils {
|
|||
new ServiceInfo(new ServiceIdentifier(application.configuration().serviceClass(), application.configuration().name(), hostedin));
|
||||
}
|
||||
|
||||
public static Throwable getCause(Throwable e) {
|
||||
Throwable cause = null;
|
||||
Throwable result = e;
|
||||
|
||||
while(null != (cause = result.getCause()) && (result != cause) ) {
|
||||
result = cause;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,14 +4,12 @@ import static junit.framework.Assert.assertEquals;
|
|||
import static junit.framework.Assert.assertNotNull;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.gcube.smartgears.configuration.Mode;
|
||||
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
||||
import org.gcube.smartgears.configuration.application.ApplicationConfigurationBinder;
|
||||
import org.gcube.smartgears.configuration.application.ApplicationExtensions;
|
||||
import org.gcube.smartgears.configuration.application.DefaultApplicationConfiguration;
|
||||
import org.gcube.smartgears.configuration.application.Exclude;
|
||||
import org.gcube.smartgears.configuration.application.Include;
|
||||
import org.gcube.smartgears.extensions.ApplicationExtension;
|
||||
import org.gcube.smartgears.persistence.DefaultPersistence;
|
||||
|
@ -101,7 +99,6 @@ public class ConfigurationTest {
|
|||
|
||||
|
||||
return new DefaultApplicationConfiguration()
|
||||
.secure(true)
|
||||
.mode(Mode.offline)
|
||||
.context("ctx")
|
||||
.name("name")
|
||||
|
|
|
@ -28,7 +28,6 @@ public class ConfigurationTest {
|
|||
String xml = "<container mode='offline'>"
|
||||
+ "<hostname>localhost</hostname>"
|
||||
+ "<port>8080</port>"
|
||||
+ "<secure-port>8484</secure-port>"
|
||||
+ "<infrastructure>gcube</infrastructure>"
|
||||
+ "<authorizeChildrenContext>true</authorizeChildrenContext> "
|
||||
+"<token>token1</token>" + "<token>token2</token>" + "<persistence location='target'/>" + appXml + "<site>"
|
||||
|
@ -54,7 +53,7 @@ public class ConfigurationTest {
|
|||
|
||||
private ContainerConfiguration sampleContainerConfiguration() {
|
||||
|
||||
return new ContainerConfiguration().mode(Mode.offline).hostname("localhost").port(8080).securePort(8484).infrastructure("gcube")
|
||||
return new ContainerConfiguration().mode(Mode.offline).hostname("localhost").port(8080).infrastructure("gcube")
|
||||
.startTokens(Arrays.asList("token1", "token2"))
|
||||
.site(new Site().country("it").location("rome").latitude("41.9000").longitude("12.5000"))
|
||||
.property("prop1", "val1").property("prop2", "val2").publicationFrequency(30)
|
||||
|
|
Loading…
Reference in New Issue