Restlet WebService returning a PDF - restlet

I have a Restlet Web Service that is returning a PDF document and the client side needs to receive this docuement and display it.
Server Side Code:
orderNumber = f.getFirstValue(PARAM_ORDER_NUMBER);
orderType = f.getFirstValue(PARAM_ORDER_TYPE).toUpperCase();
String fileName = OrderDM.getPDF(orderNumber, orderType);
pdfRep = new FileRepresentation(new File(fileName), MediaType.APPLICATION_PDF, 0);
return pdfRep;
Client Side:
ClientResource client = getClientResource(PRINTER_FRIENDLY_DOCUMENT_RESOURCE);
Reference reference = client.getReference();
reference.addQueryParameter(PARAM_ORDER_TYPE, orderType);
reference.addQueryParameter(PARAM_ORDER_NUMBER, orderNumber);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
client.get().write(outputStream);
byte[] fileContent = outputStream.toByteArray();
Will this work and is this the best way to do this.

Related

What is the RabbitMQ message max size can stored?

We are uploading 23 mb text file RabbitMQ. We will convert that file to filestream and then we will bind that message to JSONObject.
var path = Server.MapPath("~/App_Data/" + fileName);
var excelFile = new FileInfo(path);
FileStream stream = System.IO.File.Open(path, FileMode.Open, FileAccess.Read);
// Added Code for CommandComponent changes Start
byte[] fileMessage = new byte[stream.Length];
stream.Read(fileMessage, 0, fileMessage.Length);
stream.Close();
TempData["FileMessage"] = fileMessage;
TempData["FileType"] = fileType;
System.IO.File.Delete(path);
// Added Code for CommandComponent changes End
return Json(new { Result = true }, JsonRequestBehavior.AllowGet);
By AMQP specification there is not limit. The body is a buffer where you can put what you prefer.
Obviously there is the network between your application and RabbitMQ and you can't send a big-file just with a simple send.
you have to implement some kind of the streaming

C# "The request was aborted: Could not create SSL/TLS secure channel." - happening occasionally

This is a request to GoCardless test API from a Dynamics CRM plugin. I receive "The request was aborted: Could not create SSL/TLS secure channel." error. It only happens on the first request after some time without sending one. If I send it again, it will be OK. I would appreciate a lot your help.
Here is my code:
//I have tried all the following lines in comment without success
//ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
//ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
//ServicePointManager.Expect100Continue = true;
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
// Create a new WebClient instance.
string baseURL = "https://api-sandbox.gocardless.com/";
WebClient client = new WebClient();
client.Headers.Add("Content-Type", "application/json");
client.Headers.Add("Authorization", "Bearer " + t);
client.Headers.Add("GoCardless-Version", "2015-07-06");
client.Headers.Add("Accept", "application/json");
Customers model = new Customers();
customer.country_code = "GB";
model.customers = customer;
MemoryStream stream1 = new MemoryStream();
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Customers));
ser.WriteObject(stream1, model);
stream1.Position = 0;
StreamReader sr = new StreamReader(stream1);
// Apply ASCII Encoding to obtain the string as a byte array.
byte[] byteArray = Encoding.ASCII.GetBytes(sr.ReadToEnd());
ReturnedCustomers result = new ReturnedCustomers();
//Upload the input string using the HTTP 1.0 POST method.
try
{
byte[] responseArray = client.UploadData(baseURL + "customers", "POST", byteArray);
string responseText = Encoding.ASCII.GetString(responseArray);
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ReturnedCustomers));
using (Stream s = GenerateStreamFromString(responseText))
{
result = (ReturnedCustomers)serializer.ReadObject(s);
}
}
catch (WebException exception)
{
}
From the Microsoft documentation (https://msdn.microsoft.com/en-us/library/gg334752.aspx) are the following limitations:
Only the HTTP and HTTPS protocols are allowed.
Access to localhost (loopback) is not permitted.
IP addresses cannot be used. You must use a named web address that requires DNS name resolution.
Anonymous authentication is supported and recommended.
5.There is no provision for prompting the logged on user for credentials or saving those credentials.
The error may be due to seguneti things:
The certificate is invalid
The certification authority is not public
Could you check what is the value of ServicePointManager.Expect100Continue and ServicePointManager.SecurityProtocol attributes in your environment?

SSRS Report executes directly but WCF ReportExporter.Export method returns null Result and no errors

I have a report that is hosted in SQL Server 2012 SSRS and it executes fine through the browser. I am trying to run it using WCF as a Service Reference for the SSRS 2005 asmx from a ASP.Net web project and return it as a PDF using the ReportExporter.Export() method; however, it is not returning a result at all and the warnings array is empty. So, how can I troubleshoot the process to see where the difficulty is? I did not find any errors in the SSRS Log file even when I set it to verbose; nor did I find any errors in the standard SQL Log.
Here is my code:
NOTE: the call ReportExporter.Export(..) is to a method that encapsulates the execution of the webServiceProxy to the Service Reference.
{
IList<SSRS_Reports.ParameterValue> parameters = new List<SSRS_Reports.ParameterValue>();
parameters.Add(new SSRS_Reports.ParameterValue { Name = "paramId", Value = _paramId.ToString() }); }
byte[] result = null;
string extension = string.Empty;
string mimeType = string.Empty;
string encoding = string.Empty;
string reportName = "/baseFolder/ReceiptReport";
SSRS_Reports.Warning[] warnings = null;
string[] streamIDs = null;
string uN = ConfigurationManager.AppSettings["rptUName"].ToString();
string uP = ConfigurationManager.AppSettings["rptPWD"].ToString();
string uD = ConfigurationManager.AppSettings["rptDomain"].ToString();
//NOTE: the call "ReportExporter.Export(..) is to a method that encapsulates the execution of the webServiceProxy to the Service Reference.
ReportExporter.Export("ReportExecutionServiceSoap",
new System.Net.NetworkCredential(uN, uP, uD),
reportName,
parameters.ToArray(),
ExportFormat.PDF,
out result,
out extension,
out mimeType,
out encoding,
out warnings,
out streamIDs);
if (result != null)
{
//create a file and then show in browser
_mPDFFile = randomName() + ".pdf";
_mPDFPath = HttpRuntime.AppDomainAppPath + "\\pdf\\" + _mPDFFile;
//clear files older than today
Lib.FileManager.ManageFiles(HttpRuntime.AppDomainAppPath + "\\pdf", "*.pdf", -1);
if (File.Exists(_mPDFPath))
{
File.Delete(_mPDFPath);
}
FileStream stream = File.Create(_mPDFPath, result.Length);
stream.Write(result, 0, result.Length);
stream.Close();
return true;
}
}

j2me google translate api

I really need an example how to translate a text with google translate API v2.
I have implemented already the following:
String googleUrl="https://www.googleapis.com/language/translate/v2?key=<My Key>";
googleUrl+="&q=";
googleUrl+=urlEncode(txtFeedback.getString());
googleUrl+="&source=";
googleUrl+=System.getProperty("microedition.locale").substring(0, 2);
googleUrl+="&target=en";
HttpConnection googlAPI = null;
DataInputStream dis = null;
StringBuffer response = new StringBuffer();
googlAPI = (HttpConnection)Connector.open(googleUrl);
googlAPI.setRequestMethod(HttpConnection.GET);
dis = new DataInputStream(googlAPI.openInputStream());
int ch;
while ((ch = dis.read()) != -1) {
response.append((char) ch);
}
String tt = response.toString();
tt = tt.substring(tt.indexOf("{"));
JSONObject js = new JSONObject(tt);
params +=js.getJSONObject("data").getJSONArray("translations").getJSONObject(0)
.getString("translatedText") + crlf;
but this code throws the Certificate exception: certificate was issued by an unrecognized entity
it throws the exception on my real device Samsung GT-S5230 as well as Emulator
Really need help.
If I do something wrong it would be great to get an example how to call the google translate API from j2me midlet.
A quick look shows you are accessing a https url:
String googleUrl="https://www.googleapis.com/language/translate/v2?key=";
using httpConnection
googlAPI = (HttpConnection) Connector.open(googleUrl);
Change that to HttpsConnection
HttpsConnection googlAPI = null;
...
googlAPI = (HttpsConnection) Connector.open(googleUrl);
and let's see how it goes.

WCF Client access with Message Contracts

I have a web service , i add some extra class which have message contract and after that it changed the way we access some of the methods( and i have not added message contract to these classes these are data contracts ), earlier i.e before we could create one object for request and response (like see the Before part) we are creating a single object for OrderStatusResponse Class. But if you see now the After(we have to create separate objects for request and response).
is this a side effect of enabling "Always generate message contract?"
Before
SmartConnect.Service1Client Client =
new SmartConnectClient.SmartConnect.Service1Client();
SmartConnect.OrderStatusResponse Status =
new SmartConnectClient.SmartConnect.OrderStatusResponse();
Status.UserID = "1234";
Status.Password = "abcd";
Status.SoftwareKey = "abc";
Status.OrderNumber = "1234";
Status = Client.GetOrderStatus(Status);
lbl_OS.Text = Status.Status.ToString();
lbl_RM.Text = Status.ReturnMessage.ToString();
After
SmartConnectRepublic.SmartConnectClient SmartClient =
new WCF_Client.SmartConnectRepublic.SmartConnectClient();
//SmartConnectRepublic.OrderStatusResponse Status =
new WCF_Client.SmartConnectRepublic.OrderStatusResponse();
WCF_Client.SmartConnectRepublic.GetOrderStatusRequest request =
new WCF_Client.SmartConnectRepublic.GetOrderStatusRequest();
request.status = new WCF_Client.SmartConnectRepublic.OrderStatusResponse();
request.status.OrderNumber = "1055055";
request.status.UserID = "1234";
request.status.Password = "dfsdfsd";
request.status.SoftwareKey = "sdfsdfsdfs";
WCF_Client.SmartConnectRepublic.GetOrderStatusResponse response =
new WCF_Client.SmartConnectRepublic.GetOrderStatusResponse();
response = SmartClient.GetOrderStatus(request);
lbl_Status.Text = response.GetOrderStatusResult.Status;
lbl_RC.Text = response.GetOrderStatusResult.ReturnCode.ToString();
lbl_RM.Text = response.GetOrderStatusResult.ReturnCode.ToString();
Yes, I suspect it is a difference with using message contracts. You seem to have figured it out, though.