Want to pull data from DATABASE using Java And Flex - java

I Am Completely novice in flex could you just let me know about it plz.I want to access data from a database residing on a particular ip address and also i am not sure how to do it pl let me know how it can be done through flex framework.

Being a client side technology, it would be a real problem allowing direct access to the database. What you need is some server application to mediate the access to the database. This could be written in many different ways, but the majority of developers would use PHP/.net/Java

There are many ways to access your data. For simple stuff, you could use a servlet that will fetch data from db and provide it to the flex running on the client.
instead of servlets, you could also use web services. On the flex side, you have three ways to access data: HTTPService, WebService, and RemoteObject.
Its up to you to select one of them ( as I don't know what your requirements are and how well you know on these).

There are many different options. Check out a screencast I did on Flex and Java basics that walks through the various options.

Your Flex frontend
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" backgroundColor="#FFFFFF" viewSourceURL="srcview/index.html">
<mx:RemoteObject id="myservice" fault="faultHandler(event)"
showBusyCursor="true" destionation="yourDest">
<mx:method name="JavaMethodName" result="resultHandler(event)" />
</mx:RemoteObject>
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
private function faultHandler(evt:FaultEvent):void
{
trace(evt.fault);
}
private function resultHandler(evt:ResultEvent):void
{
trace(evt.result);
}
]]>
</mx:Script>
<mx:Button x="250" y="157" label="Click" width="79" click="myservice.getOperation('JavaMethodName').send();"/>
</mx:Application>
Remoting-Config.XML
<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service"
class="flex.messaging.services.RemotingService">
<adapters>
<adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
</adapters>
<destination id="yourDest">
<properties>
<source>YourClassName</source>
</properties>
</destination>
<default-channels>
<channel ref="my-amf"/>
</default-channels>
</service>
Your Java Class
import java.util.Date;
public class YourClassName{
public String JavaMethodName() {
Date now = new Date();
return "Yourname " + now;
}
}
Now in your Java Class you need to write out your JDBC connection and call the database and which you can return to flex as an Object from there you can display it in frontend in what ever format.

Look at the documentation for Adobe BlazeDS. This will show you how to do what you want and how to implement for example what Vinothababu suggested. Here's the link: http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/

Related

Java/AEM: com.day.cq.commons.Externalizer absolutelink function returning the wrong hostname

I have an existing site hosted under www.myhost.com. I created a new "site" and using apache config/rewrites, this is hosted under new.myhost.com.
The problem is that when I make a request (example: www.myhost.com/my-servlet/lets-go), the values returned by absoluteLink function uses "new.myhost.com" instead of www.myhost.com.
I have several "com.day.cq.commons.impl.Externalizer.xml" files in my code but none of them has been configured for "new.myhost.com".
Any ideas on how to fix? Thanks
edit1: I also checked publisher configMgr and the new host is not listed in "Day CQ Link Externalizer" (pid=com.day.cq.commons.impl.ExternalizerImpl).
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:OsgiConfig"
externalizer.domains="[local http://localhost:4502, author http://author.myhost.com, publish http://localhost:4503, stage http://stage.myhost.com, prod http://www.myhost.com]"
/>

WCF service In JAVA

I already created WPF(C#) apps
1) Server 2) Client
both has it's own TCP endpoints
Server Contract
public interface IServer
{
//Client calls this to register it self in server.
[OperationContract]
void RegisterClient(string hostName, string domainName);
//To submit the resut back to server.
[OperationContract]
void SubmitResult(Result result);
//heart beat check, to check the client is alive.
bool ConnectionTest();
}
Client Contract
interface IClient
{
//Heart beat check, to check the server is alive.
[OperationContract()]
bool IsAvailable();
[OperationContract()]
void dosomething(string projects);
}
Both the server and client are working fine. This there is any way i can create a Client app in java with above client Contract which will interact with WPF(C#) server?
I think java supports tcp and SOAP, is there is any WCF Equivalent framework in JAVA(a console app)?
i am new to java i don't know where to begin with.
Binding choice
NetTcpBinding is a binary Microsoft technology.
In order to call the Net service with Java, you should favour:
basicHttpBinding (SOAP 1.1)
wsHttpBinding (SOAP 1.2)
Metadata
Don't forget to expose Metadata Exchange in order for your WSDL to be called
Metadata Endpoint :
<services>
<service name="BillingService.BillingService">
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
...
</service>
Metadata Behavior :
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
...
</behavior>
</serviceBehaviors>
Generation of the proxy in java :
Then use wsimport.exe from %JavaRoot%\bin
C:\Program Files\Java\jdk1.8.0_25\bin>wsimport.exe -s e:\temp\javaws http://localhost:8733/Design_Time_Addresses/BillingService/?wsdl
Regards

How do you set up a redirect from www to non-www with Play! Java 2.3 running the default server?

I recently set up a website and pushed it to production using Digital Ocean. However, I noticed that for both SEO purposes and to make Facebook Share work appropriately, I should set up my server to redirect www. requests to non-www. I'm running Play! Java 2.3 with a PostgreSQL database and the default Netty server. Any advice would be greatly appreciated.
There are lots of ways of redirecting. I wouldn't say DNS-redirects are the correct and only way of doing it, it's one way. Google is just fine with you doing a 301 redirect with Play.
Here's one way of accomplishing it with Play! filters (scala):
object NonWwwFilter extends Filter {
def apply(f:RequestHeader => Future[Result])(rh: RequestHeader): Future[Result] =
if (rh.host.startsWith("www.")) {
Future.successful(Results.MovedPermanently("https://" + rh.host.substring(4) + rh.uri))
} else {
f(rh)
}
}
The right way to do it is to do in not on the framework/webserver side, but on the DNS-server side.
You can do it in DNS-management area of GoDaddy or any other domain name registrar.

developing android application with server using web service

I am developing client/server apps (the client is an Android application which sends data to the server). I am developing the server using Java. I already connected the sever application "using NetBeans" using SQL Navigator 5.5. I want to use Json as a middle ware, but I don't know how! What is the most suitable, XML or Json? Do i need to use HTTP? If so, how (as I want to be able to secure the application)?
The other thing that the server should respond to is the Android application by sending "longitude and latitude", for which Android should "geocode" and display on the form of map "location." Also, I need to understand more about the concept of web service that should work on the application.
This is the server code:
(The values that the server should get from the client are "long and lat")
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pkg;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
#WebService(serviceName = "lbsws")
public class lbsws {
/** This is a sample web service operation */
#WebMethod(operationName = "hello")
public String hello(#WebParam(name = "name") String longg) {
String result=null;
try
{
Connection con = dbConnection.getdbConnection("system","lbs","orcll", "localhost");
Statement st = con.createStatement();
String lat ="10";
String query="select longg,lat,abs(("+longg+"-longg))/abs(("+lat+"-lat)) as function1 from lbs where abs(("+longg+"-longg))/abs(("+lat+"-lat)) = ("+
"select min(abs(("+longg+"-longg))/abs(("+lat+"-lat))) from lbs)";
ResultSet rs = st.executeQuery(query);
while(rs.next())
{
result = rs.getFloat("longg")+","+ rs.getFloat("lat")+"-"+ rs.getFloat("function1");
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
return result;
}
}
A few things:
1) JSON Thumbs up for the transport layer. Don't give it a second thought.
2) Consuming JSON Web Services. Use HttpClient in Java based systems. Just to get the response back
than you can convert JSON to objects as needed. But calling web service is via HttpClient
3) Creating JSON Services. Well you could use Jersey. There are a few choices. I would recommend developing in Tomcat server. Its faster and not so much up/down as with Java EE servers. There are some other good choices beside Jersey.
But mainly write the simplest thing first and get it working from end-to-end. Thats what you want to do.
Just produce a service that returns the Sytem time and send that back via JSON consume it on the client and display. Then re-evaluate Jersey vs. whatever. But get something running end to end.
So step one is write a JSON Web Service and just test it in the browser. Don't worry about client side right now. Just get the service running and invoke it using the browser. BTW, there are reason to go with RESTful JSON web service. Its a good way to structure your web services.
Never attack two problems at the same time. Forget about connecting to a database until you have got the service up and running with just data that is stubbed out.

Log4J SMTP digest/aggregate emails?

I have a JBOSS batch application that sometimes sends hundreds on emails in a minute to the same email address with Log4J errors. This causes problems with Gmail, because it says we are sending emails too quickly for that gmail account.
So I was wondering if there was a way to basically create a "digest" or "aggregate" email puts all the error logs in 1 email and sends that every 5 minutes. So that way every 5 minutes we may get a large email, but at least we actually get the email instead of it being delayed for hours and hours by gmail servers rejecting it.
I read this post that suggested something about using an evaluator to do that, but I couldn't see how that is configured in the Log4J xml configuration file. It also seemed like it might not be able to "digest" all the logs into 1 email anyway.
Has anyone done this before? Or know if it's possible?
From (the archived) SMTPAppender Usage page:
set this property
log4j.appender.myMail.evaluatorClass = com.mydomain.example.MyEvaluator
Now you have to create the evaluator class and implement the org.apache.log4j.spi.TriggeringEventEvaluator interface and place this class in a path where log4j can access it.
//Example TriggeringEventEvaluator impl
package com.mydomain.example;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.TriggeringEventEvaluator;
public class MyEvaluator implements TriggeringEventEvaluator {
public boolean isTriggeringEvent(LoggingEvent event) {
return true;
}
}
You have to write the evaluator logic within this method.
I created a free useable solution for log4j2 with an ExtendedSmtpAppender.
(If you still use log4j 1.x, simply replace your log4j-1.x.jar with log4j-1.2-api-2.x.jar - and log4j-core-2.x.jar + log4j-api-2.x.jar of course.)
You get it from Maven Central as de.it-tw:log4j2-extras (This requires Java 7+ and log4j 2.8+).
If you are restricted to Java 6 (and thus log4j 2.3) then use de.it-tw:log4j2-Java6-extras
Additionally, see the GitLab project: https://gitlab.com/thiesw/log4j2-extras (or https://gitlab.com/thiesw/log4j2-Java6-extras)
[OLD text:
If you use log4j2, see answer to other stack overflow issue: https://stackoverflow.com/a/34072704/5074004
Or directly go to my external but publically available solution presented in https://issues.apache.org/jira/browse/LOG4J2-1192
]

Categories

Resources