I need to create a TrxPlugin to verify if my Claim Line has a valid Product.
This is what I am trying to do:
import java.util.List;
import com.kernelsol.common.engine.Row;
import com.kernelsol.common.plugins.TrxPlugin;
public class MyTrxPlugin extends TrxPlugin {
#Override
public List<String> fields() throws Exception {
// TODO Auto-generated method stub
return null;
}
#Override
public Row augment(Row row) throws Exception {
// TODO Auto-generated method stub
return null;
}
}
Related
Here there is pseudocode about how to handle BLOB and CLOB in olingo jpa. I added the needed imports to the pseudocode:
package me;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.SQLException;
import javax.sql.rowset.serial.SerialException;
import org.apache.olingo.odata2.jpa.processor.api.OnJPAWriteContent;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
public class OnDBWriteContent implements OnJPAWriteContent {
#Override
public Blob getJPABlob(byte[] binaryData) throws ODataJPARuntimeException {
try {
return new JDBCBlob(binaryData);
} catch (SerialException e) {
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
} catch (SQLException e) {
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
}
return null;
}
#Override
public Clob getJPAClob(char[] characterData) throws ODataJPARuntimeException {
try {
return new JDBCClob(new String(characterData));
} catch (SQLException e) {
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
}
return null;
}
}
the only problem is I couldn't find any implementation for JDBCBlob and JDBCClob. Any suggestion about how can I implement them or use some classes?
If You are using MySQL it requires an additional ExceptionInterceptor along with the Blob Implementation. You can have a custom implementation of ExceptionInterceptor and use it to initialise the Blob field.
The code to achieve it would be as follows
import java.sql.Blob;
import java.sql.Clob;
import java.util.Properties;
import org.apache.olingo.odata2.jpa.processor.api.OnJPAWriteContent;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
import com.mysql.cj.exceptions.ExceptionInterceptor;
import com.mysql.cj.log.Log;
public class CustomOnJPAWriteContent implements OnJPAWriteContent {
#Override
public Blob getJPABlob(byte[] binaryData) throws ODataJPARuntimeException {
return new com.mysql.cj.jdbc.Blob(binaryData, exceptionInterceptor);
}
#Override
public Clob getJPAClob(char[] characterData) throws ODataJPARuntimeException {
return new com.mysql.cj.jdbc.Clob(new String(characterData), exceptionInterceptor);
}
ExceptionInterceptor exceptionInterceptor = new ExceptionInterceptor() {
#Override
public Exception interceptException(Exception sqlEx) {
// TODO Auto-generated method stub
return null;
}
#Override
public ExceptionInterceptor init(Properties props, Log log) {
// TODO Auto-generated method stub
return null;
}
#Override
public void destroy() {
// TODO Auto-generated method stub
}
};
}
it is throw NullPointerException when i use RPCServiceClient and asynchronous call.But it is normal using RPCServiceClient.invokeBlocking.
my axis2 version is 1.6.4.
this is my code:
public void sendMsg(String xmldata, AxisCallback callback) throws AxisFault {
String webServiceURL = "http://171.8.212.68:8191/axis2/services/UserService";
String sendflag = "true";
if ("true".equals(sendflag)) {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(webServiceURL);
options.setTo(targetEPR);
Object[] opAddEntryArgs = new Object[]{xmldata};
QName opAddEntry = new QName("http://downstream.sysinterface.topsms.topnet.com", "sendMsg");
if (callback == null) {
callback = new AxisCallback() {
public void onComplete() {
// TODO Auto-generated method stub
System.out.println("***********onComplete");
}
public void onError(Exception exception) {
// TODO Auto-generated method stub
exception.printStackTrace();
System.out.println("***********onError:"+exception.getMessage()+":"+ Arrays.toString(exception.getStackTrace()));
System.out.println(getStackTrace(exception));
}
public void onFault(MessageContext context) {
// TODO Auto-generated method stub
System.out.println("***********onFault");
}
public void onMessage(MessageContext context) {
// TODO Auto-generated method stub
System.out.println("***********onMessage");
}
};
}
serviceClient.invokeNonBlocking(opAddEntry, opAddEntryArgs, callback);
serviceClient.cleanupTransport();
serviceClient.cleanup();
}
}
Exception is below:
java.lang.NullPointerException
at org.apache.axis2.context.AbstractContext.needPropertyDifferences(AbstractContext.java:239)
at org.apache.axis2.context.AbstractContext.setProperty(AbstractContext.java:202)
at org.apache.axis2.transport.http.AbstractHTTPSender.getHttpClient(AbstractHTTPSender.java:568)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:157)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:396)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:223)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient$NonBlockingInvocationWorker.run(OutInAxisOperation.java:446)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:767)
I get an unknown host error when I try to start an RMI server
here. The error is unknown host. Actually, I'm just a beginner in RMI and sockets programming in JAVA. Can you please provide me with some tutorials
concerning my problem.
My interface code:
package ApplicationServer;
import java.io.File;
import java.rmi.RemoteException;
import java.sql.ResultSet;
public interface Méthodes {
public String authentification(String login, String mdp) throws RemoteException;
public ResultSet selection(String requete) throws RemoteException;
public int miseAjour(String requete) throws RemoteException;
public String envoyerFichier(File fichier) throws RemoteException;
}
In this class I have all the methods that I need in my program:
package ApplicationServer;
import java.io.File;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Traitements extends UnicastRemoteObject implements Méthodes {
private Connection cnx;
private Statement stm;
private ResultSet rst;
private int rs;
public void setCnx(Connection cnx) {
this.cnx = cnx;
}
public void setStm(Statement stm) {
this.stm = stm;
}
public void setRst(ResultSet rst) {
this.rst = rst;
}
public void setRs(int rs) {
this.rs = rs;
}
protected Traitements() throws RemoteException {
super();
// TODO Auto-generated constructor stub
}
#Override
public String authentification(String login, String mdp) throws RemoteException {
// TODO Auto-generated method stub
try {
setCnx(null);
setStm(null);
setRst(null);
Class.forName("com.mysql.jdbc.Driver");
cnx=DriverManager.getConnection("jdbc:mysql://localhost:3306/banque","root","");
stm=cnx.createStatement();
rst=stm.executeQuery("select md5('"+mdp+"');");
while(rst.next()){
mdp=rst.getString(1);
}
stm.clearBatch();
stm=cnx.createStatement();
setRst(null);
String Query = "select * from utilisateurs where login like '"+login+"' and motdepasse like '"+mdp+"';";
rst=stm.executeQuery(Query);
int id = 0;
String nm = null;
String prm = null;
while(rst.next()){
id = rst.getInt("id");
nm = rst.getString("nom");
prm = rst.getString("prenom");
}
if(id>0 && nm!=null && prm!=null){
return id+" "+nm+" "+prm;
}
}catch (SQLException | ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
#Override
public ResultSet selection(String requete) throws RemoteException {
try{
setCnx(null);
setStm(null);
setRst(null);
Class.forName("com.mysql.jdbc.Driver");
cnx=DriverManager.getConnection("jdbc:mysql://localhost:3306/banque","root","");
stm=cnx.createStatement();
rst=stm.executeQuery(requete);
}catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rst;
}
#Override
public int miseAjour(String requete) throws RemoteException {
try{
setCnx(null);
setStm(null);
setRs(0);
Class.forName("com.mysql.jdbc.Driver");
cnx=DriverManager.getConnection("jdbc:mysql://localhost:3306/banque","root","");
stm=cnx.createStatement();
rs=stm.executeUpdate(requete);
}catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
#Override
public String envoyerFichier(File fichier) throws RemoteException {
// TODO Auto-generated method stub
return null;
}
}
This is the main class that runs the server:
package ApplicationServer;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
int port=12345;
String url="rmi://serveur:"+port+"/reference";
LocateRegistry.createRegistry(port);
Traitements srv = new Traitements();
Naming.rebind(url, srv);
JOptionPane.showMessageDialog(null, "Serveur Lance :");
} catch (RemoteException | MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
You are supposed to replace serveur with a real hostname in that code.
However it's far better to use localhost in the RMI URL when binding. The Registry has to be local to the host anyway so there's no point in using anything else.
In my application, we use java applet to write cookie on browser and use jquery to read this cookie. I tried do like tutorial but I always don't see the cookie set on my browser.
http://docs.oracle.com/javase/tutorial/deployment/doingMoreWithRIA/accessingCookies.html
And here is my code:
The first I create a class to handle the cookie
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.net.CookieStore;
import java.net.HttpCookie;
import java.net.URI;
import java.util.List;
public class CookieAccessor implements CookieStore {
public CookieStore store;
public CookieManager manager;
public CookieAccessor() {
try {
manager = new CookieManager();
manager.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
CookieHandler.setDefault(manager);
store = manager.getCookieStore();
} catch (Exception e) {
e.printStackTrace();
}
}
#Override
public void add(URI uri, HttpCookie cookie) {
// TODO Auto-generated method stub
store.add(uri, cookie);
}
#Override
public List<HttpCookie> get(URI uri) {
// TODO Auto-generated method stub
return store.get(uri);
}
#Override
public List<HttpCookie> getCookies() {
// TODO Auto-generated method stub
return store.getCookies();
}
#Override
public List<URI> getURIs() {
// TODO Auto-generated method stub
return store.getURIs();
}
#Override
public boolean remove(URI uri, HttpCookie cookie) {
// TODO Auto-generated method stub
return store.remove(uri, cookie);
}
#Override
public boolean removeAll() {
// TODO Auto-generated method stub
return store.removeAll();
}
}
Then I call it in main applet (I use jquery to run this applet):
try {
cookie = new CookieAccessor();
HttpCookie cookiedata = new HttpCookie("UserName", "Jonh");
URL url = new URL(getCodeBase().toString());
cookie.add(url.toURI(), cookiedata);
} catch(Exception e) {
e.printStackTrace();
}
But I've checked the browser cookies and there's no UserName What is missing in this code?
Many thanks!
I am having a very difficult time on figuring out how to get records from an object that i have passed in the path to the file.
import java.util.ArrayList;
import edu.trident.cpt237.recordreaper.CabRecordReaper;
public class CabOrginazer implements CabInfo
{
private final String FARE = "";
private final String GAS = "";
private final String SERVICE = "";
private final String MILES = "";
private final double VALUE = 0.0;
CabRecordReaper reaper = new CabRecordReaper("C:/CabRecords/September.txt" );
public void cabOrginazer()
{
}
#Override
public Records getType() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getDate() {
// TODO Auto-generated method stub
return null;
}
#Override
public String CabId() {
// TODO Auto-generated method stub
return null;
}
#Override
public double getValue() {
// TODO Auto-generated method stub
return 0;
}
#Override
public double getPerGallonCost() {
// TODO Auto-generated method stub
return 0;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
I have try'd using a Scanner but does not work so i took it out. I can't do any of my other methods until i can grab what is in side of that reaper. The only methods inside of the CabRecordReaper is hasMoreRecord() which determines if there is more lines in the file.
I'm not quite understanding your question but I think you are having difficulties with reading from a .txt file?
try (BufferedReader reader = Files.newBufferedReader(Paths.get("path here")) {
String line = null;
while ((line = reader.readLine()) != null) {
// Add your code here.
System.out.println(true);
}
} catch (IOException e) {
e.printStackTrace();
}