I'm trying to access JSON on remote server. The code works on a local replica of the database but on the server there is a "HTTP Web Server: Command Not Handled Exception" error. I have lotusscript agents doing similar things so I am thinking it is a problem with java permissions on the server.
As far as I can tell I have all permissions on the server to run the code. I've tried putting the code in to Javascript and a Java managed bean so don't think it is an issue with the code.
The server is running 11.0.1FP1 (I've read there may be issues with pol files in 11)
Any help or hints would be greatly received
public String getJSON(String url)
{
String returnCode = url;
try {
String jsonTxt = null;
URL myURL = new URL(url);
HttpURLConnection myURLConnection = (HttpURLConnection) myURL.openConnection();
if (myURLConnection.getResponseCode() < 400) {
returnCode = "Connection made";
} else {
/* error from server */
jsonTxt = "Can not access remote server";
returnCode = "Connection not made";
}
myURLConnection.disconnect();
} catch(Exception e) {
e.printStackTrace();
}
return returnCode;
}
Related
I'm trying to connect my asp.net application to an Informix DB using ODBCconnection.
The problem that I'm facing is if the Informix Db is down, my application takes forever trying to establish the connection.
It seems that the ConnectionTimeout doesn't work for me..
The following is the code that is used.
private string StartTimerForTest()
{
string err = "";
OdbcConnection odbc_Conn = new OdbcConnection();
odbc_Conn.ConnectionTimeout = 1;
DataTable ConnDt = new DataTable();
FormDataTable(ref ConnDt);
LoadSagaConfig(ref ConnDt);
SetOdbcConnectionstring(ref odbc_Conn, ref ConnDt);
try
{
odbc_Conn.Open();
odbc_Conn.Close();
}
catch (OdbcException ex)
{
err = ex.Message;
}
return err;
}
Any help will be much appreciated.
The following code works perfectly fine from my own machine (Win7 ISS7) but when I move it to a virtual server running IIS8 on a datacentre then I get the return code 150 (openingdata). I can access the ftp site via IE on this server. Is this a coding issue or configuration. Any help is greatly appreciated.
I've also tried changing UsePassive, UseBinary, no caching, to no effect and place it on an azure machine but to no avail.
private List<string> Browse()
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(m_Url);
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
result.Add("Timeout = " + request.Timeout.ToString());
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential(m_Username, m_Password);
request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
if (m_Proxy != null)
{
request.Proxy = m_Proxy;
}
bool started = false;
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
{
Stream responseStream = response.GetResponseStream();
using (StreamReader reader = new StreamReader(responseStream))
{
string line = reader.ReadLine();
while (line != null)
{
result.Add(line);
line = reader.ReadLine();
}
}
}
return result;
}
Turned out it was a program error
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(m_Url);
should have been
FtpWebRequest request = (FtpWebRequest)*Ftp*WebRequest.Create(m_Url);
I am tring to list all the management certificates in a windows azure subcription. And I tried with the following code. But it gives me an exception. And I could find that response is null and the exception message is "The remote server returned an error: (403) Forbidden."
Please help me with this. Msdn doesn't provide an example for this :(
using System;
using System.Collections.Generic;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Xml;
using System.Xml.Linq;
class ManagemenCertificateViewer
{
public static void Runme()
{
string msVersion = "2012-03-01";
string subscriptionId = "I used the subscription Id here";
try
{
ListManagementCertificates(subscriptionId, msVersion);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught: ");
Console.WriteLine(ex.Message);
}
}
private static void ListManagementCertificates(string subscriptionId, string version)
{
string uriFormat = "https://management.core.windows.net/{0}/certificates";
Uri uri = new Uri(string.Format(uriFormat, subscriptionId));
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Method = "GET";
request.Headers.Add("x-ms-version", version);
request.ContentType = "application/xml";
XDocument responseBody = null;
HttpStatusCode statusCode;
HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
// GetResponse throws a WebException for 400 and 500 status codes
response = (HttpWebResponse)ex.Response;
}
statusCode = response.StatusCode;
if (response.ContentLength > 0)
{
using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
{
responseBody = XDocument.Load(reader);
}
}
response.Close();
if (statusCode.Equals(HttpStatusCode.OK))
{
XNamespace wa = "http://schemas.microsoft.com/windowsazure";
XElement storageServices = responseBody.Element(wa + "SubscriptionCertificates");
int mngmntCertificateCount = 0;
foreach (XElement storageService in storageServices.Elements(wa + "SubscriptionCertificate"))
{
string publicKey = storageService.Element(wa + "SubscriptionCertificatePublicKey").Value;
string thumbprint = storageService.Element(wa + "SubscriptionCertificateThumbprint").Value;
string certificateData = storageService.Element(wa + "SubscriptionCertificateData").Value;
string timeCreated = storageService.Element(wa + "TimeCreated").Value;
Console.WriteLine(
"Certificate[{0}]{1} SubscriptionCertificatePublicKey: {2}{1} SubscriptionCertificateThumbprint: {3}{1} certificateData{4}{1} timeCreated{5}{1}",
mngmntCertificateCount++, Environment.NewLine, publicKey, thumbprint, certificateData, timeCreated);
}
}
else
{
Console.WriteLine("List Management certificates returned an error:");
Console.WriteLine("Status Code: {0} ({1}):{2}{3}",
(int)statusCode, statusCode, Environment.NewLine,
responseBody.ToString(SaveOptions.OmitDuplicateNamespaces));
}
return;
}
}
Thanks it's working as I expected. I just add the following line and the Method 'GetCertificate(arg1)'
request.ClientCertificates.Add(GetCertificate(certThumbprint));
One more thing, in Msdn help guide there's a tag in respond body called
<TimeCreated>time-created</TimeCreated>
But the api responds not the TimeCreated its just created.
<Created> ..... </Created>
403 error means something wrong with your management certificate used to authenticate your Service Management API requests. I don't see you attaching a management certificate along with your request in your code. You may find this link useful for authenticating service management API requests: http://msdn.microsoft.com/en-us/library/windowsazure/ee460782.
HTH.
I am using SharePoint foundation. I have a console application that is used to run some OCR process. I am calling the exe of the console application from windows service and it is working fine. I am trying to call the same exe from an event receiver but unable to call the exe and getting some error. The Event receiver is working fine but unable to call exe. I have tried to call the other exes like notepad.exe but getting same error. The details are below:
Code:
public override void ItemAdded(SPItemEventProperties properties)
{
try
{
base.ItemAdded(properties);
Log("Event Occured.");
string OCRedText = string.Empty;
string Listname = properties.ListTitle;
string itemName = Convert.ToString(properties.ListItem["Name"]);
string itemTitle = Convert.ToString(properties.ListItem["Title"]);
callService(); // Here is the method to call Process
SPListItem item = properties.ListItem;
if (System.Threading.Monitor.TryEnter(myLock, TimeSpan.FromSeconds(100)))
{
if (Convert.ToString(item["OCRed"]) == "False")
{
item["OCRed"] = "True";
Thread.Sleep(10000);
item.SystemUpdate();
Log("Item Added and Updated.");
}
else
{
Log("Can not update the Item.");
}
}
Log("Event End."+"\r\n");
}
catch (Exception ex)
{
Log("Error in Item Added Event Receiver.");
Log(ex.ToString());
}
}
public void callService()
{
Log("Calling Service is not easy.");
try
{
ProcessStartInfo pinfoService = new ProcessStartInfo();
pinfoService.FileName = #"D:\Khan\khan.exe";
//pinfoService.FileName = #"C:\Windows\System32\notepad.exe";
pinfoService.UseShellExecute = false;
pinfoService.RedirectStandardError = true;
pinfoService.RedirectStandardInput = true;
pinfoService.RedirectStandardOutput = true;
pinfoService.CreateNoWindow = true;
pinfoService.WindowStyle = ProcessWindowStyle.Hidden;
Log("FileName: " + pinfoService.FileName);
Log("Arguments for callService : "+pinfoService.Arguments);
Process pService = new Process();
pService.StartInfo = pinfoService;
Log("Process Before Start.");
Thread.Sleep(5000);
pService.Start();
Thread.Sleep(2000);
Log("Process Before wait for exit.");
pService.WaitForExit();
Log("Process Completed.");
}
catch (Exception ex)
{
Log("Error in callService(). Please contact your Administrator.");
Log(ex.ToString());
}
}
and below is the error I am getting on pService.Start();
=========================================
Info : Process Before Start.
Info : Error in callService(). Please contact your Administrator.
Info : System.ComponentModel.Win32Exception: Not enough quota is available to process this command
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at OCRonUploadDoc.EventReceiver1.EventReceiver1.callService()
=========================================
I am unable to figure out the issue. Please help me...!!!
Thanks in Advance.
Khan Abubakar
I think that the asp.net account under which the application pool runs does not have permissions to start the exe file. You can check this out http://www.daniweb.com/web-development/aspnet/threads/386380/cannot-run-exe-files-in-asp.net-application
However if your system will be used by more users you can run into problems really quickly, because every change of a document will spawn a new process. The server will run out of ram and the farm will not be unavailable.
I have the following code in groovy
HTTPBuilder http = new HTTPBuilder("https://ronna-afghan.harmonieweb.org/_layouts/searchrss.aspx")
http.request(Method.GET, groovyx.net.http.ContentType.XML) {
// set username and password for basic authentication
// set username and password for basic auth
//http.auth.basic(ConfigurationHolder.config.passportService.userName,
// ConfigurationHolder.config.passportService.password)
headers.'User-Agent' = 'Mozilla/5.0'
uri.query = [k:'execution']
// response handler for a success response code:
response.success = {resp, xml ->
println resp.statusLine
log.debug "response status: ${resp.statusLine}"
log.debug xml.toString()
}
// handler for any failure status code:
response.failure = {resp ->
log.error " ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"
}
}
when I run the code, it doesn't give me the rss feed which I'm suppose to get
When I have the same code in java
try {
// Create a URLConnection object for a URL
URL oracle = new URL(
"https://ronna-afghan.harmonieweb.org/_layouts/srchrss.aspx?k=execution&count=1&format=rss");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
it returns the xml Rss. I can't figure what the issue might be. Everything looks okay to me in the groovy code and also the Http return code is 200.
The code that you have described in Java is the equivalent of the following code in Groovy:
def oracle = "https://ronna-afghan.harmonieweb.org/_layouts/srchrss.aspx?k=execution&count=1&format=rss".toURL().text