OSB Java callout to core java class - osb

I have a simple java call out to decode a base64 string. The java looks like this
import javax.xml.bind.DatatypeConverter;
public final class DecodeBase64 {
public static byte[] decode(String base64string) {
return DatatypeConverter.parseBase64Binary(base64string);
}
}
Then I was thinking that since DatatypeConverter.parseBase64Binary is static why not call it directly. This way I can avoid having to deploy my jar.
I cannot however seem to find a way to call a core java class from the OSB java callout.
Is this possible? Is it even feasible?

I don't believe it would be possible to make that, as you can see from the documentation on Java Callouts, you first need to specify the .jar that you will use to make the callout. There's likely a ton of existing libraries, etc., in the classpath in OSB that Oracle et al wouldn't want to blindly expose, but I think you should be able to import and use in a .jar pretty easily.
Section 21.20 - Adding Java Callouts - http://docs.oracle.com/cd/E14571_01/doc.1111/e15867/proxy_actions.htm#i1321171

if you are looking to do Base64 conversion for setting Basic authorization while calling an external system or validating the input authorization header, then OSB has an inbuilt feature called "Service Accounts" which when combined with Business services / proxy services can convert your username / password into a Base64 format.
if you are looking to convert data into Base64 format for some other reason, then i am afraid, you cannot do so in OSB without making a java callout.

This is not possible . You have to import the jar

Related

APEX Rest API - Swagger

I am a bit new to the whole APEX service plugins but I was wondering if Salesforce has native support for Swagger, or any similar REST description language, for the REST api's that I create in the APEX service platform?
For example:
#RestResource(urlMapping='/v1/users/*')
global with sharing class UserRestService {
...
#HttpGet
global static List<Member__c> doGet(....)
{
...
}
}
I would like the ability to return the swagger json, a WADL document, or something for this REST service (and all other REST services I have in there). Does anyone know of a way I can do this?
Thanks in advance!
There is no built in support at this time. I was interested in seeing what could be done via currently available public APIs. The first thing I ran into is the grammar does not seem to like parameters to HttpGet methods. That right there will make it challenging since the only way to get input parameters appears to be via the Request entity which means you would have to parse the actual code. In other words, there does not appear to be declarative input binding.
Further, in looking at the tooling API which let's me get some amount of "reflective" information about the class, there is not always sufficient information to render a response payload (in your case, it just shows LIST but not what's in the list)
Again, it looks like one would have to rely on a parser (there is at least one Antl grammar floating around).
(this is getting some internal attention but I can't say any more at this time)

Twilio TwiML XML String instead of url

I want to call the twilio voice API without providing the URL.
Normally you would do it like this using python:
call = client.calls.create(url="http://demo.twilio.com/docs/voice.xml",
to=request.receiver,
from_=sender_number)
Instead of providing the URL I want to provide the XML-String. Is that somehow possible?
Background:
I'm generating the XML via a google cloud endpoints api. The response is in JSON format and a variable contains the XML. I need to parse the JSON to get the XML.
Sounds like you could use the echo Twimlet.
https://www.twilio.com/labs/twimlets/echo
Echo will just output whatever TwiML is passed into it via the URL. It is useful for building stateless, outbound apps, where arbitrarily complex content of the call is pre-generated and just passed into the REST API to initiate a call.
Example: http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3EHi+there.%3C%2FSay%3E%3C%2FResponse%3E
Twilio Evangelist here. I'm afraid you cannot do this, however there are a number of solutions. If your call doesn't require any dynamic XML, you can host it on S3, or a similar service (I use Dropbox public links quite a lot).
If you do need dynamic XML, then we have a whole bunch of tutorials that can help you get setup with a simple web application.
Hope this helps!

Eclipse doesn't generate google cloud endpoint client library

I'm trying to create my first GAE Endpoint app, and instead of generating an endpoint from a class, I'd like to create my own personalised Endpoint... is this possible?
I've written this class:
#Api(name="my_endpoint", path="my_endpoint")
public class MyFirstEndpoint {
#ApiMethod (name="my_method", path="my_method", httpMehod=HttpMethod.GET)
public Response myMethod(#Named("param1") String param1) {
...
}
}
But when I try to generate the Endpoint Client Library in Eclipse, it says that there was an error... and the worst thing is that it doesn't say what error it is!
Yes it's possible to create custom Endpoints.
I had the same error. I think you can't use "_" in the name of the Api nor the ApiMethod...
Try using "myEndpoint" and "myMethod" as the names and keep the "_" in the paths.
A bit unrelated to this particular case, but it's the first thing that popped up on Google when searching for the error: you can't have overloaded methods in your Endpoints classes. Found this by looking in the Error console as described above in a comment.

Has anyone used Enunciate to generate WADL for a RestEasy service?

There are two similar questions asked here and here but no adequate answers are given.
I found that I can use Enunciate to create WADL for a RestEasy service. So I tried it.
In one of my services I have a method mapped to HTTP GET which I am using like below
...
import org.jboss.resteasy.annotations.Form;
...
#GET
#Produces({MediaType.APPLICATION_JSON})
#Transactional(readOnly = true)
public WebServicePageResponse<D> find(#Form WebServicePageRequest<E> wsPageRequest)
{
...
}
Enunciate performs a validation on the service methods before it generates the WADL, and throws this error and fails
"A resource method that is mapped to HTTP GET must not specify an entity parameter."
#Form is a RestEasy specific annotation, while Enunciate can only parse JSR-311 annotations.
Has anyone done something similar? Has anyone successfully used Enunciate to generate documentation for a RestEasy service? Are there any alternatives?
Looks like a great suggestion for a new feature. Tracking it here.
It might be an awkward workaround, but have you tried using the signature override?
The best solution I found to this was to remove #Form annotation and use the individual annotations instead (enter link description hereatleast till Enunciate start supporting this).

GWT: Where (how) to define POJOs to make em available for client and server? (and to use datastore on serverside)

I try to get an application running which should interact with a server via RPC (JDO in Google DataStore). So I defined a persistent POJO on the server-side to get it put in the datastore via the PersistenceManager (as shown in the gwt rpc tuts). Everything works fine. But I am not able to receive the callback POJO on the client side because the POJO is only defined on server-side. How can I realize it, that the client knows that kind of object??
(sry for my bad english)
Lars
Put your POJOs in a separate package/directory (e.g. com.example.common) and then add source declaration to your GWT module descriptor (xyz.gwt.xml):
<source path="common"/> //relative to your xyz.gwt.xml location
GWT compiler will then also compile POJOs and they will be seen by your other GWT code.
Edited:
#Lars - now I understand your problem. As I see it you have several options:
If possible use Objectify instead of JDO. Objectify uses pure POJOs and they play nicely with GWT. I use this in my projects. One nice thing that Objectify gives you is #PostLoad & # PrePersist on methods to run some code before/after POJOs are loaded/saved to datastore. I use this to handle serialization of GeoPoint for instance.
Use JDO and make copies of your domain classes. This is a pain but it would work. Use 'transient' java keyword in your server JDO classes to exclude fields you do not want to RPC.
Edit #2: There is a third option that you might prefer:
Create "fake" JDO annotation classes using super-sourcing. This is a common technique to replace classes with a GWT version. Described here: http://fredsa.allen-sauer.com/2009/04/1st-look-at-app-engine-using-jdo.html
You can use DTO(stackoverflow, moar) for transferring data to client.
Basic sample here (method getTenLatestEntries() in your case).
Or you can use some third-party libraries like objectify and stop worry about making DTO`s.

Resources