1) Hello I am trying to use the admin services to create an Proxy inside the ESB.
So I have exposed the admin services (Hidden=false)
I have imported the WSDl in my Java project https://localhost:8243/services/ProxyServiceAdmin?wsdl
But I cannot workout how to call the method addProxy am I using the wrong admin service? Please help with an example of consuming this method.
ProxyServiceAdmin ps = new ProxyServiceAdmin();
ps.addProxy(); //wrong
2) I have a proxy defined as a one-line String, like
String xmlproxy="<?xml version='1.0' encoding='UTF-8'?><proxy xmlns='http://ws.apache.org/ns/synapse' name='MyProxy1' transports='https' startOnLoad='true' trace='disable'> <target inSequence='sequence1'>...."
Is it possible to add this Proxy by calling some method of the admin services?
thanks a lot for your attention!
EDIT I had a look at the WSDL "ProxyServiceAdmin?wsdl"
it says <wsdl:operation name="addProxy"><http:operation location="addProxy"/><wsdl:input><mime:content type="text/xml" part="parameters"/></wsdl:input><wsdl:output><mime:content type="text/xml" part="parameters"/></wsdl:output>
so it is there, but why I cannot call it? Why my code does not work as a normal Web Service would? Really, please help. I don't get what i am doing wrong...
ProxyServiceAdmin ps = new ProxyServiceAdmin();
ps.addProxy(); //not recognized as an operation of ProxyServiceAdmin even if it is in the wsdl
You simply have to use "org.wso2.carbon.proxyadmin.stub.ProxyServiceAdminStub" to ad proxy by admin services
Please have a look at following code and comments inline.
String endPoint = *<your backend service url>* +"ProxyServiceAdmin";
proxyServiceAdminStub = new ProxyServiceAdminStub(endPoint);
You have to authenticate your service stub before make any use of it
CarbonUtils.setBasicAccessSecurityHeaders(userName, password,
proxyServiceAdminStub._getServiceClient());
Need to generate ProxyData object of your proxy as synaps xml
String[] transport = {"http", "https"};
ProxyData data = new ProxyData();
data.setName(proxyName);
data.setWsdlURI(*<url to your WSDL>*);
data.setTransports(transport);
data.setStartOnLoad(true);
data.setEndpointXML("<endpoint xmlns=\"http://ws.apache.org/ns/synapse\"><address uri=\"" + serviceEndPoint + "\" /></endpoint>");
data.setEnableSecurity(true);
proxyServiceAdminStub.addProxy(data);
Thank You,
Dharshana
please find the sample to create a proxy using admin service here. I added Darshana's code to a complete example.
This is the JSP page is used for creating a pass through proxy. You can fill your proxy data similar to that. if you browse the other jsps you can find similar logics used for different proxy templates. Here you can find the complete module, both UI and Service code.
Related
I am implementing a TV listing service and I have decided to use ROVI as my data provider.
They provide me with an API that allows me to exchange data between my application and their servers by means of SOAP requests.
Since I am programming in Java, I used wsimport to generate the classes that would enable me to interact with their server.
//Connection
service = new ListingsService();
port = service.getListingsServiceSoap();
I have come across a problem which Google doesn't seem to have the answer for.
According to their API, whenever I want to make a call to a SOAP service I have to add my API Key to the end of url.
The problem is, I don't know how to do that. Using the stubs generated by wsimport, I can create a request object as it should be; however the URL is not displayed as per their specification. The url I currently get is: http://api.rovicorp.com/v9/listingsservice.asmx and what is required is: http://api.rovicorp.com/v9/listingsservice.asmx?apikey=myAPIkey. I obtained that by printing the following code:
System.out.println(port.toString());
Trying to run the following code:
GetServicesRS servicesRS = port.getServices(getServicesRQ, auth)
Yields the following error:
Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 403: Forbidden
What java method can I use to append this parameter into the SOAP request URL.
Thanks for your help.
Edit.
I am still struggling with this and haven't been lucky with responses, if anyone could point me in the direction of a framework or something that could facilitate this would be great!
Cheers
I manage to work around my problem using something called BindingProvider.
I added the following to my code:
//Connection
service = new ListingsService();
port = service.getListingsServiceSoap();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext()
.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://api.rovicorp.com/v9/listingsservice.asmx?apikey=" + APIKey);
With the aforementioned code the call to the API is successful:
GetServicesRS servicesRS = port.getServices(getServicesRQ, auth)
Hope it helps someone in the future.
I have a WCF service deployed at a certain server.
I need to call it through the JAVA application, when i am checking the parameter for this OperationContract is being passed correctly from java side but when i am logging the parameter value in WCF service, it seems not to be received here.
We are using 'basicHttpBinding' only and the attributes set for the Service and OperationContracts are as follows :-
[ServiceContract]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[XmlSerializerFormat(Style = OperationFormatStyle.Rpc, Use = OperationFormatUse.Encoded)]
public interface IMyService
{
[WebMethod]
[OperationContract(Action = #"http://tempuri.org/GetString")]
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped)]
string GetString(string strParameters);
}
Can any body check if this is correct or may suggest with all the steps so that a WCF can be accessed properly through JAVA application ?
For REST ful WCF, try using WEbHTTPBinding rather basic HTTP. REST WCF support WebHTTPBindings
WebInvoke attribute is not used for BasicHttpBinding (It is for webhttpBinding). You can take that out. One way to diagnose is open config in wcf config editor (SvcConfigEditor.exe). Enable tracing (search for enabling wcf tracing), make a request to service which will generate trace file. Check the log in Trace viewer (svtraceviewer.exe). You will find place where it is failing.
I am using wsdl2java to generate my java stub code for a web service.
I know it has been a bug since 1.4 that a wsdl source that requires HTTP basic auth could not be accessed. You will receive a 401 error because authorization was denied and there is no way to specify credentials.
Does anyone know if this issue was resolved or has someone a workaround for this? I could setup a proxyy server probably, but this is too much hassle for me, I am seeking something simple :)
you can try as this
...
serviceStub = new TestBeanServiceStub("<WEB SERVICE URL>"); // Set your value
HttpTransportProperties.Authenticator basicAuthenticator = new HttpTransportProperties.Authenticator();
List<String> authSchemes = new ArrayList<String>();
authSchemes.add(Authenticator.BASIC);
basicAuthenticator.setAuthSchemes(authSchemes);
basicAuthenticator.setUsername("<UserName>"); // Set your value
basicAuthenticator.setPassword("<Password>"); // Set your value
basicAuthenticator.setPreemptiveAuthentication(true);
serviceStub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, basicAuthenticator);
serviceStub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, "false");
...
As a workaround, I downloaded the wsdl file manually (using my browser) and saved it along with my code, and pointed wsdl2java to my local copy.
You can pass username and password in URL like this: http://username:password#example.com/wsdl
It works for me in axis: 1.7.9
I want to auto tweet from a java application. What is the simplest way to do it? Can i avoid using libraries like Twitter4j etc.,
I need an implementation for a simple api like
Tweet(username, password, message)..
Thank you.
I recommend you to use twitter4j and using this you can create oAuth requests easily.
Twitter rate limits apply to desktop application and it is 150/hour.
Twitter does not support basic authentication with username and password anymore.
You are required to create an application in twitter and using the consumer key and secret only you can access your twitter account.
If you are going to access the twitter by a desktop application then you have to select
Application Type: as "Client" while creating the application.
Then you can use the syntax below to update your status in twitter
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(consumerKey)
.setOAuthConsumerSecret(consumerSecret)
.setOAuthAccessToken(oAuthAccessToken)
.setOAuthAccessTokenSecret(oAuthAccessTokenSecret);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
twitter.updateStatus("This is a test message"); //ThrowsTwitterException
I hope this helps you... Please let me know if this is not the answer you were looking for.
Implementing your own oAuth request involve creating signature that for me was complicated and it is sensitive to time and time format that we send.
Twitter has a REST web API, and a lot of documentation. For reference:
http://dev.twitter.com/doc
While you don't necessarily need Twitter4J, it does make it easier. Otherwise you would need to assemble your own URL requests and take care of authentication. They offer more than one style:
http://dev.twitter.com/pages/auth_overview
Traditionally, OAuth is the preferred style for desktop application to web server integration--but that protocol is a bit complicated.
There's nothing that says you can't create your Tweet() method to hide away the details of using Tweet4J or hand-rolling the request yourself.
I want to auto tweet from a java
application.
I hope you are not spamming.. :D
Try this one: http://code.google.com/p/java-twitter/
You can wrap the example code into:
public void tweet(String username, String password, String message){
Api api = Api.builder().username(username).password(password).build();
api.updateStatus(message).build().post();
}
And then call it as tweet.(username,pass,message)
Looks simple to me.
Spring Social? I saw a demo of it at SpringOne - looked pretty cool, although I personally do not have a use for it, and therefore haven't done much besides read about it. You get some OAuth capability and templates for interacting with the major social networking sites out of the box.
My problem is I get error while trying to get request token from Yahoo. The error says Im missing oauth_callback parameter and yes I miss it because I dont need it. Ive read I need to set it to "oob" value if I dont want to use it(desktop app). And I did that but to no avail. If I set it to null the same happens. Im using OAuth for java: http://oauth.googlecode.com/svn/code/java/core/
OAuthServiceProvider serviceProvider = new OAuthServiceProvider("https://api.login.yahoo.com/oauth/v2/get_request_token",
"https://api.login.yahoo.com/oauth/v2/request_auth",
"https://api.login.yahoo.com/oauth/v2/get_token");
OAuthConsumer consumer = new OAuthConsumer("oob", consumerKey, consumerSecret, serviceProvider);
OAuthAccessor accessor = new OAuthAccessor(consumer);
OAuthClient client = new OAuthClient(new HttpClient4());
OAuthMessage response = client.getRequestTokenResponse(accessor, OAuthMessage.POST, null);
System.out.println(response.getBodyAsStream());
Have you tried using Scribe?
I also had problems with OAuth java libs so I developed that one. It's pretty much cross provider and better documented than the one you're using.
If it does not work with Yahoo you can easily extend it creating your own Provider
Hope that helps!
there is a problem in the java OAuthMassage class, I resolved it by adding to addRequiredParameters method thie line
if (pMap.get(OAuth.OAUTH_CALLBACK) == null) {
addParameter(OAuth.OAUTH_CALLBACK, consumer.callbackURL);
}
if you still have this problem I can help you: rbouadjenek#gmail.com
I haven't used that library, but it looks like it isn't properly handling the callback URL. Since OAuth 1.0a (http://oauth.net/advisories/2009-1/ and http://oauth.net/core/1.0a/), the callback URL needs to be sent in the first call to get the request token (not in the client-side call to authorise it), and it seems that this library hasn't been updated to do this (at least from looking at the code). I assume that Yahoo requires the parameter to be there.
Not sure if the original problem was ever solved, but wanted to point to a new Java OAuth SDK that Yahoo released last week:
http://developer.yahoo.net/blog/archives/2010/07/yos_sdk_for_java.html
Developers trying to access Yahoo's services via OAuth with Java may find parts of this SDK helpful.