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.
Related
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.
I am writing a server which uses a DatagramChannel (non-blocking) to send/receive data. It works flawlessly on my local network, but if I try to connect to it using the client application from a different network (i.e. over the internet), I cannot reach it.
Whilst running, if I use http://ping.eu/port-chk/ to check the port, it says it's closed. I have forwarded the appropriate ports and adjusted firewalls to appropriate levels.
My code is as follows:
public void runServer(int portNo)
{
try
{
serverChannel = DatagramChannel.open();
ipAddress = InetAddress.getLocalHost();
//ipAddress = InetAddress.getByName(getPublicIP());
//serverChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true); //Added in to try to fix
serverChannel.socket().bind(new InetSocketAddress(portNo));
serverChannel.configureBlocking(false);
serverChannel.socket().setReceiveBufferSize(receiveBufferSize);
serverChannel.socket().setSendBufferSize(sendBufferSize);
//serverChannel.connect(new InetSocketAddress(ipAddress,portNo)); //Added in to try to fix
serverRunning = true;
}
catch(IOException e)
{
e.printStackTrace();
}
}
The parts which are commented out have had no effect. The ipAddress variable in the example will fetch the local IP, where as the commented-out version will get the public IP of the computer.
If you could help me find out why I cannot connect to this port over the internet, I would be very grateful.
You haven't forwarded the ports correctly. Nothing to do with the code.
As #EJP has suggested, there doesn't seem to be anything wrong with my code. I have since hosted this server application using Amazon EC2, and it has worked flawlessly.
There is an issue with the firmware of my router which is preventing port forwarding.
I am implementing a client-server application . I am new to this . I tried following the article A Simple Java TCP Server and TCP Client
Actually i already have a client that works ( Not my code )
So i just need to write the server for it .
Also my server will be connected by only one client so i dont really see the need to support multiple clients .
As i see using netstat -a a listening server is created but the client fails to connect to it . There is no error message given out either which is suprising . Its as if the call to connect is ignored . No exceptions are seen on the client .
My Server Code ( Probably Faulty)
private static void create_request_server(int requestport) {
// TODO Auto-generated method stub
try {
ServerSocket s1 = new ServerSocket(requestport);
requestsocket = s1.accept();
// Do some stuff . But this accept never breaks.
} catch (Exception e) {
e.printStackTrace();
}
}
Correct Client
try {
fRequestSocket = new Socket("localhost", requestPort);
fRequestWriter = new PrintWriter(fRequestSocket.getOutputStream());
fRequestReader = new BufferedReader(new InputStreamReader(fRequestSocket.getInputStream()));
} catch (UnknownHostException e) {
abort(" UnknownHostException", e);
} catch (IOException e) {
abort(" IOException", e);
}
FYI
Both my client and server are on localhost
Is my server horribly incorrect ?
EDIT( Close to answer)
SO with the help of the valuable comments posted below i figured out what the problem is .
The issue is between localhost & 127.0.0.1
So i did a netstat -a and saw that a server is created as follows :
TCP [::]:56283 Sin-Host LISTENING
instead of
TCP 127.0.0.1:56283 Sin-Host LISTENING
Thus the client is unable to connect . Any ideas of how to make the server bind o 127.0.0.1
Any changes that can be made to ServerSocket s1 = new ServerSocket(requestport) ?
Sometimes there is a problem with localhost and 127.0.0.1
Try the ip in your client maybe this works.
Just to see it easier than in the comments with this constructor you maybe can configure your server:
new ServerSocket(1234,10,InetAddress.getByName("127.0.0.1"));
Have you tried checking your firewall?
Possibly your firewall is blocking the requests.
The way you set up a connection looks a lot like the way I do it. But it works fine here.
Once you have your socket, you still need to create an in and output stream to send and receive data from and to your server (lol grammar)
OutputStream writer = requestsocket.getOutputStream();
and
BufferedReader reader = new BufferedReader(new InputStreamReader(requestsocket.getInputStream());
Now whenever you want to send data to your client from your server you can do something like this:
writer.println("Data sending to client that's listening to my server");
Here is the code of the client class.
try {
//System.getProperties().put("https.proxyHost", "127.0.0.1");
//System.getProperties().put("https.proxyPort", "7575");
String endpoint = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName("AddSMSList"); // Change this to call
call.addParameter("validation", XMLType.XSD_STRING,
ParameterMode.IN); // Define Parameters
call.addParameter("XML", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
Object[] obj = new Object[] {
"POWERU-SMS",
getXML("13627621277", "testtime", "testtype", "testname",
"FAIL") }; // Assign value for the parameters
for (Object i : obj) {
System.out.println(i.toString());
}
String ret = (String) call.invoke(obj); // Call web service
System.out.println("Result : " + ret);
} catch (Exception e) {
e.printStackTrace();
}
The code itself i think is ok. The problem is the connection.
The Server is in china. And i use the code in Europe trying to reach the server.
I have to first start a vpn and after that i need to set up a jump server using putty(tunnel) When these are done i can acess the server via browser(proxy). But the java-client always gets a time out says
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.net.ConnectException: Connection timed out: connect
faultActor:
faultNode:
faultDetail:
Could someone please help me. Ive been working on it for 1 week.
Thanks in advance
I struggled with this on this and found a solution. If you're using Websphere add port 8080 to your virtual host's host aliases. The virtual host bound to the app you're trying to access. Hope this helps.
To me you seem to be experiencing a firewall issue and not a code issue, try the following from you command line. First do a telnet serverName port if this fails call your network admin and complete a traceroute with him sitting on the other side and the issue will be resolved.
Finally found the answer.
System.getProperties().put("socksProxyHost", "127.0.0.1");
System.getProperties().put("socksProxyPort", "7575");
instead of adding the https proxy i should've add the socks proxy!!!
This is a proxy server issue. It will be resolved if you provide the proxy server details in jboss standalone.xml file
-Dhttp.proxyHost=<proxy host>-Dhttp.proxyPort=<proxy port number>
I need to build an application which can receive data from over a network and use this data to do some unrelevant things with.
Here's a piece of code to make clear what I'm doing.
On the server side:
static Socket client = null;
static ServerSocket ss = null;
if (ss != null) {
ss.close();
}
ss = new ServerSocket(5513);
isrunning = true;
System.out.println("Waiting for client...");
client = ss.accept();
System.out.println("Client accepted.");
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
And the client side:
Socket client = null;
PrintWriter out = null;
try {
client = new Socket("hostname", 5513);
out = new PrintWriter(client.getOutputStream(), true);
}
Please note that this is just a piece of the code. There are no errors in the code.
After running the server-sided piece of code, it correctly waits for the client to connect.
Now here comes the problem. As soon as I try to connect from the client side, I'm getting a "connection refused"-error.
HOWEVER, I found something on the internet whoch told me to try telnetting from the client side. For example, let the server-sided IP be 192.168.1.1. So, after using this command:
telnet 192.168.1.1 5513
I actually get a connection with the server. The command will launch an empty screen, and everything I manually type in the command line will be sent to the server-side after pressing enter (checked with debugging).
So, I can manually connect to the server-side and send some data, but my code refuses to connect.
Anyone who knows what I am doing wrong?
Is this the code you're actually using?
client = new Socket("hostname", 5513);
Try changing it to:
client = new Socket("192.168.1.1", 5513);
client = new Socket("hostname", 5513);
Hostname needs to represent the IP Address you're connecting to. If you're trying to connect to yourself, it would be "localhost"
Also, the server is not listening for the client AT ALL TIMES, there must be a while loop so the server listens and accepts connections.
while (true) {
client = ss.accept();
out = new PrintWriter(client.getOutputStream(), true);
//You should probably assign it to a seperate thread to handle stuff for this client
}
And I should explain on why you're getting that particular error. When something says that the connection is refused, it usually means that the IP Address you want to connect to knows your sending a connection and is blocking it because it was not listening for that connection. Basically, when the server closed, you stopped listening for the client, so anything that came in on that port would be blocked. Of course, the other case could be that Java was blocked on your firewall and an exception should be made for it. Although this is rarely the case if what you're trying to accomplish is over a LAN.
You're not actually using "hostname" in your Socket object in the client are you?
It should the 192.168.1.1.
Are you on Windows? and If so have you added java.exe and javaw.exe to Firewall with inbound and outbound enabled? and have you added a rule for 5513 to your Firewall?
If yes Windows but no Firewall settings, that's your answer, open up your Firewall.