Endeca Assembler: Customize response header - endeca

I want to insert a new (key -> value) pair in response header from Endeca Assembler. Is it possible to do this?
Thanks

First of all, I want to clarify some things because the terminology about Assembler can get a little confusing. I'm not sure how you have designed your program, but just keep in mind that Assembler is just a Java API, so it's kind of unclear to say something like "response header from Endeca Assembler". That statement seems to imply that Assembler is a webservice, but it isn't. In my experience, people commonly mistakenly refer to the discover-data (Discover service) example app as "Assembler" or "Assembler Service", but it really isn't a general-purpose webservice; it's designed as a reference application to be used specifically with the Discover dataset (But people still use discover-data as a starting point for building production-facing applications). So, bear in mind that I'm not exactly sure what you are referring to.
Anyway, somewhere in your code, you should have a call of something like "contentItem.assemble()", which runs your cartridge handlers on that content item and returns an object of type ContentItem. In the Discover webapp, it then serializes this content item to JSON or XML or renders a JSP page (depending on the request parameters). I assume your application does something similar.
It's a simple matter of adding properties to ContentItem, because ContentItem implements map. So, you can do something like this:
ContentItem responseContentItem = contentItem.assemble();
responseContentItem.put("myKey","myValue");
...continue by serializing responseContentItem or whatever you want to do with it

Do like this:
responseContentItem.put("key", "value");
as the resposne from Endeca Assembler is simply a Map.

Related

What is the ByteBuddy recipe for building an upper-bounded wildcard?

I know some of this, but not all of it. Most notably, I am aware of TypeDescription.Generic.Builder but I have a very specific question about it.
Suppose I want to build Supplier<? extends Frob<X>>.
Suppose further that all I know I have is a TypeDefinition for the parameter, but I don't know what it represents (in the example above it would represent Frob<X>). That is, I don't know whether the TypeDefinition I have is a class, a parameterized type, a generic array type, a type variable, a wildcard, or anything else; I just know it's a TypeDefinition.
Obviously if I wanted to make Supplier<Frob<X>>, I could just do:
TypeDescription.Generic.Builder.parameterizedType(TypeDescription.ForLoadedType.of(Supplier.class),
myTypeDefinition)
.build();
…assuming I haven't made any typos in the snippet above.
How can I make an upper-bounded wildcard TypeDefinition out of an existing TypeDefinition suitable for supplying as the "parameterized" part of a parameterized type build? Is there an obvious recipe I'm overlooking, or is this a gap in the builder's DSL?
(I'm aware of the asWildcardUpperBound() method on TypeDescription.Generic.Builder, but that presumes I have a builder to work with, and in order to "bootstrap" such a builder I would need to give it a TypeDescription at the very least. But I don't have a TypeDescription; I have a TypeDefinition which might be parameterized, and I don't want to use asErasure().)
(I'm sort of looking for a way to do TypeDescription.Generic.Builder.parameterizedType(myTypeDefinition).asWildcardUpperBound().build(), but I can't obviously do that.)
There does seem to be TypeDescription.Generic.OfWildcardType.Latent::boundedAbove but I can't tell if that's supposed to be an "internal use only" class/method or not.
Such an API was indeed missing. I added an API in today's release (1.11.5) to translate an existing generic type description to a builder what allows transformations to arrays or wildcards. The API is TypeDescription.Generic.Builder.of which accepts a loaded or unloaded generic type description.

Pretty Print object in Swift on debug area

I am new to swift. I am trying to find a way to accomplish that.
In objective-c project, when I NSLog a response body from api, I got something like this. its pretty and readable. Ojective-c Debug area
However, when i use swift, when I print a response body from api, I got something like that. It's super hard to read. Swift Debug area
is there any way in swift, i could see the same format in debug area same as objective-c project.
If anyone could help, I really appreciate.
Thanks in advance.
It mainly depends on what you're trying to print in the Debug area. From Apple docs:
Swift provides a default debugging textual representation for any type. That default representation is used by the String(reflecting:) initializer and the debugPrint(_:) function for types that don’t provide their own.
From the image you've linked, it looks like you're printing a Dictionary, which prints out like that and there's not a straightforward way to change it. Considering you're getting data from an API, you can do debugging in three ways:
Print the raw body: if your server is returning JSON, that's usually readable and, in case it isn't, there are many JSON formatters/viewers online.
Parse the response into instances of a class that you define as conforming to CustomDebugStringConvertible; then, print the resulting array. This will not work in case the server response is malformed.
Loop through the dictionary and manually print keys and values in a format that looks readable to you.

Creating an Objective-C API

I have never made an API in objective-c, and need to do this now.
The "idea" is that I build an API which can be implemented into other applications. Much like Flurry, only for other purposes.
When starting the API, an username, password and mode should be entered. The mode should either be LIVE or BETA (I guess this should be an NSString(?)), then afterwards is should be fine with [MyAPI doSomething:withThisObject]; ect.
So to start it [MyAPI username:#"Username" password:#"Password" mode:#"BETA"];
Can anyone help me out with some tutorials and pointer on how to learn this best?
It sounds like what you want to do is build a static library. This is a compiled .a file containing object code that you'll distribute to a client along with a header file containing the interface. This post is a little outdated but has some good starting points. Or, if you don't mind giving away your source code, you could just deliver a collection of source files to your client.
In terms of developing the API itself, it should be very similar to the way you'd design interfaces and implementations of Objective-C objects in your own apps. You'll have a MyAPI class with functions for initialization, destruction, and all the functionality you want. You could also have multiple classes with different functionality if the interface is complex. Because you've capitalized MyAPI in your code snippet, it looks like you want to use it by calling the class rather than an instance of the class - which is a great strategy if you think you'll only ever need one instance. To accomplish this you can use the singleton pattern.
Because you've used a username and password, I imagine your API will interface with the web internally. I've found parsing JSON to be very straightforward in Objective-C - it's easy to send requests and get information from a server.
Personally I would use an enum of unsigned ints rather than a NSString just because it simplifies comparisons and such. So you could do something like:
enum {
MYAPI_MODE_BETA,
MYAPI_MODE_LIVE,
NUM_MYAPI_MODES
};
And then call:
[MyAPI username:#"Username" password:#"Password" mode:MYAPI_MODE_BETA];
Also makes it easy to check if they've supplied a valid mode. (Must be less than NUM_MYAPI_MODES.)
Good luck!

Internationalization in VB.Net : Choosing the right structure type

I'm about to start translating my vb.net application, and I don't want to use the default methods provided by Visual Studio to do so. I need my application to be very light, and it nearly doubles it size to use the resources option.
Therefore, I'm planning to use some thing like a class, of which I would have one instance per language. Since I don't want to distribute language files as separate files (I'd rather have them hard-coded), I would like to find an easy way to check if every field of the class is initialized. I was thinking of something like an Interface, where I would do something like this:
Public Interface Language
Dim HelloMsg As String
Dim GoodbyeMsg As String
End Interface
Public class English Implements Language
HelloMsg = "Hello!"
GoodbyeMsg = "Goodbye!"
End Class
It's obviously not the right way to do it (although I could use properties instead of vars), but I was wondering whether the was a way to have the compiler check that everything is translated and warn about it if not.
Anyway, maybe is there a much better way to handle this problem ?
Thanks a lot!
CFP.
I'm not convinced that you should dump the resource-based localization approach just because your app has grown in size. Indeed, it could've grown from 100 Kb to 200 Kb, but this is it! It won't grow this much more. And 200 Kb is nothing nowadays.
So my advice is to reconsider and go resource-based route.
I've decided to use a singleton class that loads a translation file, with a method that loops through all items on a form and translate on-the-fly. See Create Synchronicity source code for more details (more specifically TranslateControl in this code file)

Intercepting Method Access on the Host Program of IronPython

Greetings,
Most of the information I see around concerning the construction of Proxies for objects assume that there exists a Type somewhere which defines the members to be proxied. My problem is: I can't have any such type.
To make the problem simpler, what I have is a dictionary that maps strings to objects. I also have getters and setters to deal with this dictionary.
My goal then is to provide transparent access inside IronPython to this getters and setters as if they were real properties of a class. For example, the following code in a python script:
x.result = x.input * x.percentage;
...would actually represent something like in the host language:
x.SetProperty("result", x.GetProperty("input") * x.GetProperty("percentage"));
Also, 'x' here is given by the host program. Any ideas? Please remember that I cannot afford the creation of a typed stub... Ideally, I would be happy if somehow I could intercept every call to an attribute/method of a specific object in the script language onto the host program.
This post might be useful.