How to authenticate in Remedy using Java - java

I need to authenticate myself in Remedy. I'm following the documentation, but I still getting some errors.
https://communities.bmc.com/docs/DOC-17514
This is my code:
import com.bmc.arsys.api.ARException;
import com.bmc.arsys.api.ARServerUser;
public class Tutorial {
public static void main(String[] args) {
ARServerUser ctx = new ARServerUser();
ctx.setServer("127.0.0.1");
ctx.setUser("myusername");
ctx.setPassword("mypassword");
ctx.setPort(8080);
try {
ctx.verifyUser();
} catch (ARException e) {
System.out.println(e.getMessage());
}
}
}
I'm receiving this error:
ERROR (91): RPC call failed; 127.0.0.1:8080 can not receive ONC/RPC data
How can I fix that? I need to set the instance, like 127.0.0.1/arsys. My Remedy instance is arsys.
I can authenticate using the browser: http://127.0.0.1:8080/arsys
Thanks in advance.

is your midtier on the same server as your AR server?
if not, then You need to set the IP of your AR server instead.

Since you have mentioned that you are able to authenticate using http://127.0.0.1:8080/arsys via browser, it means that 8080 is being used by web server and AR Server can't use the same. Please provide your port number(where your AR Server is listening) in setPort(). Also try to make sure that your hostname/ip address is reachable from the machine where you are executing your program.

The setServer parameter expects the name of the ARS server, not the IP address. Here is the matching constructor signature:
ARServerUser(java.lang.String user, java.lang.String password, java.lang.String locale, java.lang.String serverName, int serverPort)
References
com.remedy.arsys.api.ARServerUser
How to authenticate in Remedy using Java

Related

java.net.ConnectException: Connection timed out: connect in Eclipse

I am trying to consume below public web service using Eclipse.
http://www.webservicex.com/globalweather.asmx?wsdl
When I execute in the java client it gives the error;
java.net.ConnectException: Connection timed out: connect
Below is the simple client program;
public class ClientTest1
{
public static void main(String[] args)
{
GlobalWeatherSoapProxy obj1 = new GlobalWeatherSoapProxy();
try
{
System.out.println(obj1.getCitiesByCountry("Japan"));
}
catch(Exception e1)
{
System.out.println(+e1.getMessage());
}
}
}
However strangely this works fine when consumed through SOAP UI. Hence I assume this is something to do with Eclipse configuration.
Thank you in advance for any help.
Eclipse has nothing to do with it. Your code is executed by the JVM, even if your development environment is Eclipse. A connection time out means that your client is not able to connect with the endpoint.
You have auto-generated the client proxy in some way getting GlobalWeatherSoapProxy. This class will obtain the reference to endpoint by loading WSDL. Alternatively url can be provided by code. Review the content of that class to see how endpoint URL is loaded
You should see something like (check this full example)
URL url = new URL("http://localhost:9999/ws/hello?wsdl");
QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);

How to discover the IP address of a Tomcat server on a network?

I have a Android application which consumes a webservice on a local network. There's a config screen where the user inform the server IP address, which is running Apache Tomcat.
I'm looking for a way to auto-detect the server based on the current connected wi-fi network.
i.e: The smartphone's IP is 10.1.1.90 and the server IP is 10.1.1.254.
Is there a way to achieve this? I'm thinking on using ping, but I don't know if is a good ideia.
The way I understand it, you need to discover IP of your tomcat server and connect it using your client.
I am assuming , both the server and client is in your control.
One simple way can be to use jGroups Cluster.
You can make your tomcat discoverable
Client can discover it using the name of the cluster you have provided .Refer the JChannel API that Jgroups uses
I simulated it making following server class
public class TomcatServer {
JChannel channel;
private void start() throws Exception {
channel = new JChannel(); // use the default config, udp.xml
channel.connect("TomcatCluster");
}
public static void main(String[] args) throws Exception {
new TomcatServer().start();
}
}
The simulated client class
public class MobileApp extends ReceiverAdapter {
JChannel channel;
private void start() throws Exception {
channel = new JChannel(); // use the default config, udp.xml
channel.setReceiver(this);
channel.connect("TomcatCluster");
channel.close();
}
public static void main(String args[]) throws Exception {
new MobileApp().start();
}
The client will provide you following information
GMS: address=MACHINENAME-47879, cluster=TomcatCluster, physical address=xxxxx:0:xxx:xxxx:xxxx:xxxx:xxx:xxxx:xxxx
** view: [MACHINENAME-31239|1] [MACHINENAME-31239, MACHINENAME-47879]
Where MACHINENAME-47879 is the client machine and port & MACHINENAME-31239 is the tomcat server name and port
Do you want to detect "a tomcat server" or "your tomcat server" ?
I mean, do you have any way to custom your server ? If it's the case, then you could create a very simple test page on your server (say a "Hello" JSP page), which your Android application could look for.
If your Android gets a "Hello" result with a GET request on http://<tomcat_ip>/hello.jsp, then you may assume that the tomcat is online.
If you can't add this test page, then you can test any page which the server is supposed to serve. (even a 404 page which sometimes is not configured well, and shows the tomcat version...)
Tomcat response headers can contain the xpoweredBy field that would advertise Tomcat if enabled. However it is most often disabled due security considerations, and even disabled by default. You however could re-enable it if you need to auto-detect exactly your Tomcat servers. From the other side, indeed, if you can place a web page on your server, you can simply place a marking page with the agreed signature.
If the server IP is unknown, I would propose the following ways to detect the server on the network:
The most straightforward way is to do the breadcast ping (ping -b broadcast_address where breadcast address can be computed here, for instance). All network devices that are configured so would reply, then verify as explained above which one is the server. However pinging broadcast address requires a rooted phone. Also the router may not support.
Your DHCP service (most likely your router) can often be configured to issue always the same IP address for the same MAC address of your server network card.
If the server is a desktop computer or laptop, it could show its address as QR code on display. It is possible for a smartphone to scan the code from the screen, and this is way easier than to enter IP address through the touchscreen. QR code can also include auto-generated password for extra security.
If there is wireless router with the possible login where both server and client are connected, the internal pages of that router often contain the relevant IP addresses. You would need to implement logging into the router and doing some screen scrapping.
I made an Android app which used a local server in the WLAN. I made the terminal (the phone) broadcast it's own IP address, which the server then picked up.
I used MultiCast class on the phone, which added the ip-address of itself to the payload. The server always has a thread in multicast read class that obains the payload of the packet (which is the terminals ip-address). Set the terminal in datagram read state and send the servers ip-address to terminal.
Maybe are better ways, but a great way to get the ip-addresses of unknown terminals in the network.
The way i had resolved this problem is with the use of enumerations.
public String getLocalIpAddress()
{
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
return inetAddress.getHostAddress().toString();
}
}
}
} catch (Exception ex) {
}
return null;
}
}

Sending email with java Apache Commons Mail through Lotus Notes

I'm having trouble with my e-mail configuration for sending e-mails using lotus notes in a java program. I know this is pretty much straight forward but i guess i'm missing something. My code is as follows;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
public class MailClass {
public void SendMail() {
SimpleEmail email = new SimpleEmail();
try {
email.setHostName("mail.smtp.host");
email.addTo("recipient#company.com");
email.setFrom("sender#agency.com");
email.setSubject("Hello World");
email.setMsg("This is a simple test of commons-email");
email.send();
} catch (EmailException ex) {
Logger.getLogger(MailClass4.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
MailClass main = new MailClass();
main.SendMail();
}
}
I keep on getting this error
SEVERE: null
org.apache.commons.mail.EmailException: Sending the email to the following server failed : mail.smtp.host:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
...
Caused by: javax.mail.MessagingException: Unknown SMTP host: mail.smtp.host;
nested exception is:java.net.UnknownHostException: mail.smtp.host at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1970)
I'm guessing it's about my host but not really sure what to do about it. From my understanding your host should be your email client (ex. mail.smtp.google.com). But since this is Lotus Notes (it runs in our intranet btw) the implimentation will be different. I've seen other samples that use the "mail.smtp.host" as host but i can't get this one right....
It's my first time doing an e-mail program so i'm pretty much clueless about this.
You can use your Domino server running on your intranet as SMTP server but first you have to ask your admin if Domino has been set up to allow SMTP - and at the same time ask for the proper host name and port).
setHostName requires the hostname or IP-address of a smtp server. And the exception makes it very clear what the issue is.
Lotus Notes is basicslly just a client and has nothing to do with what you are trying to accomplish.

Java RMI connection to localhost at home network can't find correct remote module

I have been working on this project where two modules on different machines need to be in communication through RMI.
I start both client and server modules on my laptop. RMI seems to work correctly when i am at work and connected to work network, but when i am home, connected to my home network it does not work. It says remote object could not be found.
Here is the method i use at CLIENT side to get the reference to remote object
public static MyRMIApp getRemoteApp() throws RemoteException, NotBoundException, AccessException {
Registry registry = LocateRegistry.getRegistry("localhost", 28999); // tried 127.0.0.1 instead of localhost here, still not working
MyRMIApp app = (MyRMIApp) registry.lookup("COM");
return app;
}
Digging up a bit with some debugging, when i check the object value returned from getRemoteApp method, it shows me the end point is 67.215.65.132. Which is openDNS i am using to connect to internet. Shouldn't that be 127.0.0.1 ?
Then i used my mobile internet and tried again. It seems to be working but end-point is not 127.0.0.1 again it is the address assigned to me, which is 192.168.x.x
So can anybody please tell me what is wrong i am doing here ? I really would appreciate the help.
Oh and this is the piece of code at SERVER side
//Somwhere up top
private final static MyRMIApp rmiApp = new RMIServer();
//Down below
MyRMIApp stub = (MyRMIApp) UnicastRemoteObject.exportObject(rmiApp, 0);
Registry registry = LocateRegistry.createRegistry(28999);
registry.rebind("COM", stub);
See item A.1 of the RMI FAQ: specifically, 'The appropriate workaround is to set the system property java.rmi.server.hostname when starting the server.'

"org.apache.axis2.AxisFault: unknown" when calling web service with Java

I'm trying to call a web service with a Java client. The WSDL looks like this: http://pastebin.com/m13124ba
My client:
public class Client{
public static void main(java.lang.String args[]){
try{
CompileAndExecuteServiceInterfaceStub stub =
new CompileAndExecuteServiceInterfaceStub
("http://192.168.1.3:8080/axis2/services/CompileAndExecuteServiceInterface");
Compile comp = new Compile();
comp.setArgs0("Test");
comp.setArgs1("public class Test { public static void main(String[] args) { System.out.println(\"Hello\");}}");
String[] classpath = {};
comp.setArgs2(classpath);
stub.compile(comp);
} catch(Exception e){
e.printStackTrace();
}
}
}
When I run the client now the following error occurs:
org.apache.axis2.AxisFault: unknown
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:517)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:371)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at de.dax.compileandexecuteclient.CompileAndExecuteServiceInterfaceStub.compile(CompileAndExecuteServiceInterfaceStub.java:184)
at de.dax.compileandexecuteclient.Client.main(Client.java:17)</blockquote>
I tried out the business logic of the server on my local machine and there it works. The service creates files and folders. Are web services allowed to do that? I also wrote a simple "Hello World" web service and deployed it to the server. This worked fine.
When you get one of these "unknown" AxisFaults, definitely check the server log! The client-side stack trace most likely will not be detailed enough for you to track down the error.
I believe dax is indicating above that he found the NullPointerException in the more-detailed server side stack trace. It would look something like:
org.apache.axis2.AxisFault
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
[....]
Caused by: java.lang.NullPointerException
[....]
From the provided logs, I cannot determine what's wrong. Try to set the log-level of Axis2 to "debug" (see the two log-configurations in the root directory of your Axis2 installation) and check the details for the exact cause. Axis2 tends to be a bit sparse in propagating the errors coming from webservices.
The problem was that there was an NullPointerException in my service.

Categories

Resources