500 server error? - java

I got quercus up and running on GAE and when I process this code I get Error: Server Error
<?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
$user="user";
$pass="pass";
try {
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass,
Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME);
} catch (Zend_Gdata_App_AuthException $ae) {
exit("Error: ". $ae->getMessage() ."\nCredentials provided were email: [$user] and password [$pass].\n");
}
?>
The thing is GAE is blocking every curl request and I can't make the request to the Spreadsheets

You cannot use curl on App Engine. You need to use URLFetch.

Related

How to setup Parse live query with Android (Java) with self-hosted server URL

I'm trying to use Parse live queries in Android Studio following this back4app guide. I enabled live query and set up the LiveQuery client following Steps 1 and 2 in the guide. However, I am having trouble with Step 3 (subscribing to the query). Here's what I tried:
// Back4App's Parse setup
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId(APPLICATION_ID)
.clientKey(CLIENT_KEY)
.server("wss://<my_subdomain>.back4app.io/").build()
);
// Init Live Query Client
ParseLiveQueryClient parseLiveQueryClient = null;
try {
parseLiveQueryClient = ParseLiveQueryClient.Factory.getClient(new URI("wss://<my_subdomain>.back4app.io/"));
} catch (URISyntaxException e) {
e.printStackTrace();
}
replacing the application id, client key, and subdomain appropriately. But this resulted in an error: java.net.MalformedURLException: unknown protocol: wss and I was unable to create the Parse application. I tried replacing wss:// with https:// in the server URL. The application ran, but every Parse SDK request returned error: unauthorized. Before changing the server URL, I had been using "https://parseapi.back4app.com" and everything worked perfectly. I'm unsure how to fix this issue - any help would be appreciated. Thanks.

Using Vert.x Web Client to send GET requests properly with headers

I have an internal endpoint that I am trying to send GET requests to with Vert.x Web Client with Java. So far, I am unable to successfully get any data back.
If I cURL the endpoint, it works just fine (these are internal endpoints). The service I am trying to send GET requests to requires a few headers , and data as well:
curl -H "Accept:application/json" -H "Content-Type:application/json" -H "alpha:192.168.10.20" -d '{"mutate":"*"}' http://my-endpoint.com/api/get-items
But if I try to use this in one of my router endpoints in Vert.x, I get an error:
WebClient webClient = WebClient.create(vertx);
webClient.get("http://my-endpoint.com/api/get-items")
.putHeader("Accept", "application/json")
.putHeader("Content-Type", "application/json")
.putHeader("alpha", "192.168.10.20")
.sendJsonObject(new JsonObject().put("mutate", "*"), ar -> {
if (ar.succeeded()) {
System.out.println("##### WEBCLIENT #####");
System.out.println(ar);
} else {
System.out.println("CAUSE: " + ar.cause().getMessage());
}
});
The error message I get from the else statement is:
CAUSE: Connection refused: localhost/127.0.0.1:80
What am I doing wrong? I've been using this for reference: Vert.x Web Client
===========================================
SOLUTION
===========================================
I had to change
webClient.get("http://my-endpoint.com/api/get-items")
to
webClient.post(80, "my-endpoint.com", "/api/get-items")
Also had to add .as(BodyCodec.jsonArray()) underneath the above line because the result I was getting was a Json Array.
You need to change
webClient.get("http://my-endpoint.com/api/get-items")
to
webClient.get(80, "my-endpoint.com", "/api/get-items")

Createrawtransaction - rpc connection bitcoind

when I'm trying to prepare and send an rpc request to my bitcoin-qt wallet via JSONRPC2 connection I don't get anyresponse (String is empty). When I put command into bitcoin-qt konsole is working fine. Here my code.
String requestBody = "{\"jsonrpc\":\"2.0\",\"method\":\""+method+"\""+tmpS+",\"id\":9}";
and JSON object sending to client :
{"jsonrpc":"2.0","method":"createrawtransaction","params":"[[{"txid":"ba9b655fc17448a422ae9afd28ed264a91fa631c3d131468d674bc2cf7757a3e","vout":0},{"txid":"66672599375caa1fee0d59562531b3cb57da35554ff666e34e53c06c3f1c9415","vout":1}]","{"mgGWs59KnzSt6vpA5zm1EkP2xDzYe58hHF":4.78396431}"]","id":9}
With commands like listunspent or getaccountaddress everything working good. Maybe the error is on the "multiple params" side.
Thanks, for help.

How to connect php client to java webservice?

I know php webservice SOAP,json,rest etc, but I am new for java webservice. Now I want to get php client to java webservice. What is the best way to do this?
There is nothing new in it. Just create SoapClient with java web services WSDL URL and call it's method:
<?php
try{
$proxy = new SoapClient("javaWsdlUrl?wsdl");
$result = $proxy->javaWSMethod(array("arg0"=>"1234","arg1"=>"5678"));
print_r($result);
} catch (Exception $e) {
echo $e->getMessage ();
}
?>
Other things will be same like generating stubs, getting method names,...
When you connnect to a public webservice like Amazon, you dont (necesserly) know what language is used to create the webservice (server side) . So you will connect to your java webservice the same way you connect to a php or any other webservice.

Server-Side Redirect in PHP

I have a Java application that I need to integrate our existing PHP website with. The vendor wants us to do a server-side redirect to allow for secure authentication and single-sign-on, but I'm not sure how to do that in PHP. The vendor explained the workflow as follows:
User clicks on a 'Open Application' link on our PHP site
The PHP application hits a page on the Java application, sending the authentication parameters
If successful, the PHP application sends the headers back to the user's browser, which forces a 'redirect', otherwise the PHP app displays an error
What this will allow would be for our PHP app to securely talk to the Java app, and the client never has to send any sort of authentication.
From what I understand, .NET and Java have this capability built in, but I can't find a way in PHP to do this. Any ideas?
UPDATE
I'm not talking about using the header("Location: ..."); function to do a redirect. The kicker with this server-side redirect is that the app does the authentication and sends all that information back to the client so that the client is then logged in. Using header("Location: ...") just forces the browser to go elsewhere.
UPDATE 2
autologin.php (Simulates the user logging into an external app via curl)
// The login 'form' is at login.php
$ch = curl_init('http://domain.local/login.php');
// We are posting 2 variables, and returning the transfer just so it doesn't dump out
// Headers are processed by the callback function processHeaders()
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'processHeaders');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username=user&password=pass');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute curl, close the connection, and redirect the user to a 'restricted' page
$response = curl_exec($ch);
curl_close($ch);
header("Location: http://domain.local/restricted.php");
function processHeaders($ch, $header) {
// Dump the response headers to the client
header($header);
strlen($header);
}
login.php (Contains the 'login' form)
session_start();
if($_POST) {
if($_POST['username'] == 'user' && $_POST['password'] == 'pass') {
$_SESSION['auth'] = 1;
$_SESSION['token'] = md5(time());
} else {
echo 'Auth failed';
}
} else {
echo 'Invalid access type';
}
restricted.php (Restricted page)
session_start();
if($_SESSION['auth']) {
echo 'Secret Token: '.$_SESSION['token'];
} else {
echo 'Please log in';
}
The idea is that the user wants to ultimately get to 'restricted.php'. 'login.php' contains the code necessary to log in. What I want to simulate is the user filling out the form on 'login.php' and logging the user into 'restricted.php'.
The above snippets of code work together on my local tests (hitting autologin.php redirects to restricted.php and the secret token is printed out), but I can't seem to get it to work cross-application. The apps will be on the same domain (https://domain.com/myapp, https://domain.com:1234/vendorapp).
I've never done this before in any language, I'm just going off of what my vendor has told me they've done. Apparently they've never dealt with PHP before and have no idea what to do.
like this:
header("Location: http://www.example.com/")
But it must come before any other code...see php.net
You just output a normal HTTP redirect header() like this:
<?php header('Location: http://www.example.com/'); ?>
Re Update
If I understand correctly you'd need to do this:
Browser POSTs login request to PHP server
PHP script packages the login information in some specific form for JSP app
PHP script POSTs (via cURL) or SOAPs or whatever is necessary to JSP app
PHP receives the response and parses out the necessary information
PHP sends header and/or body data back to browser
Step 4, parsing the information, depends on how you send and receive the information. If you receive them in the header via cURL, you'll need to set CURLOPT_HEADER to true and parse the necessary data out of the response. This may be as simple as splitting the string on the first blank line or more complicated, that depends on your specific situation.
How this logs in the user in your app is something you need to handle as well. The JSP app probably handles the actual password and username and hands you back a token of some sort which you'll need to keep track of.
It sounds like you are looking for the curl library, which is usually bundled with PHP.
http://php.net/manual/en/book.curl.php
<?php
session_start();
// Receive username / password from $_POST
// Prepare CURL object for post
// Post u/p to java server
// Read response
if($success)
{
header('Location: nextpage.php');
$_SESSION['LoggedInTime'] = time();
exit;
}
else
{
//display error
}
Update:
Later, you can check $_SESSION['LoggedInTime'] + 3600 > time() to see if they are still logged in. Every time they visit a logged in page, do this:
if($_SESSION['LoggedInTime'] + 3600 > time())
{
$_SESSION['LoggedInTime'] = time() + 3600;
}
else
{
header('Location: /login.php?Message=session+expired');
exit;
}
Hope this helps.
If you are trying to integrate php and java on the web, you may want to look into Quercus/Resin. Your PHP can then call java code directly. Since they are running on the same server, the java code could write any cookies, setup any sessions or doing any necessary setup processing.
http://www.caucho.com/resin-3.0/quercus/tutorial/module/index.xtp

Categories

Resources