Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

feat: add a HttpProducer for methods doing a http(s) call #11

Merged
merged 2 commits into from May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Expand Up @@ -27,4 +27,15 @@ public class MyUserDefinedScanner implements IScannerService {
return Collections.emptySet();
}
}
```
```

## Annotate Producer Methods
Scanning consumers (like http(s) endpoints or JMS receivers) is simple, but detecting the producers
(e.g. methods calling a http(s) endpoint) is much harder or even impossible. To solve this problem a
special annotation is provided:
- `@VisualizeHttpsCall(type="GET", path="/customer/{customerId}", projectId="1234", projectName="Customer Service")`

Note 1: The `projectName` is optional and might be nice to see in the code.

Note 2: There is always an annotation of the same name but ending in `s` (e.g. `@VisualizeHttpsCalls`) in case you need
to place more than one annotation on the method.
@@ -1,6 +1,5 @@
package com.hlag.tools.commvis.analyzer.annotation;

import javax.ws.rs.HttpMethod;
import java.lang.annotation.*;

/**
Expand All @@ -19,7 +18,7 @@
/**
* @return the method used to call path, e.g. GET, POST, ...
*/
String method();
String type();

/**
* @return the path called, e.g. "/customer/{id}"
Expand Down
Expand Up @@ -4,6 +4,12 @@

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
/**
* Used to group multiple {@link VisualizeHttpsCall} annotation on one element.
*/
public @interface VisualizeHttpsCalls {
/**
* @return all grouped {@link VisualizeHttpsCall} annotations
*/
VisualizeHttpsCall[] value();
}
Expand Up @@ -6,6 +6,8 @@
public abstract class AbstractCommunicationModelVisitor {
public abstract void visit(CommunicationModel model);

public abstract void visit(HttpReceiver httpReceiver);
public abstract void visit(HttpConsumer httpReceiver);
public abstract void visit(HttpProducer httpReceiver);

public abstract void visit(JmsReceiver jmsReceiver);
}
@@ -0,0 +1,20 @@
package com.hlag.tools.commvis.analyzer.model;

import lombok.*;

/**
* An endpoint which can receive http(s) messages. Typically, a REST API.
*/
@Value
public class HttpConsumer implements ISenderReceiverCommunication {
private final String className;
private final String methodName;

private final String type;
private final String path;

@Override
public void visit(AbstractCommunicationModelVisitor visitor) {
visitor.visit(this);
}
}
@@ -0,0 +1,36 @@
package com.hlag.tools.commvis.analyzer.model;

import lombok.Value;

/**
* Holds the data of one method calling a http(s) endpoint.
*/
@Value
public class HttpProducer implements ISenderReceiverCommunication {
/**
* The full qualified classname where the producer lives.
*/
private final String className;
/**
* The method name of the producer.
*/
private final String methodName;

/**
* The HTTP method like GET or POST.
*/
private final String type;
/**
* The full path name called (usually without a domain).
*/
private final String path;
/**
* The project id of the referenced project.
*/
private final String destinationProjectId;

@Override
public void visit(AbstractCommunicationModelVisitor visitor) {
visitor.visit(this);
}
}

This file was deleted.