-
Notifications
You must be signed in to change notification settings - Fork 47
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 #78 from mendix/feature/global-request-settings
Added action to set max concurrency and timeouts
- Loading branch information
Showing
10 changed files
with
214 additions
and
120 deletions.
There are no files selected for viewing
Binary file not shown.
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
Binary file not shown.
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
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,54 +1,54 @@ | ||
// This file was generated by Mendix Business Modeler. | ||
// | ||
// WARNING: Only the following code will be retained when actions are regenerated: | ||
// - the import list | ||
// - the code between BEGIN USER CODE and END USER CODE | ||
// - the code between BEGIN EXTRA CODE and END EXTRA CODE | ||
// Other code you write will be lost the next time you deploy the project. | ||
// Special characters, e.g., é, ö, à, etc. are supported in comments. | ||
|
||
package restservices.actions; | ||
|
||
import restservices.consume.RestConsumer; | ||
import restservices.proxies.HttpMethod; | ||
import com.mendix.systemwideinterfaces.core.IMendixObject; | ||
import com.mendix.systemwideinterfaces.core.IContext; | ||
import com.mendix.webui.CustomJavaAction; | ||
|
||
/** | ||
* | ||
*/ | ||
public class getWithParams extends CustomJavaAction<IMendixObject> | ||
{ | ||
private String resourceUrl; | ||
private IMendixObject requestData; | ||
private IMendixObject targetObject; | ||
|
||
public getWithParams(IContext context, String resourceUrl, IMendixObject requestData, IMendixObject targetObject) | ||
{ | ||
super(context); | ||
this.resourceUrl = resourceUrl; | ||
this.requestData = requestData; | ||
this.targetObject = targetObject; | ||
} | ||
|
||
@Override | ||
public IMendixObject executeAction() throws Exception | ||
{ | ||
// BEGIN USER CODE | ||
return RestConsumer.request(getContext(), HttpMethod.GET, resourceUrl, requestData, targetObject, false).getMendixObject(); | ||
// END USER CODE | ||
} | ||
|
||
/** | ||
* Returns a string representation of this action | ||
*/ | ||
@Override | ||
public String toString() | ||
{ | ||
return "getWithParams"; | ||
} | ||
|
||
// BEGIN EXTRA CODE | ||
// END EXTRA CODE | ||
} | ||
// This file was generated by Mendix Business Modeler. | ||
// | ||
// WARNING: Only the following code will be retained when actions are regenerated: | ||
// - the import list | ||
// - the code between BEGIN USER CODE and END USER CODE | ||
// - the code between BEGIN EXTRA CODE and END EXTRA CODE | ||
// Other code you write will be lost the next time you deploy the project. | ||
// Special characters, e.g., é, ö, à, etc. are supported in comments. | ||
|
||
package restservices.actions; | ||
|
||
import restservices.consume.RestConsumer; | ||
import restservices.proxies.HttpMethod; | ||
import com.mendix.systemwideinterfaces.core.IMendixObject; | ||
import com.mendix.systemwideinterfaces.core.IContext; | ||
import com.mendix.webui.CustomJavaAction; | ||
|
||
/** | ||
* | ||
*/ | ||
public class getWithParams extends CustomJavaAction<IMendixObject> | ||
{ | ||
private String resourceUrl; | ||
private IMendixObject requestData; | ||
private IMendixObject targetObject; | ||
|
||
public getWithParams(IContext context, String resourceUrl, IMendixObject requestData, IMendixObject targetObject) | ||
{ | ||
super(context); | ||
this.resourceUrl = resourceUrl; | ||
this.requestData = requestData; | ||
this.targetObject = targetObject; | ||
} | ||
|
||
@Override | ||
public IMendixObject executeAction() throws Exception | ||
{ | ||
// BEGIN USER CODE | ||
return RestConsumer.request(getContext(), HttpMethod.GET, resourceUrl, requestData, targetObject, false).getMendixObject(); | ||
// END USER CODE | ||
} | ||
|
||
/** | ||
* Returns a string representation of this action | ||
*/ | ||
@Override | ||
public String toString() | ||
{ | ||
return "getWithParams"; | ||
} | ||
|
||
// BEGIN EXTRA CODE | ||
// END EXTRA CODE | ||
} |
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,53 +1,53 @@ | ||
// This file was generated by Mendix Business Modeler. | ||
// | ||
// WARNING: Only the following code will be retained when actions are regenerated: | ||
// - the import list | ||
// - the code between BEGIN USER CODE and END USER CODE | ||
// - the code between BEGIN EXTRA CODE and END EXTRA CODE | ||
// Other code you write will be lost the next time you deploy the project. | ||
// Special characters, e.g., é, ö, à, etc. are supported in comments. | ||
|
||
package restservices.actions; | ||
|
||
import restservices.consume.RestConsumer; | ||
import com.mendix.systemwideinterfaces.core.IMendixObject; | ||
import com.mendix.systemwideinterfaces.core.IContext; | ||
import com.mendix.webui.CustomJavaAction; | ||
|
||
/** | ||
* | ||
*/ | ||
public class postWithResult extends CustomJavaAction<IMendixObject> | ||
{ | ||
private String collectionUrl; | ||
private IMendixObject dataObject; | ||
private IMendixObject responseData; | ||
|
||
public postWithResult(IContext context, String collectionUrl, IMendixObject dataObject, IMendixObject responseData) | ||
{ | ||
super(context); | ||
this.collectionUrl = collectionUrl; | ||
this.dataObject = dataObject; | ||
this.responseData = responseData; | ||
} | ||
|
||
@Override | ||
public IMendixObject executeAction() throws Exception | ||
{ | ||
// BEGIN USER CODE | ||
return RestConsumer.postObject(getContext(), collectionUrl, dataObject, responseData).getMendixObject(); | ||
// END USER CODE | ||
} | ||
|
||
/** | ||
* Returns a string representation of this action | ||
*/ | ||
@Override | ||
public String toString() | ||
{ | ||
return "postWithResult"; | ||
} | ||
|
||
// BEGIN EXTRA CODE | ||
// END EXTRA CODE | ||
} | ||
// This file was generated by Mendix Business Modeler. | ||
// | ||
// WARNING: Only the following code will be retained when actions are regenerated: | ||
// - the import list | ||
// - the code between BEGIN USER CODE and END USER CODE | ||
// - the code between BEGIN EXTRA CODE and END EXTRA CODE | ||
// Other code you write will be lost the next time you deploy the project. | ||
// Special characters, e.g., é, ö, à, etc. are supported in comments. | ||
|
||
package restservices.actions; | ||
|
||
import restservices.consume.RestConsumer; | ||
import com.mendix.systemwideinterfaces.core.IMendixObject; | ||
import com.mendix.systemwideinterfaces.core.IContext; | ||
import com.mendix.webui.CustomJavaAction; | ||
|
||
/** | ||
* | ||
*/ | ||
public class postWithResult extends CustomJavaAction<IMendixObject> | ||
{ | ||
private String collectionUrl; | ||
private IMendixObject dataObject; | ||
private IMendixObject responseData; | ||
|
||
public postWithResult(IContext context, String collectionUrl, IMendixObject dataObject, IMendixObject responseData) | ||
{ | ||
super(context); | ||
this.collectionUrl = collectionUrl; | ||
this.dataObject = dataObject; | ||
this.responseData = responseData; | ||
} | ||
|
||
@Override | ||
public IMendixObject executeAction() throws Exception | ||
{ | ||
// BEGIN USER CODE | ||
return RestConsumer.postObject(getContext(), collectionUrl, dataObject, responseData).getMendixObject(); | ||
// END USER CODE | ||
} | ||
|
||
/** | ||
* Returns a string representation of this action | ||
*/ | ||
@Override | ||
public String toString() | ||
{ | ||
return "postWithResult"; | ||
} | ||
|
||
// BEGIN EXTRA CODE | ||
// END EXTRA CODE | ||
} |
51 changes: 51 additions & 0 deletions
51
javasource/restservices/actions/setGlobalRequestSettings.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,51 @@ | ||
// This file was generated by Mendix Business Modeler. | ||
// | ||
// WARNING: Only the following code will be retained when actions are regenerated: | ||
// - the import list | ||
// - the code between BEGIN USER CODE and END USER CODE | ||
// - the code between BEGIN EXTRA CODE and END EXTRA CODE | ||
// Other code you write will be lost the next time you deploy the project. | ||
// Special characters, e.g., é, ö, à, etc. are supported in comments. | ||
|
||
package restservices.actions; | ||
|
||
import restservices.consume.RestConsumer; | ||
import com.mendix.systemwideinterfaces.core.IContext; | ||
import com.mendix.webui.CustomJavaAction; | ||
|
||
/** | ||
* | ||
*/ | ||
public class setGlobalRequestSettings extends CustomJavaAction<Boolean> | ||
{ | ||
private Long maxConcurrentRequests; | ||
private Long timeout; | ||
|
||
public setGlobalRequestSettings(IContext context, Long maxConcurrentRequests, Long timeout) | ||
{ | ||
super(context); | ||
this.maxConcurrentRequests = maxConcurrentRequests; | ||
this.timeout = timeout; | ||
} | ||
|
||
@Override | ||
public Boolean executeAction() throws Exception | ||
{ | ||
// BEGIN USER CODE | ||
RestConsumer.setGlobalRequestSettings(maxConcurrentRequests, timeout); | ||
return true; | ||
// END USER CODE | ||
} | ||
|
||
/** | ||
* Returns a string representation of this action | ||
*/ | ||
@Override | ||
public String toString() | ||
{ | ||
return "setGlobalRequestSettings"; | ||
} | ||
|
||
// BEGIN EXTRA CODE | ||
// END EXTRA CODE | ||
} |
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
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
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,29 @@ | ||
package tests; | ||
|
||
import com.mendix.core.Core; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import restservices.RestServices; | ||
import restservices.consume.RestConsumeException; | ||
import restservices.consume.RestConsumer; | ||
import restservices.proxies.HttpMethod; | ||
import restservices.publish.MicroflowService; | ||
|
||
public class TimeoutTests extends TestBase { | ||
|
||
@Test | ||
public void testIdleTimeout() throws Exception { | ||
RestConsumer.setGlobalRequestSettings(null, 1000L); | ||
String url = RestServices.getAbsoluteUrl("ServiceWithLongOperation"); | ||
|
||
new MicroflowService("Tests.ServiceWithLongOperation", "*", HttpMethod.GET, "Service with 1 minute operation"); | ||
|
||
try { | ||
RestConsumer.request(Core.createSystemContext(), HttpMethod.GET, url, null, null, false); | ||
} catch (RestConsumeException rce) { | ||
Assert.assertTrue(rce.getResponseData().getBody().startsWith("java.net.SocketTimeoutException")); | ||
} finally { | ||
RestConsumer.setGlobalRequestSettings(null, 0L); | ||
} | ||
} | ||
} |