Call SimpleDateFormat From JNI - java-native-interface

im not much familiar with Jni
can anyone help to convert this code in Jni.
public static void getTime(String zone,String format){
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
dateFormat.setTimeZone(TimeZone.getTimeZone(zone));
String statusDate = dateFormat.format(new Date());
System.out.println(statusDate);
}

Related

Is there any other way to put parameter of MockMVC?

I am currently testing api endpoints using Spring MockMvc and junit.
It just works fine with the following code.
public void testGetMethod(String url, String locale, String empKey, String accessToken) throws Exception {
mockMvc.perform(get(url).param("locale", locale).param("empKey", empKey).param("accessToken", accessToken))
.andDo(print())
.andExpect(status().isOk());
}
But the thing is when I am trying to modify this code
as follows (for setting parameters with .properties file later),
I am getting 400 code with message, "Required String parameter 'locale' is not present".
public void testGetMethod_param(String url, String locale, String empKey, String accessToken) throws Exception {
MultiValueMap<String, Object> paraMap =new LinkedMultiValueMap<>();
paraMap.add("locale", locale);
paraMap.add("empKey", empKey);
paraMap.add("accessToken", accessToken);
mockMvc.perform(get(url))
.andDo(print())
.andExpect(status().isOk());
}
Can anybody point out what I'm doing wrong here?
You need to add the paraMap to the get request.
mockMvc.perform(get(url).params(paraMap))
.andDo(print())
.andExpect(status().isOk());

What is the reference type for Node-FFI for a c++ file pointer?

I can't figure out which 'ref' module type to use in this situation.
I have a DLL function that returns a bool and takes a file pointer as a parameter:
__declspec(dllexport) BOOL __stdcall GB_Build( FILE *fname )
{ return Greenhouse.Build(fname) == true ? TRUE : FALSE; }
And a Node-FFI binding:
var ffi = require('ffi');
var ref = require('ref');
var greenbuildlib = null;
greenbuildlib = './PGD/GreenBuild_DLL.dll';
var greenbuild = ffi.Library(greenbuildlib, {
"GB_GetBayLength": ['double', []],
"GB_SetBayLength": ['void', ['double']],
"GB_Build": ['bool', [ref.types.Object]],
});
module.exports = greenbuild;
The "GB_Build" function creates a json file, and returns a bool based on if the file was created or not. fname stands for "file name" and is a C++ nullptr in the C++ code within the DLL.
I am wondering what the ref.type would be to properly pass a file pointer in Node-FFI. I've tried null pointers, null, string, and Object, but all of them crash the application when I try this in the client-code:
var file_name = "test.json";
greenbuild.GB_Build(file_name)
Thank you for any help. I couldn't find another question on stackoverflow about file pointers in Node-FFI.
For anybody else with this problem, since this question got no responses, the answer seems to be that Node-FFI does not have a file pointer at all. You must change the source code for C or C++ to use char * instead.

WSDL imported with C++ Builder Wizard (C++ Builder Xe6 Pro)

i am pretty lame with using wsdl importer wizard with c++ Builder (XE6 Pro)
but finnally managed to properly import EBAY WSDL:
http://developer.ebay.com/webservices/latest/ebaySvc.wsdl
I can successfully run simple calls, but problem arises , when trying to set (or get )
Enum values.
At this point i am getting beautifull access violation after compilation.
Relevant piece of code:
void __fastcall TEbay::IndexBClick(TObject *Sender)
{
CallName="GetMyeBaySelling";
UnicodeString PUrl = MakeLink();
_di_eBayAPIInterface EbayCall = GeteBayAPIInterface(false,PUrl,HTP1);
CustomSecurityHeaderType *HDR = new RequesterCredentials;
HDR->eBayAuthToken=AuthToken;
HDR->Credentials = new UserIdPasswordType();
HDR->Credentials->AppId=AppId;
HDR->Credentials->DevId=DevId;
HDR->Credentials->AuthCert=CertId;
_di_ISOAPHeaders headers = EbayCall;
HTP1->SOAPHeaders->Send(HDR);
HTP1->SOAPHeaders->SetOwnsSentHeaders(True);
//GeteBayOfficialTimeRequest TR = new GeteBayOfficialTimeRequestType();
GetMyeBaySellingRequest *TR = new GetMyeBaySellingRequest();
GetMyeBaySellingResponse *ER =new GetMyeBaySellingResponse();
//ShowMessage(PUrl);
TR->Version=Version;
TR->ErrorLanguage="en_GB";
// This one raises error
TR->SoldList->OrderStatusFilter=OrderStatusFilterCodeType::All;
ShowMessage("2");
ER = EbayCall->GetMyeBaySelling(TR);
TDateTime ACK = ER->Timestamp->AsDateTime;
ShowMessage(UnicodeString("ODP:")+ACK);
// EbayCall->GeteBayOfficialTime(ER);
delete TR;
delete ER;
delete HDR;
}
Violation comes when i try to set up OrderStatusFilter or any enum values.
Declaration: (ebasvc.h) :
enum class OrderStatusFilterCodeType /* "urn:ebay:apis:eBLBaseComponents"[GblSmpl] */
{
All,
AwaitingPayment,
AwaitingShipment,
PaidAndShipped,
CustomCode
};
class OrderStatusFilterCodeType_TypeInfoHolder : public TObject {
OrderStatusFilterCodeType __instanceType;
public:
__published:
__property OrderStatusFilterCodeType __propType = { read=__instanceType };
};
I am getting mad allready with this, could anybody help me run this $#&^#$&^ ??
Best regards
TR->SoldList->OrderStatusFilter=OrderStatusFilterCodeType::All;
Looks like you are trying to assign a value to a property on the SoldList object, yet I can't see where you have created that object. Try the following.
TR->SoldList = new ItemListCustomizationType();
TR->SoldList->OrderStatusFilter=OrderStatusFilterCodeType::All;

Playframework 1.2.4: get the results of render() as a String?

In a play framework 1.2.4 Controller, is it possible to get the contents of a template or tag as a String before output to the browser?
I want to be able to do this:
String json = renderAsString("/path/to/template.json", var1, var2);
//then use json as the body of a Play.WS request body.
The solution is based on the assumption that you are talking about PlayFramework 1.x
If you are using Groovy template engine:
Map<String, Object> args = ...
Template template = TemplateLoader.load("path/to/template.suffix");
String s = template.render(args);
And you have a shortcut way if you are using Rythm template engine:
String s = Rythm.render("path/to/template.suffix", param1, param3...);
Or you can also use named arguments:
Map<String, Object> args = ...
String s = Rythm.render("path/to/template.suffix", args);
Note the Groovy way also works for Rythm if your template file is put under app/rythm folder.
In addition to green answer.
If creating a json is what you want you would better use gson rather than building your own string with groovy templates. Gson is included in Play Framework 1.2.X.
You can find more information here. Example from Gson doc:
class BagOfPrimitives {
private int value1 = 1;
private String value2 = "abc";
BagOfPrimitives() {
// no-args constructor
}
}
BagOfPrimitives obj = new BagOfPrimitives();
Gson gson = new Gson();
String json = gson.toJson(obj);
//json is {"value1":1,"value2":"abc"}
You can also use Flexjson instead of gson.

Webmethod call from a C++ ATL console Application

I am trying to call a .net webservice from a C++ ATL console Application. This is how my webmethod looks like:
[WebMethod]
public string[] GetFieryIP(string companyname)
{
IpAddress = new string[]{"1","2","3","4"};
return IpAddress;
}
In the c++ application, I have added a web reference.This is how i am accessing the webmethod:
BSTR str = SysAllocString(L"");
BSTR *ptr = new BSTR[4];
int ptr1;
HRESULT hr = ws.GetFieryIP(str, &ptr, &ptr1);
ws is the webservice proxy.
Is this correct? If yes, How do i get the IpAddress from the *ptr. I am new to C++ and dont have much idea abt pointers and COM.Please help.