Invoking a method using reflection with json data as argument
Hi,
I want to invoke a method using reflection and this method have one argument . Now I want to pass a json data as an argument to this method .Please see the following code.
int HelloWorld(int Id){
return Id;
json data{"Id":43}
how can I use the reflection to use the json.
Please provide your guidelines
Thanks for your reply, I am building a windows console application .And I want to convert the json data to object array to use in Method Base.Invoke method.
Regards,
Ethan
Maybe you could select the correct language development forum here:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=vslanguages&filter=alltypes&sort=lastpostdesc
Best Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.
Similar Messages
-
Difference between invoking a method using reflect.proxy and reflect.Method
Could any one tell me the difference between invoking a method using reflection java.lang.reflect.Method and java.lang.reflect.Proxy
using both the class, we can invoke a method at runtime
1)
Method mthd=cl.getMethod("methodName",parameterName);
Integer output=(Integer)mthd.invoke(new RunMthdRef(),input);
2)
Proxy.newProxyInstance(super.getClass().getClassLoader(), new Class[] { adapter }, new SomeClass(this));
Does anybody have any idea?The two idioms are fundamentally different. Using java.lang.reflect.Method is how we call a method on a class, using Proxy is how we intercept that method call. An exercise for you, to illustrate that they do not do the same thing: write a simple class with one method, then use java.lang.reflect.Method to invoke that method, and then use a Proxy to invoke that method
-
Can we invoke a method using BCEL(byte code engineering library)
Hi i am new in Java bcel,So can anyone guide me in this problem.
I am searching for some techniques in BCEL to invoke a method of some class just like we use to invoke methods using Java Reflection.I have also tried a Java Assembler named "Jasmin" that used to interact with Operand Stack,Local variable array & Constant Pool etc so i guess this is the same containers with which our BCEL also interact with so then i am wondering why not then there exists a way through which we can invoke a method using BCEL IF this will happen in any case then kindly point it out some direction of help.
thanks in advance856989 wrote:
I think i have clearly mentioned that "Tell me any way in doing this invocation in BCEL not in Reflection."
Why i not want to use reflection because it have "invocation overhead"Wrong.
If I dynamically load a class and reference it via a interface there is absolutely no difference in that and if I referenced the class statically and used it via an interface. The load and use process is exactly the same.
And the first uses "reflection".
If you use a proxy interface via something like java.lang.reflect.Method
then of course there is some overhead because there is in fact more classes involved. Just as if you had any other layer in any other code.
And even so unless you have actually profiled the application and found an actual bottleneck (and not just a measured impact) then even looking at it is a waste of time.
If it was me I would be far more concerned that inserting byte codes was correct for all cases. -
Query Not reflected with Updated Data
Dear Experts,
I am facing a Problem in query data updation. Data has been daily updating in infoprovider successfully ,But when user run query through Bex he is always shown old data. Then I go to RSRT and generate the query and data got updated.
Every Time for new data updation I need to Generate the query.
What could be reason for this. Is this related to cache data ?
Any Advise .
Thanks in Advance.Dear Michael,
This problem is coming only for one Multiprovider. Running this program would affect all other queries also . This will Delay the reporting.
Any other reason why query is reflected with old data Though infoprovide is loaded with new data. -
Use of "with master data & with out master data" at DTP update level
Hello experts,
In DTP, I check "with out master data". When I try to send corresponding transactional data, It is showing SID related error. Can anybody suggest what is the use of "with master data & with out master data" at DTP level.
Thanks in advance,
Zakir.HI
HI in DTP level If you set this indicator, the system terminates the update of the request if no values are available for a data record.
Load the relevant master data before you load the transaction data.
If you set this indicator, the system terminates activation if master data is missing and produces an error message.
If you do not set this indicator, the system generates any missing SID values during activation.
In DataStore maintenance, if you do not set the SIDs Generation upon Activation indicator, the No Update without Master Data indicator in the DTP has no effect.
thx
vijju -
What is the method used for upload of data
Hi All,
What is the method used for upload of Data from excel spread sheets to SAP HR.
it is Bulk Data from many countries.LSMW or BDC Session Method?
what are country specific infotypes used for PA and OM.
can u plz give the list of country specific infotypes used for PA n OM Module.
Thanks
ArchanaHi Archana,
To Upload bulk data I think BDC is the best and effecient way.
Regarding Infotypes we dont have any country specific Infotypes in OM & PA. In Payroll we do have according to country wise.
I hope you had understood the point
Regards
Pavani
Remainder: Points to be given on answers -
Any Examples of using ActiveCollectionModelDecorator with POJO data control
Are there any Examples of using ActiveCollectionModelDecorator with POJO data control in any of the sample packs?
OK, here's an quick example. Create a new Windows Forms application and add a ScatterGraph and a Label to the form. Add a cursor to the ScatterGraph, then add the code below to the form. This generates 50 random data points when the form is loaded and plots them, then uses the cursor's AfterMove event to display the current X and Y positions in the label. Here's the code:
Private Sub OnFormLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Const dataLength As Integer = 50
Dim xData(dataLength - 1) As Double
Dim yData(dataLength - 1) As Double
Dim rnd As Random = New Random
For i As Integer = 0 To dataLength - 1
xData(i) = i
yData(i) = rnd.NextDouble() * 10
Next
ScatterGraph1.PlotXY(xData, yData)
End Sub
Private Sub OnAfterMoveXYCursor(ByVal sender As Object, ByVal e As NationalInstruments.UI.AfterMoveXYCursorEventArgs) Handles XyCursor1.AfterMove
Label1.Text = String.Format("({0}, {1})", e.XPosition, e.YPosition)
End Sub
Hope this helps.
- Elton -
Hi,
Iam trying to invoke a private method of an object of some class thru reflection. Despite setting method.setAccessible( true), Iam not able to invoke the private method. Is invoking private methods via reflection not allowed at all?
thanks,This worked for me :
public class Test {
public static void main(String[] arg) throws Exception {
TestAccess t = new TestAccess();
Method m = t.getClass().getDeclaredMethod("foo", null);
m.setAccessible(true);
m.invoke(t, null);
class TestAccess {
private void foo() {
System.out.println("This is private");
} -
Can I invoke instance method using JNI pointer
Hi,
In my work, I need to pump data from dll to my java application.. for this I came to the following workaround.
1. Created a static method with (printMe()) in my java class (GrabTest.java)
public static int count = 5;
public static int printMe(int a)
System.out.println("result printMe : " + a);
return count--;
}2. Invoked this class object in dll side as follows
jclass cls = env->FindClass("GrabTest");
jmethodID mid = env->GetStaticMethodID(cls, "printMe", "(I)I");
jint count = env->CallIntMethod(cls, mid, 10);
cout<<"Count =" <<count<<endl;This works fine, i able to invoke the static method of GrabTest class from dll and I can pass an int value from there.
I tried to call a not static method which in GrabTest.java, from dll as follows
jmethodID mid2 = env->GetMethodID(cls, "printMe", "(I)I");
jint counter = env->CallIntMethod(cls, mid2, 10);
cout<<"Counter =" <<counter<<endl;when I try to invoke the instance method from dll, my application get crashes.
So, I would like know,
1. Is there any other way to pump data from dll side to the client application,
2. If i go with the static method to pump the data from dll, weather the other values of class variables of my GrabTest will give problem?
Looking for your guidance on this issue.
Thanks in advance,
Ramesh856989 wrote:
I think i have clearly mentioned that "Tell me any way in doing this invocation in BCEL not in Reflection."
Why i not want to use reflection because it have "invocation overhead"Wrong.
If I dynamically load a class and reference it via a interface there is absolutely no difference in that and if I referenced the class statically and used it via an interface. The load and use process is exactly the same.
And the first uses "reflection".
If you use a proxy interface via something like java.lang.reflect.Method
then of course there is some overhead because there is in fact more classes involved. Just as if you had any other layer in any other code.
And even so unless you have actually profiled the application and found an actual bottleneck (and not just a measured impact) then even looking at it is a waste of time.
If it was me I would be far more concerned that inserting byte codes was correct for all cases. -
My labview is Labview 2009 64 bit, I use PostLVUserEvent to post message with cluster data to labview. The following is the struct in dll:
typedef struct {
int32 dimSize;
uInt8 elt[1];
} TD1DINT8;
typedef TD1DINT8 **TD1DINT8Hdl;
typedef struct{
int32 interruptSource;
TD1DINT8Hdl portData;
}DIInterruptData, *PDIInterruptData, **HDIInterruptData;
In labview, the DIInterruptData corresponds to a cluster, in which there are a int32 integer and a uint8 array.
It works well in labview 32bit. But in labview 64bit, unhanlded exception occured. why?Hi Danil,
when complaining about double-posts one should provide a link to the other thread to guide other users...
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome -
I Want to graph useing MSGraph with array data
Hi..
I need to skill to graph using the msgraph with array data
My forte version 2.0h
E-MAIL ADDRESS : [email protected]
TEL(C) : 02)273-3131(5233), 0331)40-8366(ÇöÀç ¿©±â ÀÖ½¿)
PAGER : 015-959-9390
HAND PHONE : 011-411-9395
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>This #pdfloc data is generated by RMSDK when user highlight (annotation) pdf and keep it in XML format in file system: E.g.
<annotation y="-116" isvisible="False" x="-110" width="220" height="100">
<dc:identifier>urn:uuid:DF061693-A668-49DF-A20B-DE243C463919</dc:identifier>
<dc:date>2015-03-02T12:04:53Z</dc:date>
<dc:creator>creator id</dc:creator>
<dc:title>Page 4, 02-Mar-2015 5:34 pm</dc:title>
<target>
<fragment start="#pdfloc(7f54,3,37,0,0,0,0,1)" end="#pdfloc(7f54,3,37,3,1,0,1,1)">
<text>by Matt</text>
</fragment>
</target>
<content>
<dc:date>2015-03-02T12:04:53Z</dc:date>
<text></text>
</content>
</annotation> -
I m building a wcf service n exploring whether I should use JSON or XML. JSON will reduce payload size but I think xml is default config/setting. With JSON, do we need to do any additional setting?
my calling client is a windows service. Is JSON applicable only for web applications? Do I need to serialize in calling code before sending to service and then de-serialize again when service response come back?
thnx in advnce.Yes, json is better.
Vote if help you -
Unable to use transactions with System.Data.OracleClient data provider
I am using VS2008, System.Data.OracleClient, Oracle 10g, and ODAC 10.2.0.20. I haven't been able to get transactions to work. When I use 'connection.BeginTransaction()', the rollback doesn't work. When I use TransactionScope, the output parameter is always DBNull. Any ideas/comments?
Here's the sample code:
// #define ENABLE_TRANSACTION // failure is 'rollback not working'
#define ENABLE_TRANSACTION_SCOPE // failure is 'no output parameter value'
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Data.OracleClient;
#if ENABLE_TRANSACTION_SCOPE
using System.Transactions;
#endif
namespace TestOracleTransaction
class Program
static void Main(string[] args)
#if ENABLE_TRANSACTION_SCOPE
using (TransactionScope scope = new TransactionScope())
#endif
string connectionString = "Data Source=ORADEV;User ID=user;Password=pwd";
using (OracleConnection connection = new OracleConnection(connectionString))
try
connection.Open();
#if ENABLE_TRANSACTION
using (OracleTransaction transaction = connection.BeginTransaction())
#endif
try
#if ENABLE_TRANSACTION_SCOPE
if (Transaction.Current == null)
throw new ArgumentException("no ambient transaction found for OracleClient");
#endif
OracleCommand command = connection.CreateCommand();
#if ENABLE_TRANSACTION
command.Transaction = transaction;
#endif
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "TIS.P_TIS_GATEWAY_INFO_ADD";
OracleParameter param = command.CreateParameter();
param.ParameterName = "p_gateway_id";
param.Direction = ParameterDirection.Input;
param.DbType = DbType.Int64;
param.Value = 18;
command.Parameters.Add(param);
param = command.CreateParameter();
param.ParameterName = "p_info_id";
param.Direction = ParameterDirection.Input;
param.DbType = DbType.Int64;
param.Value = 79;
command.Parameters.Add(param);
param = command.CreateParameter();
param.ParameterName = "p_user";
param.Direction = ParameterDirection.Input;
param.DbType = DbType.String;
param.Value = "spms";
command.Parameters.Add(param);
param = command.CreateParameter();
param.ParameterName = "p_gateway_info_id";
param.Direction = ParameterDirection.Output;
param.DbType = DbType.Int64;
param.Size = sizeof(Int64);
command.Parameters.Add(param);
int count = command.ExecuteNonQuery();
object value = command.Parameters["p_gateway_info_id"].Value;
long id = (value == DBNull.Value) ? -1 : Convert.ToInt64(value);
if (id < 0)
// FAILURE - no output parameter value when TransactionScope enabled
throw new ArgumentException("no return value");
#if ENABLE_TRANSACTION
// FAILURE - rollback doesn't work when Transaction enabled
transaction.Rollback();
#endif
#if ENABLE_TRANSACTION_SCOPE
scope.Complete();
#endif
catch (Exception ex)
System.Console.WriteLine("ERROR: " + ex.Message);
#if ENABLE_TRANSACTION
transaction.Rollback();
#endif
finally
if (connection.State == ConnectionState.Open)
connection.Close();
}Hi,
First, this is not the place for questions with System.Data.OracleClient, this is the Oracle Data Provider for .NET forum. Having said that I went ahead and tested your code with some slight modifications because you did not provide the stored procedure information. I am assuming your stored procedure is doing some sort of DML since you are using transactions and attempting to commit and rollback.
I tested the following with both Transaction scope and a local transaction object and it worked fine with System.Data.OracleClient. I provided the create table and stored procedure I used.
Observations
========
When using transaction scope, a distributed transactions was executed and the data was inserted and returned in the output variable.
From console
p1 value is Hello World
From SQL Plus
SQL> select * from foo;
C1
Hello World
When using a local transaction, the DML was not inserted when calling rollback and when I changed it to commit, the row was inserted successfully.
Maybe you can test the simple foo example below to see if it works for you. Maybe there is something going on in your SP that is causing your specific observations.
The code I posted at this point is using local transaction and calling transaction.commit(), rollback is commented out. But I tested all scenarios and they worked as expected.
HTH
Jenny
#define ENABLE_TRANSACTION // failure is 'rollback not working'
//#define ENABLE_TRANSACTION_SCOPE // failure is 'no output parameter value'
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Data.OracleClient;
#if ENABLE_TRANSACTION_SCOPE
using System.Transactions;
#endif
create table foo (c1 varchar2(50));
create or replace procedure getstr (p1 out varchar2) as
begin
insert into foo(c1) values ('Hello World') returning c1 into p1;
end;
namespace TestOracleTransaction
class Program
static void Main(string[] args)
#if ENABLE_TRANSACTION_SCOPE
using (TransactionScope scope = new TransactionScope())
#endif
string connectionString = "Data Source=orcl;User ID=scott;Password=tiger";
using (OracleConnection connection = new OracleConnection(connectionString))
try
connection.Open();
#if ENABLE_TRANSACTION
using (OracleTransaction transaction = connection.BeginTransaction())
#endif
try
#if ENABLE_TRANSACTION_SCOPE
if (Transaction.Current == null)
throw new ArgumentException("no ambient transaction found for OracleClient");
#endif
OracleCommand command = connection.CreateCommand();
#if ENABLE_TRANSACTION
command.Transaction = transaction;
#endif
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "SCOTT.GETSTR";
OracleParameter param = command.CreateParameter();
param.ParameterName = "p1";
param.Direction = ParameterDirection.Output;
param.DbType = DbType.AnsiString;
param.Size = 20;
command.Parameters.Add(param);
int count = command.ExecuteNonQuery();
object value = command.Parameters["p1"].Value;
Console.WriteLine("p1 value is {0}",value.ToString());
#if ENABLE_TRANSACTION
// FAILURE - rollback doesn't work when Transaction enabled
transaction.Commit();
//transaction.Rollback();
#endif
#if ENABLE_TRANSACTION_SCOPE
scope.Complete();
#endif
catch (Exception ex)
System.Console.WriteLine("ERROR: " + ex.Message);
#if ENABLE_TRANSACTION
transaction.Rollback();
#endif
finally
if (connection.State == ConnectionState.Open)
connection.Close();
} -
All the examples in the text books, etc. show the LoadVars
object being used with a .txt file. Can I use it with a .xml file
or not? I have tried but the output panel just shows rubbish
data!LoadVars is not XML. You need to get a textbook that
discusses XML and
Flash.
The Flash documentation has excellent example for both
LoadVars and XML.
LoadVars:
http://livedocs.macromedia.com/flash/8/main/00002336.html
XML:
http://livedocs.macromedia.com/flash/8/main/00002879.html
With XML you have the additional task of parsing out the
data.
Lon Hosford
www.lonhosford.com
Flash, Actionscript and Flash Media Server examples:
http://flashexamples.hosfordusa.com
May many happy bits flow your way!
"Goo101" <[email protected]> wrote in
message
news:ec1iu6$m6j$[email protected]..
> All the examples in the text books, etc. show the
LoadVars object being
> used with a .txt file. Can I use it with a .xml file or
not? I have tried
> but the output panel just shows rubbish data! -
How to use EVS with different data in each row, in a Java Web Dynpro table?
Hi all,
I am using EVS in a column of java web dynpro table.
Let's say the name, and context attribute, of this column is column1.
It's filled dynamically using an RFC, that uses as input parameter the value of another column, and related context attribute, from the same table (Let's call it column2). Obviously, from the same row. So, in other words: the values of the EVS in column1 of row1, are dependent of the value of column2 of row1. And the values of the EVS in column1 of row2, are dependent of the value of column2 of row2. And so on... Hope i could explain myself ok.
The code I'm using works great for filling the EVS dynamically:
IWDAttributeInfo attrInfo = wdContext.nodeDetail().getNodeInfo().getAttribute(nodeElement.COLUMN1);
ISimpleTypeModifiable siType = attrInfo.getModifiableSimpleType();
IModifiableSimpleValueSet<String> value = siType.getSVServices().getModifiableSimpleValueSet();
value.clear();
if(this.initRFC_Input(nodeElement.getColumn2())){
for (int i = 0; i < wdContext.nodeRFCresult().size(); i++){
value.put(wdContext.nodeRFCresult().getRFCresultElementAt(i).getLgort()
, wdContext.nodeRFCresult().getRFCresultElementAt(i).getLgobe());
In this code, nodeElement is the context row of the table that is passed dynamically to the method when the value of colum2 is changed.
HOWEVER, the problem I'm having is that after executing this code, EACH NEW ROW that is added to the table has by default the same values as the first row, in the column1 EVS. And, for example, if I refresh the values of the column1 EVS in row 2, all EVS values in the other rows are also refreshed with the same values as the ones of EVS in row 2.
How can I make sure each row EVS has its own set of independent values, so they don't mess with each other?
Hope you guys can help me. And please, let me know if I didn't explain myself correctly!
Thanks!I just did as you said (I think), but it's still having the same behaviour as before (same data for all EVS in the table).
Here´s what I did:
I
In node "Detail" (cardinality 0...n, singleton set to true), which is binded to the table, I created a child node named "Column1Values" wth cardinality 1...1 and singleton set to false.
"Column1Values" node has an attribute called "column1", of type String.
I did the binding between attribute "column1" and the column1 inputfield celleditor in the table.
I created an event called Column2Changed and binded it to the column2 celleditor of the table. I added a parameter called nodeElement of type IPrivateCompView.IDetailElement to this event, and mapped it to the column2 editor in the table so that I can dynamically get the nodeElement that is being affected.
I added the following code to the onActionColumn2Changed(wdEvent, nodeElement) method that gets created in the view:
IWDAttributeInfo attrInfo = nodeElement.nodeColumn1Values().getNodeInfo().getAttribute("column1");
ISimpleTypeModifiable siType = attrInfo.getModifiableSimpleType();
IModifiableSimpleValueSet<String> value = siType.getSVServices().getModifiableSimpleValueSet();
if(this.initRFC_Input(nodeElement.getColumn2())){
for(int i =0; i < wdContext.nodeRFCresults().size(); i++){
value.put(wdContext.nodeRFCresults().getRFCresultsElementAt(i).getId(),
wdContext.nodeRFCresults().getRFCresultsElementAt(i).getDesc());
And with this, I still get the original problem... When the EVS of one row is updated, ALL other EVS of the table get also updated with the same values.
What am I missing? Sorry Govardan, I bet I'm not seeing something really obvious... hopefully you can point me in the right direction.
Thanks!
Maybe you are looking for
-
Trouble with Windows 8.1 and hp officejet 8620
Hi, we've installed a brand new hp Officejet Pro 8620. We've installed the full software package on a Windows 8.1 machine. It all seemed to be fine, but suddenly our machine is not capable of print on certain circumstances: - It can't print from: a)
-
IPhoto 6 and Nikon's Coolpix S6
Hello, I have the latest version of iPhoto, and I'm using Nikon's Coolpix S6 digital camera, which has a wireless transfer option built in, but I'm not sure how to transfer my pictures wirelessly to iPhoto. Can this be done? or am I stuck with the pr
-
Just updated to Yosemite, computer crashes everytime I unplug my WiMax from USB port
I have a MacBook Pro Retina, and updated from Mavericks OS X to Yosemite OS X. Ever since the update, my laptop crashes everytime I unplug my WiMax portable internet from USB port. The error message that appears says: "your computer restarted because
-
I have a 7th generation IPOD, I have downloaded APPLE ISTORE software and have downloaded 23 of my CD's. All of this is being done thru a Windows desk top. I can not get it to download automatically the CD's to my IPOD. Please advise
-
Okay so i had a blackberry curve 9300 it broke so i got the exact same phone from someone i know, on my old phone my emails were set up to come to my phone now on this phone it wont let me set up my email at all. The thing is i goto the setup and cli