axis2 invokeNonBlocking NullPointerException - java

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)

Related

Trying to acquire token with adal4j

I don't know how to acquire token without username and password using the adal4j library. I have this code:
public class GetToken implements AuthenticationCallback {
public static void main(String[] args) {
// TODO Auto-generated method stub
String resource = "resource";
String redirectUrl = "redirecturl";
String authority = "https://login.microsoftonline.com/common/";
ExecutorService executor = null;
ClientAssertion clientId = new ClientAssertion("my-client-id");
AuthenticationCallback callback;
// Authenticate the registered application with Azure Active Directory.
AuthenticationContext authContext;
try {
authContext = new AuthenticationContext(authority, false,executor);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Future <AuthenticationResult> result = authContext.acquireToken(resource, clientId, callback);
}
#Override
public void onSuccess(AuthenticationResult result) {
// TODO Auto-generated method stub
}
#Override
public void onFailure(Throwable exc) {
// TODO Auto-generated method stub
}
}
And I don't know how to acquire token ....
Check this link: https://learn.microsoft.com/en-us/azure/active-directory/develop/active-directory-devquickstarts-webapp-java#step-8-create-the-basicfilter-file-for-basicfilter-mvc
Look into the getAccessToke() method.This is what you're looking for:
ExecutorService executor = Executors.newFixedThreadPool(1);
Hope this helps!
You will get an IllegalArgumentException as the Executor service passed to AuthenticationContext is null.

Java Applet CookieManager not adding cookie to browser

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!

How to Grab records from an object

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();
}

NullPointer exception while calling a SOAP function

I am trying the following code to run a SOAP method from a web service.
public de.externalwebservices.worms.aphiav1_0.AphiaRecord[] getAphiaChildrenByID(int aphiaID, int offset, boolean marine_only) throws java.rmi.RemoteException{
if (aphiaNameServicePortType == null)
_initAphiaNameServicePortTypeProxy();
return aphiaNameServicePortType.getAphiaChildrenByID(aphiaID, offset, marine_only);}
That I call in a second class called WORMSWSDAO as:
public AphiaRecord[] getAphiaChildrenByID(int AphiaID){
AphiaRecord[] result = new AphiaRecord[0];
try {
result = port.getAphiaChildrenByID(AphiaID, 1, false);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
Then I run it in the main as follows:
public static void main(String[] args) throws RemoteException {
WORMSWSDAO wDAO = new WORMSWSDAO();
AphiaRecord [] result = wDAO.getAphiaChildrenByID(219275);
System.out.println(result[1].getFamily());
}
but after running that all I get is a null pointer exception..

Apache FTPClient and Apache FTPServer (JAVA)

Hello everyone my question is that I've created an FTP Server and FTPClient using Apache all in eclipse and everything seems to be working fine except the part when i try to upload a jar file which is for another code i wrote in java but it keeps corrupting and I've literally tried everything that i could find but it wouldn't work. So anybody who can help me or direct me to help would be greatly appreciated.
Thank You. I've attached both my Apache FTPServer code and FTPCLient again Thank You in advance.
serverFactory = new FtpServerFactory();
factory = new ListenerFactory();
factory.setPort(3232);
factory.setIdleTimeout(3000);
serverFactory.addListener("default", factory.createListener());
//serverFactory.setUserManager(addUser("jjj"));
userManagerFactory = new PropertiesUserManagerFactory();
//userManagerFactory.setFile(new File("C:/Users/Jean-Jacques/myusers.properties"));
userManagerFactory.setPasswordEncryptor(new PasswordEncryptor ()
{
public String encrypt(String password){
return password;
}
public boolean matches(String passwordTocheck, String storedpassword){
return passwordTocheck.equals(storedpassword);
}
});
serverFactory.setUserManager(addUser("jjj","hello"));
m = new HashMap<String, Ftplet>();
m.put("miaFtplet", new Ftplet()
{
#Override
public FtpletResult afterCommand(FtpSession session, FtpRequest request,
FtpReply reply) throws FtpException, IOException {
// TODO Auto-generated method stub
return FtpletResult.DEFAULT;
}
#Override
public FtpletResult beforeCommand(FtpSession session, FtpRequest request)
throws FtpException, IOException {
// TODO Auto-generated method stub
return FtpletResult.DEFAULT;
}
#Override
public void destroy() {
// TODO Auto-generated method stub
}
#Override
public void init(FtpletContext ftpletContext) throws FtpException {
// TODO Auto-generated method stub
}
#Override
public FtpletResult onConnect(FtpSession session) throws FtpException,
IOException {
// TODO Auto-generated method stub
return FtpletResult.DEFAULT;
}
#Override
public FtpletResult onDisconnect(FtpSession session)
throws FtpException, IOException {
// TODO Auto-generated method stub
return FtpletResult.DEFAULT;
}
});
server = serverFactory.createServer();
try{
server.start();
}catch(FtpException ex){
System.out.println("sorrty bro");
}
}
public UserManager addUser(String person, String pass) {
// TODO Auto-generated method stub
user = new BaseUser();
user.setName(person);
user.setPassword(pass);
//user.setHomeDirectory("C:/Users/Jean-Jacques/New Folder"); //by taking this out you can create any directory you want
userManagerFactory.setFile(new File("C:/Users/Jean-Jacques/myusers.properties"));
authorities = new ArrayList<Authority>();
authorities.add(new WritePermission());
user.setAuthorities(authorities);
um = userManagerFactory.createUserManager();
try{
um.save(user);
} catch(FtpException e){
}
return um;
}
here is the FTPCLient
private static void showServerReply(FTPClient ftpClient){
String[] replies = ftpClient.getReplyStrings();
if(replies != null && replies.length > 0){
for (String aReply : replies) {
System.out.println("Server: " + aReply);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String server = "localhost";
int port = 3232;
String user = "jjj";
String pass = "hello";
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(server, port);
ftpClient.enterLocalPassiveMode();
ftpClient.login(user, pass);
if(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)){
System.out.print("bbbbbb");
}
ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
showServerReply(ftpClient);
System.out.println("binary");
int replyCode = ftpClient.getReplyCode();
if(!FTPReply.isPositiveCompletion(replyCode)) {
System.out.println("Operation failed. server reply code: " + replyCode);
return;
}
boolean gone = ftpClient.changeWorkingDirectory("/upload"); // this removes directory from root
if(gone){
System.out.println("gone");
} else{
}
File dod = new File("C:\\Users\\Jean-Jacques\\New Folder\\BattleShip.jar");
String file = "BattleShip.jar";
//try{
input = new FileInputStream(dod);
System.out.println("its uploading");
OutputStream output = ftpClient.storeFileStream(file);
byte[] bytein = new byte[8192];
int read =0;
while((read = input.read(bytein)) != -1){
output.write(bytein, 0, read);
}
input.close();
output.close();
boolean yo = ftpClient.completePendingCommand();
if(yo){
System.out.println("yo");
}
} catch (IOException ex) {
System.out.println("Oops! ");
ex.printStackTrace();
}
finally{
System.out.println("finally");
try {
if(ftpClient.isConnected()){
ftpClient.logout();
ftpClient.disconnect();
System.out.println("connected");}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

Categories

Resources