I`m trying to test connection timeout property for jaxws client which is deployed on IBM Websphere Application Server 8.5. I set timeout properties the following way:
((BindingProvider) port).getRequestContext().
put(com.ibm.wsspi.webservices.Constants.RESPONSE_TIMEOUT_PROPERTY, "30");
((BindingProvider) port).getRequestContext().
put(com.ibm.wsspi.webservices.Constants.CONNECTION_TIMEOUT_PROPERTY, "15";
RESPONSE_TIMEOUT_PROPERTY works fine.
But I have no idea how to test CONNECTION_TIMEOUT_PROPERTY. If webservice is not available during creating an instance of Service I get the following exception:
javax.xml.ws.WebServiceException: The following WSDL exception occurred:
WSDLException: faultCode=WSDL4JWrapper : : javax.wsdl.WSDLException:
WSDLException: faultCode=WSDL4JWrapper : :
java.net.ConnectException: Connection refused: connect
If webservice is not available during creating port(invoking getPort(...) method) I get the following exception:
javax.xml.ws.WebServiceException:
java.net.ConnectException: HTTP ( 404 ) Not Found address :
http://myhost:myport/WsServer/helloService
Exceptions are thrown immediately. I suppose I do something wrong. Any pointers would be helpful.
There needs to be a socket open on the server to accept the connection.
Try something like the following
public static void main(String[] args) {
int port = Integer.parseInt(args[0]);
try (ServerSocket serviceStub = new ServerSocket(port)) {
while (true) {
serviceStub.accept();
System.out.println("Something connected");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
}
}
Run this on the server (with whatever port you need). It will accept a connection but will never do anything which ought to simulate your timeout.
Generally, anything that listens on a port and does nothing should fit the bill.
Related
I am having sandbox account of Avalara(Avatax) and that is working fine on my local system and also on the staging environment. But the same sandbox credentials are not working on the UAT instance.
Error logged: avaTaxConnection java.net.SocketException: Connection reset
This is the code snippet I used :
try {
client = new AvaTaxClient("PriceBook", "1.0", "https://sandbox-
rest.avatax.com/api/v2/utilities/ping", AvaTaxEnvironment.Sandbox).withSecurity(PropertiesFileConfiguration.Avatax_AccountID,
PropertiesFileConfiguration.Avatax_LicenseKey);
PingResultModel ping = client.ping();
if (ping.getAuthenticated()) {
return client;
}
} catch (Exception e) {
LOGGER.error("ERROR in avaTaxConnection " + e);
}
When I am trying to get PingResultModel ping on the basis of the client object getting the exception: avaTaxConnection java.net.SocketException: Connection reset.
I have also checked whether the connection is created or not, but the connection is created successfully. I printed the connection object in logs.
I'm trying to set up a simple test FTPS server in Java using Apache FtpServer and connect to it using a domain name instead of the IP address.
I've pointed the A record to the IP address and set up the SSL certificate. Based on the Apache FtpServer documentation, here is what my code looks like so far:
FtpServerFactory ftpServerFactory = new FtpServerFactory();
ListenerFactory listenerFactory = new ListenerFactory();
listenerFactory.setPort(990);
listenerFactory.setServerAddress("example.com");
SslConfigurationFactory sslConfigurationFactory = new SslConfigurationFactory();
sslConfigurationFactory.setKeystoreFile(JKS);
sslConfigurationFactory.setKeystorePassword(JKS_PASS);
listenerFactory.setSslConfiguration(sslConfigurationFactory.createSslConfiguration());
listenerFactory.setImplicitSsl(true);
ftpServerFactory.addListener("default", listenerFactory.createListener());
PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
userManagerFactory.setFile(USERS_PATH.toFile());
BaseUser test = new BaseUser();
sample1.setName("test");
sample1.setPassword("test");
sample1.setHomeDirectory(HOME.getAbsolutePath().toString());
test.setAuthorities(List.of(new WritePermission());
UserManager userManager = userManagerFactory.createUserManager();
try {
userManager.save(test);
}
catch (FtpException e) {
e.printStackTrace();
}
ftpServerFactory.setUserManager(userManager);
FtpServer server = ftpServerFactory.createServer();
try {
server.start();
}
catch (FtpException e) {
e.printStackTrace();
}
However, when I try to connect to the FTPS server, I get an ECONNREFUSED - Connection refused by server from my FTPS client.
Are there any steps that I missed?
If your client reports a 'connection refused' that usually indicates (no guarantee) that no firewall prevented the TCP traffic, the connection request ended up on the intended machine but nothing was accepting the connection on the port you tried to connect to.
Things you can check:
Was the server process running? Was the server process on the correct port? Did the client connect to the correct port?
You might try to connect with another client (e.g. curl) just to see whether the TCP connection can be established.
You might try to connect to another port (e.g. 22 / ssh) to see if the client can establish the connection.
My problem is: I need to discovery if one IP and Port is running a SMTP service.
To do this, I'm using SMTPClient to try open a connection. I'm using the code below.
private static boolean validateSMTP(String ip, int port, int timeOut) {
SMTPClient smtp = new SMTPClient();
try {
smtp.setConnectTimeout(timeOut);
smtp.connect(ip, port);
return true;
} catch (SocketException e) {
LogAplication.Warning("Ops... something wrong", e);
} catch (IOException e) {
LogAplication.Warning("Ops... something wrong", e);
}
finally{
smtp = null;
}
return false;
}
It's working fine and I've gotten the expected results, but the timeOut has been my problem.
E.g: If I try ip: 127.0.0.1 and port 80 (IIS open port) the connect step takes a long (much more than is defined in timeout) to throw an exception
java.net.SocketException: Connection reset
How can I set timeOut for this case? Or existis another way to do my simple test ?
After take a look at grepCode, I found this for method connect(string host, int port):
Opens a Socket connected to a remote host at the specified port and
originating from the specified local address and port. Before
returning, _connect Action() is called to perform connection
initialization actions.
As the port is opened by another service, the socket is opened, not causing timeOut (by socket), but the exception was thrown by "connectAction()"
So I needed to set a global timeOut for my SMTPClient, which is used by socket connection and inside of "connectAction()" . And I did this to solve my problem:
smtp.setDefaultTimeout(timeOut);
With this, now I've the expected results for, open ports which throws exceptions and of course, the successfully connection for SMTP services.
I want to edit the RMI hello world example to work with client and server on different machines, but i'm stuck with the unmarshalling return error.
If i run client and server in the same project on Netbeans they work fine but when i split them i edited the try statement on the client side to be:
try {
Registry registry = LocateRegistry.getRegistry("localhost");
String[] c = registry.list();
System.out.println(c[0].toString());
Remote lookup = Naming.lookup("HelloServer");
} catch (Exception e) {
System.out.println("HelloClient exception: " + e.getMessage());
}
without Remote lookup = Naming.lookup("HelloServer");, the print command gives "HelloServer" which is correct, but when i create the remote object I'm getting this error:
HelloClient exception: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: rmimain.Hello
I've tested the policy and it's working fine, any help would be much appreciated.
Your client doesn't have the rmimain.Hello class on its CLASSPATH.
I have created web service client using NetBeans.
Some of the code:
...
mtsvmi.MGWPUBLICFUNCTIONSService service = new mtsvmi.MGWPUBLICFUNCTIONSService();
mtsvmi.MGWPUBLICFUNCTIONSPortType proxy = (service.getMGWPUBLICFUNCTIONSPort());
((BindingProvider)proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "username");
((BindingProvider)proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");
QName portQName = new QName("http://xmlns.oracle.com/orawsv/SISTEMA_MOKA/MGW_PUBLIC_FUNCTIONS", "MGW_PUBLIC_FUNCTIONSPort");
String req = "<INSERT_RECEIVES xmlns=\"https://IP:PORT/orawsv/test/SISTEMA_MOKA/MGW_PUBLIC_FUNCTIONS\"><parameters>"+pingKonteineris+"</parameters></INSERT_RECEIVES>";
try { // Call Web Service Operation
Dispatch<Source> sourceDispatch = null;
sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
Source result = sourceDispatch.invoke(new StreamSource(new StringReader(req)));
// System.out.println("---Ans: "+result.toString()+"---");
} catch (Exception ex) {
System.out.println(ex);
}
...
gives me:
com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: Connection refused: connect
What did I do wrong? How do I fix this? What other info do you need to help me out in here?
The ConnectException you get means that your app was not able to establish a socket connection to its target. Typically this means that you've given the wrong hostname or port, or that the service on the other end isn't running.
From what you've posted it's not clear exactly what line of code threw the failure, or what address the connection attempt was made to. However I would hazard a guess that it's the line where you call sourceDispatch.invoke - and that the MGWPUBLICFUNCTIONSService class is responsible for providing the address.
I suggest that you look into the logs, error messages and/or configuration to find out what address is being used and why a connection can't be established to that address. Using telnet to try and establish connections yourself may be very helpful in preliminary investigation.
I faced this issue. and i resolved it by changing in .wsld file
<service name="CalculatorService">
<port binding="tns:CalculatorPortBinding" name="CalculatorPort">
<soap:address
location="http://localhost:6060/WebServiceProject/CalculatorPort" />
</port>
</service>
whre my port number was 8080 and changed to 6060 which i am using.
may it ll help u. try it.