Test Web services - php

I would like to test my web services (wsdl/soap/php) that is exposed to my clients. ihave test it with the browsers and it's good, but when my clients test it , they have the 400 bad request error.( they test with soapui). what are the tools that i can test my web services that it exposed to my clients ? How can i verify that my server apache responds very good to http calls ?
Thanks for your answers.

You are in an integration scenario: you've published an interface and some code over which you have no control is trying to use it.
Web Services, even simple ones, let along the full panoply of WS-* capabilities are notorious for subtle interoperability problems. These especially come from small version skew issues.
I see two fundamental philosophies here, I'm rather over-stating, to make the point:
You say: I publish this interface, with this WSDL, this version of the WS specs, I test it with this message and it works. You clients are responsible for creating a conformant request. I've given you a sample, it's up to to fit me. Your responsibilities are limited to producing clear working sample messages.
You take responsibility for conducting interoperability testing for some set of client technologies. You clearly can't test everything, but if you some key "customers" you get or build sample applications and make sure they work. You probably end up documenting "use these options when generating client code".
Either way I'd suggest you need to write test clients of your own, and as a Java developer I use JUnit for that. This get's me to step 1 above.

Related

Azure with API for WPF and javascript

I want to create following project :
Server application hosted on Azure - it connects to databse via Entity framework and gives and API for anyone who want to connect (but with account stored in SQL database)
WPF application - it consumes server methods, objects etc.
Web app (php & javascript) - also consumes server methods and object etc.
IMPORTANT : I have only azure student's subscription and I want to hold onto it - buying anything else is out of the question unless it has strong argumentation.
I figured that to do this I have to create REST Web API because I have no other choice to connect to server than via HTTPWebRequest (because I want to have the same API for WPF nad web app).
My question is : does better solution exists?
I think I can create different API's for desktop client than web app but I have no idea how to do that. Whould you be so kindly to show me other way?
Why dont I want to have this solution?
Reason is simple. For big databases and slow internet connection it would take ages to download whole data in few seconds. As far as my knowledge goes there is no lazy loading in REST thus my WPF application's thread reponsible for downloading database would freeze for a big period of time.
If my question is too broad please leave a comment before you put up a flag.
Also, any tips regarding my project design are well appreciated.
Different APIs for Desktop and Web: this can be done easily enough. Assume you have a class library to contain your business logic (domain stuff). Create a web api project that makes use of it, then create yet another web api project separately that also makes use of the core models. When you deploy, deploy each separately to a different domain/subdomain (I'm unsure if you'll require further Azure resources for this, but consider api.desktop.myapp.com and api.web.myapp.com... no real technical reason why you can't do it that way, though for architecture reasons I'd avoid it (it's really coming close to if not definitely is duplication of code).
Same API for Desktop and Web: you stated that you thought you'd have to do this differently for the desktop and web, specifically because of the resource usage on the server. I disagree here, and think you should implement some standardized rate limiting into your API. Typically this is done by allowing only X amount of resources to be returned in a single call. If the initial request asks for more than X limit, an offset/nextID is returned by the API, and the client submits a new request noting that offset/nextID. This means you have subsequent calls from the client to get everything it needs, but gives your server a chance to handle it in smaller chunks (e.g., check for rate limits, throttling, load balancing, etc). See the leaky bucket algorithm for an implementation that I prefer, myself: https://en.wikipedia.org/wiki/Leaky_bucket)

Proper RESTful SOA approach in PHP applications?

So, i've been reading a lot on SOA's lately and been trying to implement something useful. I have started with a simple blog, creating the RESTful API. So far, so good. It works perfectly. However, i'm starting to pull my hair off when writing the web interface that will consume the RESTful API. I don't know if i'm doing the right thing.
For example, the web interface has an admin panel. That admin panel makes HTTP requests to the API, through file_get_contents and stream options. Right now, the API is localhost, as well the web interface, but the whole process is a little slower. Is this right? Is this the proper way of implementing a SOA? Also, i'm dealing with little bits of duplicated code for validation. Where should i validate data? In the API or the web interface? What is the best approach?
Tips, tutorials and, specially, books are welcome. This is being implemented using Silex, built on top of Symfony components.
That's exactly how i do it. Although the connection with localhost might seem an overhead at first, it is a feature, since you're ready to deploy your web interface application anywhere and still consume your API, that might be anywhere. Of course, you would put some SSL over this.
As for Validation, you should validate on the API and return HTTP status codes for those situations (for example, "400 Bad Request" for invalid parameters). This way, any other client can interpret the response from the API and treat that to display how they want. In the case of your web interface, nice little error messages based on the HTTP status code.
What other problems are you facing? Also, as far as general SOA architecture is concerned, this book is very good.

Unit Testing Google OAuth2 with PHP

I'm wondering if there is some way to do unit testing using the Google API for authentication using the Google API PHP Client.
Here is the kind of code example that I want to use around my unit testing case.
(but i want to do more complicated things around it of course that is why i need to do unit testing)
http://code.google.com/p/google-api-php-client/source/browse/trunk/examples/userinfo/index.php
It is messy, but possible. It is not going to be exactly unit testing, but still...
You need to
either write stubs for the parts of your code which do actual
requests to the google api, which would return predefined responses
which your code needs to be ready for.
or create a simple separate
service in your local network which would behave like google api web
service. It is easier than it sounds - a simple php script with a
switch and a readfile(responseFileNumberN)...
Either way you need to decide which of google's behaviours/errors you need to emulate. Testing on live service is a bad idea. This way you are going to test google's api which is out of your control or your network connection, not your app.

How do I send an email via invoking a web service using php, javascript, wsdl?

I have some experience building web applications in html, css, javascript, jquery, and php. I understand what a wsdl document is made up of. I have been tasked to invoke a web service, which will then send an email that says "hello world."
After some hours of research, I've come across things like Apache Axis, XML-RPC, Open ESB, and Mule. Do I have to know java in order to invoke web service->send email? Is there a way to invoke a wsdl from within a web app using php?
I know about the mail() function in php. But I have been specifically told to learn how to invoke a web service. I'm lost and don't know where to begin.
I'm going to research Apache Axis until I figure out what to do.
Do I have to know java in order to invoke web service->send email?
You can create a web service using any web/server-side languange. But you should understand what is "Web Service", at the firs place, before you go too far with your question.
And stop thinking that Web Service = XML = Java.
I know about the mail() function in php. But I have been specifically
told to learn how to invoke a web service. I'm lost and don't know
where to begin.
Web services are starting to get fairly popular, but are not often well understood. When we talk about web service, we mean interfaces to data offered via HTTP, designed to be used programatically. With these loose definition, RSS feeds (also) appear to be a web service too since they share data across HTTP in format intended for parsing by software rather than humans, altough they're not usually included in such discussions.
Web service has become a label for XML sent over HTTP with read and write capabilities (but this is not the entire picturre). While HTTP always sit at the core (putting 'web' into 'webservices') we don't necessarily need to use XML, nor do we need to provide methods to write data. Many web services only allow querying and reading data.
While we already have a transport layer in our networking stack (TCP/UDP), then when we talk about web service (which actually an API on the top of HTTP), then we also need an API transport layer. When we talk about API transport layers, what we actually mean is a layer above the application layer at the top of OSI seven-layer model. Shortly, there tend to be three main contenders in this space,
A. REST
B. XML-RPC
C. SOAP
After you create your own public API, using ones of above transport layer, you can then encourage people to building with more outlandish languange and applications to build their own API kits, by providing the core set of languange support (PHP, Perl, Phyton, .NET, and Java).
So where is sending email in these explanation? Its just a part (a little one) of what you called "Web Service". After you have enough playing with "Web Service", then you will know exactly where you can put that as part of your Web Service.

Which one should I choose AMQP or XMPP for real-time browser-based game?

I'm choosing between AMQP (RabbitMQ) vs XMPP (eJabberd) for my browser-based flash-free javascript powered real-time turn-based game. I don't know much about AMQP and XMPP protocol. I would like to use PHP for user-authorization and some data store-retrieve with MySQL. As far as I found out, RabbitMQ has PHP clients but eJabberd not.
What I understood is javascript client calls PHP script and manipulate necessary processing and then pass to AMQP or XMPP server to pass the data to opponent player. There is a good book 'Pro XMPP Programming with JS and jQuery' from Wrox but there is no example with PHP. So following are my questions.
1) Which protocol is suit for my game?
2) Shall I choose RabbitMQ just for it's PHP client support?
I've had fairly good success implementing an XMPP client in Javascript by using HTTP Bind approach to XMPP BOSH. I don't know about AMQP, but for client-side access, I love XMPP. A few words why.
ejabberd already includes BOSH support, and to use with Javascript (and presumably Flash) you just need to direct your server to redirect requests to port on which you configure ejabberd to listen for HTTP requests. (And even this only because Javascript security model in today's browsers forbids Javascript requests to different domains and even different ports.)
Since XMPP is a bunch of quite trivial small XML documents, it should be fairly easy to encode them in any language you pick.
Since it's widely supported, you might be able to avoid requiring your users to register with your service, which they will most certainly appreciate.
Implementing XMPP means you can trivially add instant messaging support to your game, with federationing to the rest of the Jabber network (including Google Talk).
Since I don't know anything about AMQP, I cannot compare them -- but I can say why I'll always first consider XMPP for my future multiplayer projects.
My personal reason for choosing ejabberd is simple -- it's super easy to install and configure on Debian. I'm almost completely unfamiliar with Erlang and Java; what I understand, however, about Erlang is that it makes scalability easy to achieve, and ejabberd people say they have achieved it.
If you want to do server side logic checking, I'm afraid I don't know of any good method. I'd go with a proxy PHP script doing sanity checking on the incoming XMPP BOSH message, then forwarding it to the server, instead of just forwarding it via Apache's mod_rewrite.
As mentioned above, you will definitely have to do proxying of some sort (with mod_rewrite or with PHP or in some other way) since the XMPP server will listen on a different port than the "main" web server, and Javascript cross-domain security model does not allow doing XMLHTTPRequest on a different port.
So, sanity checking might be easiest done while relaying BOSH requests to XMPP server of your choice. Digging into the server software might not be the best way to do this type of checks. It would take long, and would probably make it harder to integrate with the rest of your game.
Alternatively, I stumbled upon an answer that mentions XMPP components and ejabberd modules. This will be an interesting read for me, too.
Good luck, and be sure to drop a comment with the name of the game when it's done -- I'd love to see it :-)
I just noticed someone else posted a very similar question to yours. Its answers contain some more interesting info for you.
On using XMPP with Flash:
You could nevertheless use HTTP binding (BOSH) with Flash. In fact, while HTTP binding allows Javascript to access XMPP, it was conceived for a variety of applications, such as mobile connections that can often break.
I mostly figured out how to establish the connection by observing communications between web-based client JWChat and ejabberd (for info on BOSH), and then communications between cross-platform client Psi and ejabberd (for info on protocol itself). With JWChat and WebKit's Web Inspector or with Firebug for Firefox, one can easily track XMLHttpRequests being done towards the server. With Psi, one can turn on the XML console and read the communications log. Combined with prototyping a client in a language of your choice, studying BOSH and XMPP turned out to be very easy.
Also, following XEPs are useful: XEP-0124, XEP-0206.
O'Reilly book that I'm reading right now, "XMPP: The Definitive Guide" (P. Saint-Andre, Kevin Smith, Remko Tronçon; much cheaper on Apple's App Store) also gives you the feeling "why things are done the way they are", and documents many small things and various applications of XMPP.
After that, implementing a BOSH-based client could turn out to be rather easy. I have no experience with coding with Flash apart from making a button play and pause, so take this with a grain of salt :-)
As someone mentioned, you need to consider the client-to-server part; that seems of more importance.
It sounds like you already have the best book on the subject (Jack Moffit's XMPP + JS book) and I would definitely say that's the technology to go with.
Also you get user authentication, encryption and all the many XMPP protocol extensions on top of that, as the book will describe.
Even although I can't recommend any PHP-XMPP clients, I don't think you'd necessarily have the same level of features out-of-the-box with AMQP.
Also, if you're versed in other languages, and depending on the amount of game logic required, you could write an XMPP server component. See this prior question about XMPP + gaming for info:
XMPP C# Interaction
AMQP has not yet reached version 1.0 and has some possible design issues around it. There are XMPP clients for PHP so if I were you I'd give that a try first.

Categories