Can I make a HTTP callout from Oracle DB via java code - java

Long ago I was consuming web service from Oracle DB with procedure that was generated with JPublisher. Simply providied URL of WS WSDL and JPublisher utility did the rest of procedure generation.
Now I need to make a call to REST service but with java code from Oracle DB. I googled for a while with no results. Is it possible or is it so trivial?

Yes, it is possible. You would store the HTTP command as an xml clob. You would also need to have sys access in order to add the calling user to the network ACL.

Related

Write and get result for SOQL query using JAVA

how do I write a java program to query an object/table in salesforce and get results in csv?
I haven't found any clear instructions for the same on the internet.
Salesforce has some default APIs that allow external systems interacting with a Salesforce org. Two examples of them are the SOAP API and the REST Api. Both APIs expose methods to interact with the Salesforce Org, allowing operations like creating, updating, deleting records and also querying.
You can use the SOAP Api (more precisely, the query method https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_query.htm) to query the Salesforce database.
You can check this example from the SF documentation that walks you through a JAVA implementation: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_quickstart_steps_walk_through_code.htm. Also, the rest of the documentation from that Salesforce site is full of Java examples that can help you.

Android: RESTful JDBC Proxy. Performance and Security

We wanted to use cloud backend for storing Android app data.
Our backend RDBMS is famous MySQL server which comes with MySQL Connector/J (an Official MySQL Network JDBC Adapter which can connect to remote MySQL database).
Now the problem is we cannot use this MySQL Connector/J in Android as its not developed for android. So what we did is, we created a REST class with four rest methods /query, /insert, /update, /delete. All these methods takes JSON Object which is wrapping parameters of respective Android ContentProvider methods. /query rest method returns a tabular resultset data in JSON format.
Then we wrote Android ContentProvider which is acting as a proxy to call our above rest methods. ContentProvider.query() method calls /query rest method and converts the received resultset JSON into Cursor for returning it.
With this architecture our server code become generic without having any business logic. And our Android app is unaware of whether the data is coming from cloud server or local database. Practically all this is working fine.
So the question is how much secure this architecture is? from the hacking point of view. And what will be the impact on Android App performance? Please help us with your valuable comments/answers.
You not should connect directly from Android app to Database (MySQL), it will give you not good performance.
I recommend for you buid Webservice API which will connect to Database and fetch, hence from Android app connect and fetch data from Webservice.
I hope this helpful for you.
Anybody can decompile your code, find this service and if he breaks your service security he can do nasty things with your database. He can browse your database, steal data, corrup data .. Crackers are searching for SQL injection on web - and you are providing direct database access.
Do not do that. Create a service for each use case that will validate/escape parameters and then call prepared JDBC statement.

Understanding how Mule ESB fits in with JDBC and REST

I have this simple REST service running in our JBoss app server which works great. For now, the service has one #GET method (getAllPeople), which makes a JDBC connection to a mysql database, to retrieve some data (SELECT name, address FROM Person).
My team lead wants me to experiment with Mule ESB, and use this simple project as a starting point. I'm confused on how to make this work with a Mule flow. I set up my flow with an HTTP inbound point, REST component, and JDBC component, like this:
I configured the JDBC component to use MySQL, and added a query to it (SELECT name, address FROM Person).
The question: The code in my REST service #GET method is still connecting directly to the DB with JDBC. I think I need to change this to instead, invoke the Mule JDBC datasource instead, but I have no idea how to do this. What code do I need to put in my REST service #GET method to utilize the Mule JDBC component, and get a result? I am trying to get a grasp on how the components talk to each other.
EDIT: new thought - Should an ESB be used to link different components of a single system together, such as REST services, SOAP services, and JDBC data sources, or should an ESB be used only to connect completely independent systems together?
To make your trivial example work, just delete the REST component and add an Object to JSON transformer after the JDBC component. Your flow will then return the query results in JSON format.
We can use mule here to call the rest api, rest api will return some data that may not be sufficient. In order to get more data from db based on the result of rest call (transformed by JsontoObject) jdbc connector could be used. In your case if you want to call rest api which eventually calls the DB, you will get json or xml which can be transformed to send the data to outbounds.
Thanks-
I am not sure why you have that 'rest' component in between. that may not be needed. the simplest would be to have the http, and a transformer (to transform the data from http to/from), and a jdbc component. with this approach you are leaving behind the existing ReST service in JBoss App Server.
I think in the posted picture you try to call the pre-existing ReST service in Jboss App Server which may not be needed. You can simply immitate what the existing service does. or you may consider the existing service and the new mule service can act as a proxy service - in such a case the JDBC component is not required.

Making a web service in PHP to give information to Java

Following my question regarding connecting to a MySQL database in Java, I am looking to create a web service in PHP. My Java program needs to ask the web service to gather some data from MySQL database and send the result back. However, I have a few dilema's:
Firstly, my web hosts do not support Java, and therefore the server side needs to be written in PHP but the client needs to be written in Java.
Secondly, all the tutorials I have found seem to involve creating a whole web service project in order for my Java program to communicate with the web service, where as realistically only a couple of classes need to contact the PHP web service.
And, you may have already guessed but I don't know anything about web service's. It was just suggested that I used one in order to get around the GPL licence of the JDBC driver...
I realise that similar questions may have been asked here before but as I am a complete novice, the posts that are saw here did not contain enough information for me and I require as much help as I can get - almost a step by step guide!
Alternatively, I did think about just using standard PHP Sockets, as I am pretty sure I know how to use them. However, I don't know how secure they are and I didn't want to take any risks because I will be needing to retrieve information such as licence keys!
Thanks in Advance
You don't need to use PHP Sockets, all you need is a simple PHP script on your web host that fetches the data you need from the MySQL DB and outputs the data to be read by your Java client.
Your PHP script will need:
To retrieve any query parameters from the Java client (probably
via $_POST or $_GET).
Information to connect to MySQL (hostname/ip address, db name,
username, password).
To run SQL query/queries to grab the data from the database.
To output the data for the java client to read, in some mutually-acceptable format, such as XML, JSON, HTML, etc.
You would structure the script something like this:
<?php
// 1. Read and validate input parameters
$myquery_val = $_POST['queryval'];
// 2. Connect to MySQL
// 3. Fetch MySQL data
// 4. Output data
?>
To learn how to connect to MySQL and retrieve data, read up on MySQL PDO: http://php.net/manual/en/ref.pdo-mysql.php
What I would do is use an agnostic form of communication between your PHP service and the Java client. My weapon of choice is XML.
The steps would be:
Create the PHP classes which will interact with your database and get the data you want to work with. GitHub has plenty of examples and source code. Sample PHP-MySQL Database Abstraction Layer
Create a RESTful php service which takes the data from step 1 and makes it into an XML REST service. Checkout the Recess Framework, an easy to use REST framework
Create your JAVA client, it should just need to be able to work with HTTP, and consume XML. No need for a huge soap or other framework.

invoking batch script/Java code from Oracle database

I have a requirment, of invoking a Java file from Oracle database. In my project, whole of my business logic is in database, but there is a requirement of invoking a third party system (SOAP / RMI call) from my application.
Now for this i need to invoke atleast a Java Code or a batch script file (depending on Windows(.bat) Or Linux(.sh)).
Thanks
Try this page: http://www.cs.umbc.edu/portal/help/oracle8/java.815/a64686/04_call2.htm
You can can Java-Code from your PL/SQL.
Web-service call outs can be done from the Oracle Database. I'm not sure why you need to use Java for this as PL/SQL also allows for outbound calls using UTL_DBWS.
If you do not intend to use JPublisher, or you have a very simple web-service to consume, then you can use UTL_HTTP itself, or the appropriate class in Java - HttpURLConnection. However, I've never seen any case where a JAX-RPC library or any other web-service library was loaded into the database using loadjava, and used to make web-service calls; it ought to be possible do so, as long as the library is very light (in not depending on other libraries that cannot be loaded or used in the database), and requires permissions only to connect out from the database.
Related question
Access Web service from Oracle stored procedure

Categories