Amazon DynamoDB Java SDK won't use proxy settings - coldfusion

I'm trying to implement an interface to AWS' DynamoDB in ColdFusion 11, on a corporate network with an NTLM proxy. I started with BDCraven's cfdynamo implementation, and extended it as per the SDK docs to include my proxy settings.
Component structure and init function below. getProxyParameters.cfm pulls my proxy settings from the database and initialises strProxyServer, strProxyPort etc. These proxy settings and credentials have been tested in other ColdFusion code (using cfhttp) and are definitely valid.
component accessors="true" alias="cfc.DynamoClient" displayname="DynamoClient" hint="I handle interactions with an Amazon DynamoDB instance"{
property name="aws_key" type="string" hint="The AWS Key";
property name="aws_secret" type="string" hint="The AWS Secret";
property name="aws_creds" type="object";
property name="aws_dynamodb" type="object";
include "/getProxyParameters.cfm";
variables.aws_key = "";
variables.aws_secret = "";
public cfc.DynamoClient function init(required string aws_key, required string aws_secret){
variables.aws_key = trim(arguments.aws_key);
variables.aws_secret = trim(arguments.aws_secret);
variables.aws_creds = createObject("java","com.amazonaws.auth.BasicAWSCredentials").init(variables.aws_key, variables.aws_secret);
aws_clientconfig = createObject("java","com.amazonaws.ClientConfiguration").init();
aws_clientconfig.setProtocol(createObject("java","com.amazonaws.Protocol").HTTPS);
aws_clientconfig.setProxyHost(strProxyServer);
aws_clientconfig.setProxyPort(strProxyPort);
aws_clientconfig.setProxyUsername(strProxyUsername);
aws_clientconfig.setProxyPassword(strProxyPassword);
aws_clientconfig.setProxyDomain(strProxyDomain);
variables.aws_dynamodb = createObject("java","com.amazonaws.services.dynamodb.AmazonDynamoDBClient").init(aws_creds, aws_clientconfig);
variables.aws_dynamodb.setEndpoint('dynamodb.ap-southeast-2.amazonaws.com');
variables.aws_dynamodb.setConfiguration(aws_clientconfig);
return this;
}
[...etc]
This init function returns without error, and variables.aws_dynamodb is an object of type com.amazonaws.services.dynamodb.AmazonDynamoDBClient.
The problem is that when I try to use it, the proxy settings are ignored:
public array function list_tables(string start_table, numeric limit=1){
var table_request = createObject("java","com.amazonaws.services.dynamodb.model.ListTablesRequest").init();
table_request.setLimit(arguments.limit);
if(structKeyExists(arguments,"start_table")){
table_request.setExcusiveStartTableName(trim(arguments.start_table));
}
return variables.aws_dynamodb.listTables(table_request).getTableNames();
}
This list_tables function waits for a long time, and then returns a ColdFusion error:
I've tried running netstat -a on the server while this request is happening, and the only connection is this SYN_SENT:
...and that IP looks like one of AWS's servers, not my proxy. Am I missing something obvious? Has anyone gotten this combination of tech to work properly?

Related

aws Environment Variables to replace connection string in ASP.net MVC

I was trying to deploy an application in AWS elastic beanstalk with connection string inside web.config file everything works fine. But when I tried to implement by setting environment variables in AWS application it did not work. What I did was I added AWS tags key value pair in aws like RDS_DATABASENAME - admin then i added those in web.config like
<add key="RDS_DB_NAME" value="RDS_DB_NAME"/>
<add key="RDS_USERNAME" value="RDS_USERNAME"/>
<add key="RDS_PASSWORD" value="RDS_PASSWORD"/>
<add key="RDS_HOSTNAME" value="RDS_HOSTNAME"/>
<add key="RDS_PORT" value="*RDS_PORT" />
Then while building connectionString I used this:
var appConfig = ConfigurationManager.AppSettings; // trying to get connection details from enviornment varibales
string dbname = appConfig["RDS_DB_NAME"];
if (string.IsNullOrEmpty(dbname)) return null;
string username = appConfig["RDS_USERNAME"];
string password = appConfig["RDS_PASSWORD"];
string hostname = appConfig["RDS_HOSTNAME"];
string port = appConfig["RDS_PORT"];
SqlConnectionStringBuilder sqlString = new SqlConnectionStringBuilder()
{
DataSource = hostname + "," + port,
InitialCatalog = dbname,
UserID = username,
Password = password
};
return sqlString.ToString();
I followed the aws doc itself somehow I missed something!
The idea with Elastic Beanstalk is that any Environment Properties configured for the Environment will be automatically passed to your application. In a .NET application, this means that they are appended automatically to the end of the <appSettings> section of the Web.config.
So you shouldn't need to make any changes to your Web.config (I would leave those variables out entirely), and your implementation of building the connectionString appears fine.
To troubleshoot, try launching the application with the Environment Properties set. Then log into the instance and verify that the variables have been added to the Web.config correctly. If they are you might need to do some more testing around making sure your application is reading them in correctly.

How to read request parameter values in wso2 esb script mediator

I need to catch the url parameters parsing in a get request by script mediator. I uses WSO2 esb 4.8.1. and I tried with the following js code. but it gives an error saying window is not defined.
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
var requestNew="<m:ViW xmlns:m=\"wom\">
<m:request>
<RequestHeader>
<RemoteIP>dummyIp</RemoteIP>
<AppName>dummyAppName</AppName>
<AppPassword>dummyPassword</AppPassword>
<UserName>dummyUserName</UserName>
</RequestHeader>
<OrderId>23</OrderId>
<AccountNo>23</AccountNo>
<Cir>23</Cir>
<DocketNo>23</DocketNo>
<Status>23</Status>
<RequestType>23</RequestType>
<RequestedFrom>2016-04-19T22:47:37.000Z</RequestedFrom>";
requestNew=requestNew+"
<RequestedTo>"+getUrlVars()['RequestedTo']+"</RequestedTo>
</m:request>
</m:ViW>";
mc.setPayloadXML(new XML(requestNew));
So how can I access url parameter values in the wso2 esb script mediator?
Following blog will tell you how to do it. Its written targetting WSO2 API Cloud. But since synapse is used in both ESB and API Manager, its valid for your question as well. In summary,
To retrieve path parameters
var id = mc.getProperty('uri.var.id');
To retrieve query parameters
var mask = mc.getProperty('query.param.mask');

simple azure web service, http404 error on publish when adding /dowork to URL

I am trying my first web app service using Azure services. I've created it in VS, and it works locally. All it does it return a string that says "hello user" is JSON.
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
// To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
// To create an operation that returns XML,
// add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
// and include the following line in the operation body:
// WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
[OperationContract]
[WebGet(UriTemplate = "/DoWork")]
public string DoWork()
{
// Add your operation implementation here
return "hello user";
}
// Add more operations here and mark them with [OperationContract]
}
}
Problem is when I publish it, says successful. I can see it running on portal.
When I goto published site I get the standard THIS WEB APP HAS BEEN SUCCESSFULLY CREATED, but... when I add the /DoWork to the URL I get HTTP error 404.
I know I must be missing something simple...
any ideas?
you're missing the name of the service. In your case would be something like:
http://engineappservicev001.azurewebsites.net/something.svc/dowork
More info in here:
http://www.codeproject.com/Articles/571813/A-Beginners-Tutorial-on-Creating-WCF-REST-Services

How to enable pretty logging of SOAP messages in JBoss 7

I have enabled SOAP logging by adding following in standalone.xml as described in Jboss Advanced User Guide:
<system-properties>
<property name="org.apache.cxf.logging.enabled" value="true"/>
</system-properties>
This configuration does not pretty print XML messages. I am sure that CXF supports pretty printing since there is a AbstractLoggingInterceptor.setPrettyLogging() method in the library.
How can I enable pretty printing of SOAP requests and responses in JBoss 7.
Using org.apache.cxf.logging.enabled property is the right way, it accepts value "pretty" for nicely formatted xml output
<system-properties>
<property name="org.apache.cxf.logging.enabled" value="pretty"/>
</system-properties>
For details see https://github.com/apache/cxf/blob/master/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerBus.java#L68-L72
Even though Serdal's answer is correct, it does not look practical to me.
My solution
I removed org.apache.cxf.logging.enabled system property and used following code to enable SOAP logging:
Client client = ClientProxy.getClient(port);
LoggingInInterceptor inInterceptor = new LoggingInInterceptor();
inInterceptor.setPrettyLogging(true);
client.getInInterceptors().add(inInterceptor);
LoggingOutInterceptor outInterceptor = new LoggingOutInterceptor();
outInterceptor.setPrettyLogging(true);
client.getOutInterceptors().add(outInterceptor);
I was able to pretty print and also to increase limit size of XML response from Webservice by doing the following:
wsdlLocationURL = new URL(productServiceURLStr);
ServiceFacadeBeanService serviceFacade =
new ServiceFacadeBeanService(wsdlLocationURL, SERVICE_FACADE_QNAME);
ServiceFacade sfPort = serviceFacade.getServiceFacadeBeanPort();
Client client = ClientProxy.getClient(sfPort);
List<Interceptor<? extends Message>> ics = client.getBus().getOutInterceptors();
for (Interceptor ic: ics) {
if (ic instanceof LoggingOutInterceptor) {
LoggingOutInterceptor out = (LoggingOutInterceptor) ic;
out.setPrettyLogging(true);
out.setLimit(1024 * 1024 *1024);
}
}
Use below mentioned annotations with your web service.
#InInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingInInterceptor")
#OutInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingOutInterceptor")
#InFaultInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingInInterceptor")
#OutFaultInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingOutInterceptor")
#Logging(pretty = true)

Trouble with SOAP request from Flex

SUM: I ended up having to form the XML manually. I also had to create an Operation and use its send(); method rather than just doing something like WebService.MyServiceFunction(); - not sure why that was the case.
I send off the request as follows:
var xm:XML =
<SetPropertiesForCurrentUser xmlns="http://asp.net/ApplicationServices/v200">
<values xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<d4p1:KeyValueOfstringanyType>
<d4p1:Key>{obj.Key}</d4p1:Key>
<d4p1:Value xmlns:d6p1="http://www.w3.org/2001/XMLSchema" i:type="d6p1:string">{obj.Value}</d4p1:Value>
</d4p1:KeyValueOfstringanyType>
</values>
</SetPropertiesForCurrentUser>;
var profileService:WebService = new WebService();
profileService.useProxy = false;
profileService.loadWSDL(url);
var o:Operation = profileService.SetPropertiesForCurrentUser;
o.send(xm);
Here’s my scenario:
I have ASP.NET web services to handle authentication, user roles, and user profiles (default ASP.NET AuthenticationService, RoleService, and ProfileService, to be exact).
So from my Flex web app, I am able to successfully call the ASP.NET service. For example, something like this works fine:
var profileService:WebService = new WebService();
profileService.useProxy = false;
profileService.GetAllPropertiesForCurrentUser.addEventListener("result",getAllPropertiesForCurrentUser_EventHandler);
profileService.addEventListener("fault",getAllPropertiesForCurrentUserFault_EventHandler);
profileService.loadWSDL(url);
profileService.GetAllPropertiesForCurrentUser();
I run into trouble when I need to pass a Dictionary object to another function on the service (SetPropertiesForCurrentUser). The .NET service asks for this type of value:
System.Collections.Generic.IDictionary(Of String, Object)
Here are the two pertinent entries from the web.config entry from my ASP.NET service:
<properties>
<clear/>
<add name="coordinateFormat" />
</properties>
...
<profileService enabled="true"
readAccessProperties="coordinateFormat"
writeAccessProperties="coordinateFormat"/>
So after putting together a SOAP request from a Silverlight app (which works as expected) I’ve narrowed it down to a difference in the XML request sent to the SOAP handler:
From Flex:
<tns:Value>DMS</tns:Value>
From Silverlight:
<d4p1:Value xmlns:d6p1="http://www.w3.org/2001/XMLSchema" i:type="d6p1:string">DMS</d4p1:Value>
If I take the request generated by Flex, catch it with Fiddler, modify that one line to include the “type” namespace – it works.
Anyone have an idea how I can get that namespace onto my variable that is passed to the SOAP handler from Actionscript? Here is my code for sending off that SetPropertiesForCurrentUser function:
var obj:Object = {};
obj["Key"] = "coordinateFormat";
obj["Value"] = DMS;
var profileService:WebService = new WebService();
profileService.useProxy = false;
profileService.SetPropertiesForCurrentUser.addEventListener("result",setPropertiesForCurrentUser_EventHandler);
profileService.addEventListener("fault",setPropertiesForCurrentUserFault_EventHandler);
profileService.loadWSDL(url);
profileService.SetPropertiesForCurrentUser(new ArrayCollection([obj]),false);
Thanks,
Josh
The default SOAPEncoder that is used is some what limited in its capabilities (like not including the type attribute you mentioned above). Luckily, there is a way to control that by writing your own encoder.
see this link at adobe (read part about using custom web service serialization) Link on Adobe's Site