-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #471 from axonivy-market/cxfInterceptors
interceptor on client by example
- Loading branch information
Showing
7 changed files
with
187 additions
and
8 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...ivity/connectivity-demos-test/src_test/soap/bpm/TestClientedInterceptedPersonService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package soap.bpm; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import org.junit.jupiter.api.Test; | ||
import com.axonivy.connectivity.soap.client.CustomLogFeature; | ||
import ch.ivyteam.ivy.bpm.engine.client.BpmClient; | ||
import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; | ||
import ch.ivyteam.ivy.security.ISession; | ||
|
||
@IvyProcessTest | ||
public class TestClientedInterceptedPersonService { | ||
|
||
@Test | ||
void customLogInterceptor(BpmClient bpmClient, ISession session) { | ||
assertThat((String)session.getAttribute("lastExchange")) | ||
.isNull(); | ||
|
||
bpmClient.start() | ||
.process("soap/client/interceptedService/clientIntercept.ivp") | ||
.as().session(session) | ||
.execute(); | ||
|
||
assertThat((String)session.getAttribute("lastExchange")) | ||
.as("session attrs set by "+CustomLogFeature.class) | ||
.isNotBlank(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 24 additions & 7 deletions
31
connectivity/connectivity-demos/config/webservice-clients.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,57 @@ | ||
# yaml-language-server: $schema=https://json-schema.axonivy.com/app/0.0.1/webservice-clients.json | ||
WebServiceClients: | ||
personService: | ||
Id: 16150E44A158D09C | ||
ServiceClass: com.axonivy.connectivity.soap.service.client.PersonServiceService | ||
WsdlUrl: http://127.0.0.1:8081/designer/ws/connectivity-demos/16150E1D07E8CA18?WSDL | ||
WsCallLibrary: CXF | ||
ServiceClass: com.axonivy.connectivity.soap.service.client.PersonServiceService | ||
Features: | ||
- ch.ivyteam.ivy.webservice.exec.cxf.feature.HttpBasicAuthenticationFeature | ||
Properties: | ||
username: theBoss | ||
password: ${decrypt:\u007B\u0012\u0012\u0075\u002F\u0017\u00D1\u0083\u00C4\u009C\u0094\u00B0\u009A\u00B2\u00ED\u006B\u00AE\u000D\u005A\u0007\u0032\u009C\u0070\u00D6\u006F\u0027\u0008\u0080\u0085\u00CA\u005F\u00B5\u0094\u006C\u0091\u002D\u001A\u00F9\u0082\u0013\u004E\u00C4\u00C0\u0099\u00DA\u003B\u00C4\u0074} | ||
Endpoints: | ||
PersonServicePort: | ||
- '${ivy.app.baseurl}/ws/connectivity-demos/16150E1D07E8CA18' | ||
- ${ivy.app.baseurl}/ws/connectivity-demos/16150E1D07E8CA18 | ||
technicalBackend: | ||
Id: 162B962523BAAB85 | ||
ServiceClass: com.axonivy.connectivity.client.TechnicalBackendServiceService | ||
WsdlUrl: http://localhost:8081/designer/ws/connectivity-demos/162B95BB70C3178E?WSDL | ||
WsCallLibrary: CXF | ||
ServiceClass: com.axonivy.connectivity.client.TechnicalBackendServiceService | ||
Endpoints: | ||
TechnicalBackendServicePort: | ||
- '${ivy.app.baseurl}/ws/connectivity-demos/162B95BB70C3178E' | ||
- ${ivy.app.baseurl}/ws/connectivity-demos/162B95BB70C3178E | ||
smartbearTests: | ||
Id: 162B97C859B22CA3 | ||
ServiceClass: com.smartbear.sample.test.client.SampleWebService | ||
WsdlUrl: http://secure.smartbearsoftware.com/samples/testcomplete12/webservices/Service.asmx?WSDL | ||
WsCallLibrary: CXF | ||
ServiceClass: com.smartbear.sample.test.client.SampleWebService | ||
Endpoints: | ||
SampleWebServiceSoap: | ||
- http://secure.smartbearsoftware.com/samples/testcomplete12/webservices/Service.asmx | ||
SampleWebServiceSoap12: | ||
- http://secure.smartbearsoftware.com/samples/testcomplete12/webservices/Service.asmx | ||
#the backend defines a custom interceptor | ||
interceptedService: | ||
Id: 16D2A643A3A25C52 | ||
ServiceClass: com.axonivy.connectivity.soap.interceptor.client.ServiceWithExceptionService | ||
WsdlUrl: http://localhost:8081/designer/ws/connectivity-demos/16D29AE50A7A6E34?WSDL | ||
WsCallLibrary: CXF | ||
ServiceClass: com.axonivy.connectivity.soap.interceptor.client.ServiceWithExceptionService | ||
Endpoints: | ||
ServiceWithExceptionPort: | ||
- '${ivy.app.baseurl}/ws/connectivity-demos/16D29AE50A7A6E34' | ||
- ${ivy.app.baseurl}/ws/connectivity-demos/16D29AE50A7A6E34 | ||
#client with a custom interceptor feature | ||
interceptedPersonService: | ||
Id: 16330E44A158D09C | ||
ServiceClass: soap.intercepted.client.person.ivyteam.ch.client.PersonServiceService | ||
WsdlUrl: http://127.0.0.1:8081/designer/ws/connectivity-demos/16150E1D07E8CA18?WSDL | ||
WsCallLibrary: CXF | ||
Features: | ||
- ch.ivyteam.ivy.webservice.exec.cxf.feature.HttpBasicAuthenticationFeature | ||
- com.axonivy.connectivity.soap.client.CustomLogFeature | ||
Properties: | ||
username: theBoss | ||
password: ${decrypt:\u007B\u0012\u0012\u0075\u002F\u0017\u00D1\u0083\u00C4\u009C\u0094\u00B0\u009A\u00B2\u00ED\u006B\u00AE\u000D\u005A\u0007\u0032\u009C\u0070\u00D6\u006F\u0027\u0008\u0080\u0085\u00CA\u005F\u00B5\u0094\u006C\u0091\u002D\u001A\u00F9\u0082\u0013\u004E\u00C4\u00C0\u0099\u00DA\u003B\u00C4\u0074} | ||
Endpoints: | ||
PersonServicePort: | ||
- ${ivy.app.baseurl}/ws/connectivity-demos/16150E1D07E8CA18 |
Binary file added
BIN
+178 KB
connectivity/connectivity-demos/lib_ws/client/cxfClient_16330E44A158D09C.jar
Binary file not shown.
27 changes: 27 additions & 0 deletions
27
connectivity/connectivity-demos/processes/soap/client/clientInterceptor.p.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"$schema" : "https://json-schema.axonivy.com/process/11.2.1/process.json", | ||
"id" : "18A89E15504D8B30", | ||
"config" : { | ||
"data" : "com.axonivy.connectivity.Data" | ||
}, | ||
"elements" : [ { | ||
"id" : "f0", | ||
"type" : "RequestStart", | ||
"name" : "start", | ||
"config" : { | ||
"signature" : "start" | ||
}, | ||
"visual" : { | ||
"at" : { "x" : 96, "y" : 64 } | ||
}, | ||
"connect" : [ | ||
{ "id" : "f2", "to" : "f1" } | ||
] | ||
}, { | ||
"id" : "f1", | ||
"type" : "TaskEnd", | ||
"visual" : { | ||
"at" : { "x" : 352, "y" : 64 } | ||
} | ||
} ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ctivity/connectivity-demos/src/com/axonivy/connectivity/soap/client/CustomLogFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.axonivy.connectivity.soap.client; | ||
|
||
import org.apache.cxf.endpoint.Client; | ||
import org.apache.cxf.frontend.ClientProxy; | ||
import org.apache.cxf.interceptor.Fault; | ||
import org.apache.cxf.message.Message; | ||
import org.apache.cxf.phase.AbstractPhaseInterceptor; | ||
import org.apache.cxf.phase.Phase; | ||
import org.apache.http.HttpStatus; | ||
import ch.ivyteam.ivy.environment.Ivy; | ||
import ch.ivyteam.ivy.webservice.exec.feature.WebServiceClientFeature; | ||
import ch.ivyteam.ivy.webservice.exec.feature.WebServiceClientFeatureContext; | ||
|
||
/** | ||
* Demonstrates the setup of custom interceptors that track | ||
* the messages going out to the remote service and their responses. | ||
*/ | ||
public class CustomLogFeature implements WebServiceClientFeature { | ||
|
||
private static final String EXCHANGE_ID_KEY = "exchangeId"; | ||
|
||
@Override | ||
public void initialize(WebServiceClientFeatureContext context) { | ||
Client proxy = ClientProxy.getClient(context.getBindingProvider()); | ||
proxy.getOutInterceptors().add(new CxfSendInterceptor(Phase.SEND_ENDING)); | ||
proxy.getInInterceptors().add(new CxfReceiveInterceptor(Phase.RECEIVE)); | ||
Ivy.log().info("call initiated with custom interceptors provided by "+this); | ||
} | ||
|
||
public static class CxfSendInterceptor extends AbstractPhaseInterceptor<Message> { | ||
|
||
public CxfSendInterceptor(String phase) { | ||
super(phase); | ||
} | ||
|
||
@Override | ||
public void handleMessage(Message message) throws Fault { | ||
String exchangeId = getExchangeKey(message); | ||
Ivy.session().setAttribute("lastExchange", exchangeId); | ||
Ivy.log().debug("started exchange "+exchangeId); | ||
} | ||
|
||
} | ||
|
||
public class CxfReceiveInterceptor extends AbstractPhaseInterceptor<Message> { | ||
|
||
public CxfReceiveInterceptor(String phase) { | ||
super(phase); | ||
} | ||
|
||
@Override | ||
public void handleMessage(Message message) throws Fault { | ||
int responseCode = (int) message.get(Message.RESPONSE_CODE); | ||
Ivy.log().debug("ended exchange "+getExchangeKey(message)); | ||
if (HttpStatus.SC_OK != responseCode) { | ||
Ivy.log().error("request failed with http error code "+responseCode); | ||
} | ||
} | ||
} | ||
|
||
private static String getExchangeKey(Message message) { | ||
return (String) message.getExchange().get(EXCHANGE_ID_KEY); | ||
} | ||
} |