forked from jottley/spring-social-salesforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom api Apex Callout Developmemt (jottley#73)
* #Custom API Apex Callout Development * #Custom Api Development * #Custom Api Development * #Custom Api Development * Update CustomApiTemplate.java * Update CustomApiTemplate.java Co-authored-by: agarw <agarw@LAPTOP-IES41ROR>
- Loading branch information
1 parent
10478ae
commit d6a8427
Showing
6 changed files
with
626 additions
and
247 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/main/java/org/springframework/social/salesforce/api/CustomApiOperations.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,56 @@ | ||
/** | ||
* Copyright (C) 2021 https://github.com/jottley/spring-social-salesforce | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.social.salesforce.api; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
/** | ||
* Defines operations for calling custom apex exposed rest apis. | ||
* | ||
* @author Sanchit Agarwal | ||
* | ||
*/ | ||
public interface CustomApiOperations { | ||
|
||
<T> T postForApexObject(String uriPath, Object request, Class<T> responseType); | ||
|
||
<T> T postForApexObject(String uriPath, Object request, Class<T> responseType, Map<String, ?> uriVariables); | ||
|
||
<T> T getForApexObject(String uriPath, Class<T> responseType); | ||
|
||
<T> T getForApexObject(String uriPath, Class<T> responseType, Map<String, ?> uriVariables); | ||
|
||
<T> T putForApexObject(String uriPath, Object request, Class<T> responseType); | ||
|
||
<T> T putForApexObject(String uriPath, Object request, Class<T> responseType, Map<String, ?> uriVariables); | ||
|
||
<T> T patchForApexObject(String uriPath, Object request, Class<T> responseType); | ||
|
||
<T> T patchForApexObject(String uriPath, Object request, Class<T> responseType, Map<String, ?> uriVariables); | ||
|
||
<T> T deleteForApexObject(String uriPath, Class<T> responseType); | ||
|
||
<T> T deleteForApexObject(String uriPath, Class<T> responseType, Map<String, ?> uriVariablesMap); | ||
|
||
// for custom api - (to get headers and body) | ||
<T> ResponseEntity<T> executeApexApi(String uriPath, HttpMethod method, HttpEntity<?> request, Class<T> responseType, Map<String, ?> uriVariables); | ||
|
||
<T> ResponseEntity<T> executeApexApi(String uriPath, HttpMethod method, HttpEntity<?> request, Class<T> responseType); | ||
} |
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
121 changes: 121 additions & 0 deletions
121
src/main/java/org/springframework/social/salesforce/api/impl/CustomApiTemplate.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,121 @@ | ||
/** | ||
* Copyright (C) 2021 https://github.com/jottley/spring-social-salesforce | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.social.salesforce.api.impl; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.social.salesforce.api.CustomApiOperations; | ||
import org.springframework.social.salesforce.api.Salesforce; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
/** | ||
* Defines operations for calling Apex based custom rest apis. | ||
* | ||
* @author Sanchit Agarwal | ||
* | ||
*/ | ||
public class CustomApiTemplate extends AbstractSalesForceOperations<Salesforce> implements CustomApiOperations { | ||
|
||
private RestTemplate restTemplate; | ||
|
||
public CustomApiTemplate(Salesforce api, RestTemplate restTemplate) { | ||
super(api); | ||
this.restTemplate = restTemplate; | ||
} | ||
|
||
protected String createUriPath(String uriPath) { | ||
return this.api.getInstanceUrl() + "/services/apexrest" + uriPath; | ||
} | ||
|
||
@Override | ||
public <T> T postForApexObject(String uriPath, Object request, Class<T> responseType) { | ||
requireAuthorization(); | ||
return this.restTemplate.postForObject(this.createUriPath(uriPath), request, responseType); | ||
} | ||
|
||
@Override | ||
public <T> T postForApexObject(String uriPath, Object request, Class<T> responseType, Map<String, ?> uriVariables) { | ||
requireAuthorization(); | ||
return this.restTemplate.postForObject(this.createUriPath(uriPath), request, responseType, uriVariables); | ||
} | ||
|
||
@Override | ||
public <T> T getForApexObject(String uriPath, Class<T> responseType) { | ||
requireAuthorization(); | ||
return this.restTemplate.getForObject(this.createUriPath(uriPath), responseType); | ||
} | ||
|
||
@Override | ||
public <T> T getForApexObject(String uriPath, Class<T> responseType, Map<String, ?> uriVariables) { | ||
requireAuthorization(); | ||
return this.restTemplate.getForObject(this.createUriPath(uriPath), responseType, uriVariables); | ||
} | ||
|
||
@Override | ||
public <T> T putForApexObject(String uriPath, Object request, Class<T> responseType) { | ||
requireAuthorization(); | ||
ResponseEntity<T> entity = this.restTemplate.exchange(this.createUriPath(uriPath), HttpMethod.PUT, new HttpEntity<Object>(request), responseType); | ||
return entity.getBody(); | ||
} | ||
|
||
@Override | ||
public <T> T putForApexObject(String uriPath, Object request, Class<T> responseType, Map<String, ?> uriVariables) { | ||
requireAuthorization(); | ||
ResponseEntity<T> entity = this.restTemplate.exchange(this.createUriPath(uriPath), HttpMethod.PUT, new HttpEntity<Object>(request), responseType, uriVariables); | ||
return entity.getBody(); | ||
} | ||
|
||
@Override | ||
public <T> T patchForApexObject(String uriPath, Object request, Class<T> responseType) { | ||
requireAuthorization(); | ||
return this.restTemplate.patchForObject(this.createUriPath(uriPath), request, responseType); | ||
} | ||
|
||
@Override | ||
public <T> T patchForApexObject(String uriPath, Object request, Class<T> responseType, Map<String, ?> uriVariables) { | ||
requireAuthorization(); | ||
return this.restTemplate.patchForObject(this.createUriPath(uriPath), request, responseType, uriVariables); | ||
} | ||
|
||
@Override | ||
public <T> T deleteForApexObject(String uriPath, Class<T> responseType) { | ||
requireAuthorization(); | ||
ResponseEntity<T> entity = this.restTemplate.exchange(this.createUriPath(uriPath), HttpMethod.DELETE, HttpEntity.EMPTY, responseType); | ||
return entity.getBody(); | ||
} | ||
|
||
@Override | ||
public <T> T deleteForApexObject(String uriPath, Class<T> responseType, Map<String, ?> uriVariables) { | ||
requireAuthorization(); | ||
ResponseEntity<T> entity = this.restTemplate.exchange(this.createUriPath(uriPath), HttpMethod.DELETE, HttpEntity.EMPTY, responseType, uriVariables); | ||
return entity.getBody(); | ||
} | ||
|
||
@Override | ||
public <T> ResponseEntity<T> executeApexApi(String uriPath, HttpMethod method, HttpEntity<?> request, Class<T> responseType) { | ||
requireAuthorization(); | ||
return this.restTemplate.exchange(this.createUriPath(uriPath), method, request, responseType); | ||
} | ||
|
||
@Override | ||
public <T> ResponseEntity<T> executeApexApi(String uriPath, HttpMethod method, HttpEntity<?> request, Class<T> responseType, Map<String, ?> uriVariables) { | ||
requireAuthorization(); | ||
return this.restTemplate.exchange(this.createUriPath(uriPath), method, request, responseType, uriVariables); | ||
} | ||
} |
Oops, something went wrong.