Skip to content

Commit 8c9b45e

Browse files
committed
move controller endpoint
The endpoint for the postback controller is now at `/webhook/blitline/image` to facilitate CSRF exemption for Webhooks/postbacks generally.
1 parent 5058ef8 commit 8c9b45e

File tree

7 files changed

+28
-18
lines changed

7 files changed

+28
-18
lines changed

blitline-image-client-example/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.blitline</groupId>
66
<artifactId>blitline-java-parent</artifactId>
7-
<version>0.16.0-SNAPSHOT</version>
7+
<version>0.16.0</version>
88
</parent>
99

1010
<artifactId>blitline-image-client-example</artifactId>

blitline-image-client-spring/README.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ it can find in the Spring environment (see below).
5353
arguments.
5454
- If the `builtinPostback` property of the `@EnableBlitlineImageService`
5555
annotation is **not** set to `false`, a skeleton Spring MVC controller mapped
56-
to `/blitline/image`. This controller will accept the postbacks sent from
56+
to `/webhook/blitline/image`. This controller will accept the postbacks sent from
5757
Blitline and pass them on to a handler, which you must define.
5858

5959
####Properties
@@ -105,6 +105,20 @@ logic for what the system should do when a postback arrives. Register a bean
105105
implementing the `BlitlinePostbackHandler` interface, and it will be invoked
106106
whenever postbacks show up. See the example for a minimal implementation.
107107

108+
You may be interested in custom HTTP headers that you specify to Blitline,
109+
such as a job-correlation ID. Simply register Spring beans of type `String`
110+
annotated with `@BlitlinePostbackHeader`, and any headers matching those
111+
names will be passed to the handler.
112+
113+
Spring Integration's service-activator support can handle Blitline postbacks
114+
easily. Use the following declaration:
115+
116+
````xml
117+
<int:gateway
118+
service-interface="com.blitline.image.spring.postback.BlitlinePostbackHandler"
119+
default-request-channel="your-postback-channel" />
120+
````
121+
108122
#####Use your own endpoint
109123

110124
If you want to heavily customize the postback handling, or if you would like
@@ -118,13 +132,9 @@ disable the built-in postback controller:
118132
In this case, if you want to use postbacks, you **must** specify the URL
119133
explicitly, as the system has no way of finding your custom endpoint.
120134

121-
Spring Integration's inbound HTTP channel adapter can handle Blitline postbacks
122-
easily. Use the following declaration:
135+
####Security
123136

124-
````xml
125-
<int-http:inbound-channel-adapter
126-
path="/blitline"
127-
channel="blitline-postback-announce"
128-
request-payload-type="com.blitline.image.BlitlinePostback"
129-
message-converters="blitlinePostbackHttpMessageConverter" />
130-
````
137+
Since postbacks will be coming in asynchronously, CSRF protection will need
138+
to be disabled for the postback endpoint. The built-in controller is mapped
139+
under `/webhook`, and it is suggested that `/webhook/**` be exempted from the
140+
CSRF policy and used to aggregate all such handlers.

blitline-image-client-spring/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.blitline</groupId>
66
<artifactId>blitline-java-parent</artifactId>
7-
<version>0.16.0-SNAPSHOT</version>
7+
<version>0.16.0</version>
88
</parent>
99

1010
<artifactId>blitline-image-client-spring</artifactId>

blitline-image-client-spring/src/main/java/com/blitline/image/spring/web/BlitlinePostbackController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
@RequestMapping(BlitlinePostbackController.BASE_ENDPOINT)
4040
public class BlitlinePostbackController {
4141

42-
public static final String BASE_ENDPOINT = "/blitline";
42+
public static final String BASE_ENDPOINT = "/webhook/blitline";
4343
public static final String IMAGE_PATH = "/image";
4444

4545
private final Log log = LogFactory.getLog(BlitlinePostbackController.class);

blitline-image-client/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ API](https://www.blitline.com/docs/functions) will need to be reflected here.**
4040

4141
BlitlineImageJob j = BlitlineImageJob.forApplication("myApplicationId")
4242
.fromUrl("http://cdn.blitline.com/filters/boys.jpeg") // also supports S3
43-
.withPostback("https://backend.example.com/blitline") // for job status
43+
.withPostback("https://backend.example.com/webhook/blitline/image") // for job status
4444
.apply( // function pipeline starts here
4545
Blitline.drawEllipse(150,150,200,100).andSaveResult("ellipse-overlay"),
4646
Blitline.cropToSquare().gravity(Gravity.SOUTHWEST).andSaveResult("square-color").thenApply(
@@ -49,14 +49,14 @@ BlitlineImageJob j = BlitlineImageJob.forApplication("myApplicationId")
4949
)
5050
)
5151
);
52-
52+
5353
String json = mapper.writeValueAsString(j);
5454
````
5555

5656
````java
5757
// using Spring injection for identifiers and RestTemplate for HTTP operations
5858

59-
final String IMAGE_IDENTIFIER = "ellipse-overlay";
59+
final String IMAGE_IDENTIFIER = "ellipse-overlay";
6060

6161
@Autowired BlitlineImageService bis; // applicationId and optionally postbackUrl read from properties
6262

blitline-image-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.blitline</groupId>
66
<artifactId>blitline-java-parent</artifactId>
7-
<version>0.16.0-SNAPSHOT</version>
7+
<version>0.16.0</version>
88
</parent>
99

1010
<artifactId>blitline-image-client</artifactId>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.blitline</groupId>
55
<artifactId>blitline-java-parent</artifactId>
6-
<version>0.16.0-SNAPSHOT</version>
6+
<version>0.16.0</version>
77
<packaging>pom</packaging>
88
<name>Blitline Java client</name>
99
<description>Java client libraries for Blitline</description>

0 commit comments

Comments
 (0)