Skip to content

Commit

Permalink
upadte osgi annotatation in rest endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
plutasnyy committed Aug 10, 2018
1 parent 3800206 commit 34d8e54
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 100 deletions.
17 changes: 16 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@
</dependency>

<!-- osgi -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.metatype.annotations</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
Expand Down Expand Up @@ -668,7 +683,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.4.1.1168</version>
<version>3.4.1.1168</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
Expand Down
28 changes: 10 additions & 18 deletions rest-endpoint/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.osgi</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
Expand All @@ -81,8 +77,16 @@
</dependency>

<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.metatype.annotations</artifactId>
</dependency>

<dependency>
Expand All @@ -93,18 +97,6 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
<goals>
<goal>scr</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.HttpService;

@Service
@Component(label = "ArtifactDataContent", description = "Data Storage information service", immediate = true)
@Component(immediate = true)
public class ArtifactServlet extends BasicDataServlet {

private static final long serialVersionUID = 1867870883439947956L;
private static final long serialVersionUID = -8115349502567690275L;

@Reference
private transient HttpService httpService;

@Reference
private ArtifactsDAO artifactsDAO;
Expand All @@ -60,6 +62,16 @@ protected void process(DBKey dbKey, HttpServletRequest req, HttpServletResponse
}
}

@Override
protected HttpService getHttpService() {
return httpService;
}

@Override
protected void setHttpService(HttpService httpService) {
this.httpService = httpService;
}

@Activate
public void start() {
register(Helper.getArtifactPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,18 @@
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.osgi.service.http.HttpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component
abstract class BasicDataServlet extends HttpServlet {

private static final long serialVersionUID = -6301708910829830328L;
private static final long serialVersionUID = -5819760668750910009L;

private static final Logger LOGGER = LoggerFactory.getLogger(BasicDataServlet.class);

private static final Gson GSON = new Gson();

@Reference
private transient HttpService httpService;

/***
* Returns JSON representation of Suite based correlationId or suite name
* Returned test suite is always in newest version.
Expand Down Expand Up @@ -77,18 +71,17 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
void register(String servletPath) {
LOGGER.debug("Registering servlet at ", servletPath);
try {
httpService.registerServlet(servletPath, this, null, null);
getHttpService().registerServlet(servletPath, this, null, null);
} catch (Exception e) {
LOGGER.error("Failed to register servlet at ", servletPath, e);
}
}

void unregister(String servletPath) {
httpService.unregister(servletPath);
httpService = null;
getHttpService().unregister(servletPath);
setHttpService(null);
}


boolean isValidName(String suiteName) {
return ValidatorProvider.getValidator().validateValue(Suite.class, "name", suiteName).isEmpty();
}
Expand All @@ -105,6 +98,10 @@ protected String responseAsJson(String format, Object... args) {
return GSON.toJson(new ErrorMessage(format, args));
}

protected abstract HttpService getHttpService();

protected abstract void setHttpService(HttpService httpService);

private static class ErrorMessage {

private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,18 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.HttpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Service
@Component(label = "ConfigsServlet", description = "Provides config for clients a", immediate = true)
@Component(immediate = true)
public class ConfigsServlet extends HttpServlet {

private static final long serialVersionUID = 101244102274582495L;
private static final long serialVersionUID = -8757845025924429010L;

private static final Logger LOGGER = LoggerFactory.getLogger(ConfigsServlet.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,16 @@
import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


@Service(LockService.class)
@Component(label = "LockService", description = "Provides lock service", immediate = true)
@Component(service = LockService.class, immediate = true)
public class LockService implements Serializable {

private static final long serialVersionUID = 101244102266582495L;
private static final long serialVersionUID = -2029917823742862618L;

private static final Logger LOGGER = LoggerFactory.getLogger(LockService.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,18 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.HttpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


@Service
@Component(label = "LocksServlet", description = "Provides lock services for clients", immediate = true)
@Component(immediate = true)
public class LockServlet extends HttpServlet {

private static final long serialVersionUID = 101244102274582495L;
private static final long serialVersionUID = 638302620021335857L;

private static final Logger LOGGER = LoggerFactory.getLogger(LockServlet.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,18 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.HttpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Service
@Component(label = "MetadataServlet", description = "Returns Suite Metadata", immediate = true)
@Component(immediate = true)
public class MetadataServlet extends BasicDataServlet {

private static final long serialVersionUID = 100244101178249562L;
private static final long serialVersionUID = 7233205495217724069L;

private static final Logger LOGGER = LoggerFactory.getLogger(MetadataServlet.class);

Expand All @@ -61,6 +60,9 @@ public class MetadataServlet extends BasicDataServlet {
@Reference
private LockService lockService;

@Reference
private transient HttpService httpService;

@Override
protected void process(DBKey dbKey, HttpServletRequest req, HttpServletResponse resp)
throws IOException {
Expand Down Expand Up @@ -103,6 +105,16 @@ protected void process(DBKey dbKey, HttpServletRequest req, HttpServletResponse
}
}

@Override
protected HttpService getHttpService() {
return this.httpService;
}

@Override
protected void setHttpService(HttpService httpService) {
this.httpService = httpService;
}

/***
* Saves Suite parsed from json provided in post body.
* It also increments Version of Suite.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,29 @@
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.apache.commons.io.IOUtils;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.HttpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Service
@Component(label = "XUnitServlet", description = "Provides xunit test result", immediate = true)
@Component(immediate = true)
public class XUnitServlet extends BasicDataServlet {

private static final Logger LOGGER = LoggerFactory.getLogger(XUnitServlet.class);
private static final long serialVersionUID = -5583065996820534015L;

private static final long serialVersionUID = 2459345654081429533L;
private static final Logger LOGGER = LoggerFactory.getLogger(XUnitServlet.class);

private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n";

@Reference
private MetadataDAO metadataDAO;

@Reference
private transient HttpService httpService;

@Activate
public void start() {
register(Helper.getXUnitPath());
Expand Down Expand Up @@ -84,6 +86,16 @@ protected void process(DBKey dbKey, HttpServletRequest request, HttpServletRespo
}
}

@Override
protected HttpService getHttpService() {
return this.httpService;
}

@Override
protected void setHttpService(HttpService httpService) {
this.httpService = httpService;
}

private Suite getSuite(DBKey dbKey, String correlationId, String suiteName)
throws RestServiceException {
final Suite suite;
Expand Down
Loading

0 comments on commit 34d8e54

Please sign in to comment.