Proxy in Docusign Credential API - soap

Following the Examples of Docusign SDK located at
https://github.com/docusign/DocuSign-SOAP-SDK
Trying to implement the Credential API, code is something listed below
public LoginResult getCredentialAPI() {
CredentialSoap credApi = new CredentialFactory().getCredential(credentialURL);
LoginResult result = credApi.login("[" + integratorKey + "]" + username, password, true);
return result;
}
I am getting a Connection Times out Error, The reason been I have to use Proxy connection setting to make the connection, where do I add the server URL and port for proxy connections. The class Credential Factory is listed below
public class CredentialFactory {
/**
* Builds the API interface in order to use the Docusign Credential API.
*
* #param webserviceEndpoint the endpoint for the credential webservice
* #return the credential api stub
*/
public CredentialSoap getCredential(String webserviceEndpoint) {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
setupService(factory, webserviceEndpoint);
CredentialSoap credentialProxy = (CredentialSoap) factory.create();
return credentialProxy;
}
/**
* Set service class and webservice url.
*
* #param factory
* #param webserviceEndpoint the endpoint for the credential webservice
*/
protected void setupService(JaxWsProxyFactoryBean factory, String webserviceEndpoint) {
factory.setServiceClass(CredentialSoap.class);
factory.setAddress(webserviceEndpoint);
}
}

Proxy settings are stack-dependent. So the setting is usually below the level of the SOAP call. What stack are you using?
Judging from your variable name, you're using JAX-WS. In that case, see
https://stackoverflow.com/a/6447240/64904

Related

Spring Cloud Contract and Zuul

Using Spring Cloud Dalston, we have built a proxy service that, of course, uses Zuul. I am now trying to add Spring Cloud Contract tests to verify our proxy service works as expected from a contract adherence perspective. What is strange is that I can send a request and receive a 200 status code back, but the expected response body, content type header, etc. is empty, and my tests fail as a result.
Are there additional configurations not specified in the Spring Cloud Contract documentation necessary for testing services that use Zuul capabilities?
Here you have an example https://github.com/spring-cloud/spring-cloud-contract/issues/450
/**
* Abstraction of configuration to test contracts with external microservices which are using a zuul-gateway in between.
*
* When a provider of data only allows communication through a Zuul-Gateway, a special way to ensure valid contracts is needed.
* The Goal is to emulate the Zuul-Interception to be able to use the contracts stored within the providing service.
*
* F.e.: Consumer-Service consumes the Provider-Service, but the provider can not be called directly.
* The Consumer-Service calls an URL with a prefix consisting of the name of the gateway ("gateway") and name of the
* service (in this example "Provider-Service"). For example: http://gateway/provider/path/to/resource.
* The contract provided by Provider-Service holds only a part of the provided URL (here: "/path/to/resource").
* The resolution of "gateway" and "provider" is done within this class.
*/
#RunWith(SpringRunner.class)
#SpringBootTest(classes = EmbeddedZuulProxy.class,
properties = {"server.port: 8080",
"zuul.routes.provider.path: /provider/**",
"zuul.routes.provider.service-id: provider",
"zuul.routes.provider.url: http://localhost:9090/" //the url of the provider-stub is at port 9090
},
webEnvironment = WebEnvironment.DEFINED_PORT) //defined port is important! Ribbon points to zuul, which then points to the provider-stub
#AutoConfigureMockMvc
#AutoConfigureJsonTesters
//the stub runs on fixed port 9090, so that zuul can point to it
#AutoConfigureStubRunner(ids = "<group-id>:<artifact-id>:+:stubs:9090")
#DirtiesContext
public abstract class ZuulContractBase {
}
/**
* Configuration and Setup of an embedded Zuul-Gateway.
* This way it is possible to use contracts, stored in providing service
*/
#Configuration
#ComponentScan(basePackages = "<path.to.feign.client>") //autowiring feign client
#EnableAutoConfiguration
#EnableZuulProxy
#EnableFeignClients
#RibbonClient(name = "gateway", configuration = SimpleRibbonClientConfiguration.class)
class EmbeddedZuulProxy {
#Bean
RouteLocator routeLocator(DiscoveryClient discoveryClient,
ZuulProperties zuulProperties) {
return new DiscoveryClientRouteLocator("/", discoveryClient, zuulProperties);
}
}
/**
* Ribbon Load balancer with fixed server list for "simple" pointing to localhost,
* which holds the mocked zuul-gateway
*
* f.e. a call with feign would normally look like:
* http://gateway/provider/rest/path/to/your/{url}
* which is mapped to:
* http://localhost:{zuulport}/provider/rest/path/to/your/{url}
*/
#Configuration
class SimpleRibbonClientConfiguration {
#Value("${server.port}")
private Integer zuulPort;
#Bean
public ServerList<Server> ribbonServerList() {
return new StaticServerList<>(new Server("localhost", zuulPort));
}
}

How to call another restapi from rest api in same process using restEasy

I have rest api '/users/{id}/checkin' in which i want to do some processing and call another rest api on different resource but in same service. For example.
ServiceResource.java
#GET
#path(/services/checkin/)
public Response checkinUser(User user)
{
// --- processing.
}
UserResource.Java
#POST
#path(/users/{id}/checkin/)
public Response verifyUser(#PathParam("id) String id)
{
// --- Get the users from the iD.
User user = getUsers(id);
// --- need to call service from the serviceResource.
}
Any idea how to do it? as i want to avoid the HTTPclient call.
Put all method definitions and the resteasy annotations in an interface and use this interface as input to the resteasy proxy framework.
See documentation for details.
ServiceResourceIF.java:
public interface ServiceResourceIF {
#GET
#path(/services/checkin/)
public Response checkinUser(User user);
}
The calling code could look like this (stolen from the original documentation of resteasy, see link above):
User = new User(...);
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://your.service.url/base/uri");
ResteasyWebTarget rtarget = (ResteasyWebTarget)target;
ServiceClient service = rtarget.proxy(ServiceResourceIF.class);
service.checkinUser(user);
Note: You can use the same interface to configure the client and server.

zend framework1.12 rest services for web and mobile app

im new to zend framework and would like to create a web portal which offers a services .
The services would be used by webapplication and mobile application both.
I'm using Chris Danielson's article
http://www.chrisdanielson.com/2009/09/02/creating-a-php-rest-api-using-the-zend-framework/) as the base for.
My question is am i going in the right direction .currently im accessing the services as
http://www.zendrestexample.com/version .
1) I require it to use the url as http://www.zendrestexample.com/api/version
instead.
2)Do i need to use zend restserver for writing services ?
3)can i use the same service for both mobile app and the web app ?I mean any redirects problem arise?
4)Do i need to usezend rest client to consume those service ?
Pleas help me out..
Well you are not using bunch of PHP files to get this done... so I think you are on the right track =). The implementation in the article is okay, but very old... was written > 4 years ago. I would suggest looking into Zend_Soap_Server, Zend_Json_Server or Zend_Rest_Server. Soap solution is a bit heavy for the mobile in my opinion.
Just decide on the implementation and do little planning!
I wrote a web application and later had to add services layer in order to add mobile app interface to the application. Unfortunately this was not part of initial requirements so had to redo many things.
My advice is as follows (if you webapp and api are in a same project):
code all your application logic in library or in controller helpers. So same code can be reused in the main web application and in API layer
code your webapp logic in default module
code your api layer in a dedicated module called 'api'
phpdoc must be perfect in order for zend to autogenerate the SMD
For the API use standard JSON-RPC 2.0 protocol, there are clients for both Android / iPhone that utilize this and provide auto-discovery (SMD like WSDL but for json). All request sent via GET result in SMD being displayed all others result in handling of the request.
Utilize Zend_Json_Server for your API layer.
Here is an functional example :
<?php
// API Controller Example
class ApiController extends Zend_Controller_Action
{
public function init()
{
parent::init();
$this->getHelper('ViewRenderer')->setNoRender();
}
public function helloWorldAction()
{
$this->_handleRequest('App_Api_HelloWorld');
}
protected function _handleRequest($handlerClassName)
{
//
$this->getHelper('ViewRenderer')->setNoRender();
//
$server = new Zend_Json_Server();
$server->setClass($handlerClassName);
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$cfg = Zend_Registry::get('config');
$req = $this->getRequest();
$reqUrl = $cfg->paths->basehref . $req->getControllerName() . '/' . $req->getActionName();
$server->setTarget($reqUrl)
->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
$smd = $server->getServiceMap();
header('Content-Type: application/json');
echo $smd;
} else {
// handle request
$server->handle();
}
}
}
// HANDLER Class Example
class App_Api_HelloWorld extends App_Api_ApiHandlerAbstract
{
/**
* says "hello world"
*
* #return string
*/
public function hello()
{
return 'hello world';
}
/**
* says "hello $name"
*
* #param string $name
* #return string
*/
public function hello2($name)
{
return "hello $name";
}
/**
*
* #return string
* #throws Exception
*/
public function hello3()
{
throw new Zend_Json_Server_Exception('not allowed');
return '';
}
}
Here is sample Request (I added some bootstrap magic to pickup session by id)
https://domain.com/api/hello-world
{
"session_id": "4ggskr4fhe3lagf76b5tgaiu57",
"method": "hello2",
"params": {
"name" : "Alex"
},
"id": 123
}
Review JSON RPC 2.0 Documentation.
I found Advanced REST Client for Google Chrome to be BEST extension for developing and testing JSON web services.
For additional security you can restrict ALL the request via HTTP Auth by adding few lines of code to the abstract controller or even create security controller plugin.
Good Luck.

facebook4j OAuth issue

I am using facebook4j i have set the configuartion details in facebook4j.properties file. But when i trying to get the accesstoken it shows
SEVERE: Error while creating the Access TokenOAuth app id/secret combination not supplied
java.lang.IllegalStateException: OAuth app id/secret combination not supplied
at facebook4j.FacebookBaseImpl.getOAuth(FacebookBaseImpl.java:247)
at facebook4j.FacebookBaseImpl.getOAuthAuthorizationURL(FacebookBaseImpl.java:213)
at facebook4j.FacebookBaseImpl.getOAuthAuthorizationURL(FacebookBaseImpl.java:206)
Could anyone can provide a example for the facebook4j for java console application
Facebook facebookClient = new FacebookFactory().getInstance();
return facebookClient;
This is how you could use facebook4j without external configuration files. The code below provides a minimal example.
Here is my simple demo:
import facebook4j.Facebook;
import facebook4j.FacebookException;
import facebook4j.FacebookFactory;
import facebook4j.auth.AccessToken;
public class Facebook4JMinimalExample {
/**
* A simple Facebook4J client.
*
*
* #param args
* #throws FacebookException
*/
public static void main(String[] args) throws FacebookException {
// Generate facebook instance.
Facebook facebook = new FacebookFactory().getInstance();
// Use default values for oauth app id.
facebook.setOAuthAppId("", "");
// Get an access token from:
// https://developers.facebook.com/tools/explorer
// Copy and paste it below.
String accessTokenString = "PASTE_YOUR_ACCESS_TOKEN_STRING_HERE";
AccessToken at = new AccessToken(accessTokenString);
// Set access token.
facebook.setOAuthAccessToken(at);
// We're done.
// Write some stuff to your wall.
facebook.postStatusMessage("Wow, it works...");
}
}
Note that it is important to FIRST make a call to "facebook.setOAuthAppId(..)" and THEN set the access token. Otherwise you'll get an IllegalStateException saying "OAuth app id/secret combination not supplied".
In this case, I've just used a default value for OAuthAppId.

Can (and should?) Zend_Auth return class as the Identity?

I have a class R00_Model_User, which, curiously enough, represents user as he is. Can $result->getIdentity() return me an object of this class? (Or maybe it's stupid?)
(There is a factory method in R00_Model_User which prevents from duplicating objects. I'd like Zend_Auth to use it instead of creating a new object, if it can)
Two options:
write your own authentication adapter subclassing the out-of-the-box-adapter that matches your scenario best
class R00_Auth_Adapter extends Zend_Auth_Adapter_*
{
/**
* authenticate() - defined by Zend_Auth_Adapter_Interface. This method is called to
* attempt an authentication. Previous to this call, this adapter would have already
* been configured with all necessary information to successfully connect to a database
* table and attempt to find a record matching the provided identity.
*
* #throws Zend_Auth_Adapter_Exception if answering the authentication query is impossible
* #return Zend_Auth_Result
*/
public function authenticate()
{
$result = parent::authenticate();
if ($result->isValid() {
return new Zend_Auth_Result(
$result->getCode(),
R00_Model_User::load($result->getIdentity()),
$result->getMessages()
);
} else {
return $result;
}
}
}
This will allow you to code
$adapter = new R00_Auth_Adapter();
//... adapter initialisation (username, password, etc.)
$result = Zend_Auth::getInstance()->authenticate($adapter);
and on successfull authentication your user-object is automatically stored in the authentication storage (session by default).
or use your login-action to update the stored user identity
$adapter = new Zend_Auth_Adapter_*();
$result = $adapter->authenticate();
if ($result->isValid()) {
$user = R00_Model_User::load($result->getIdentity());
Zend_Auth::getInstance()->getStorage()->write($user);
}
In one of my applications, I have getIdentity() return a user object, and it works pretty well for me. To use your factory method, do like this:
$auth = Zend_Auth::getInstance();
$user = R00_Model_User::getInstance(...);
$auth->getStorage()->write($user);
Then when you call getIdentity(), you will have your user object.