I'm trying to access online .Net Webservice through Java Webservice client.
But unfortunately, am getting an error "Connection timed out: connect"
Below is my code:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
public class WebServiceMain {
public static void main(String[] args) {
try {
String endpoint = "http://wsf.cdyne.com/SpellChecker/check.asmx";
Service service = new Service();
Call call = (Call)service.createCall();
call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
call.setProperty(Call.SOAPACTION_URI_PROPERTY, "http://ws.cdyne.com/CheckTextBodyV2");
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setPortName(new QName("http://ws.cdyne.com/", "check"));
call.setOperationName(new QName("http://ws.cdyne.com/", "CheckTextBodyV2"));
System.out.println(call.invoke(new Object[] {"helo is my name"}));
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
Connection timeout comes because of network issues.try to acess URL in browser.also try to append ?wsdl at the end of URL,you should see the wsdl.if this doesn't work troubleshoot network settings.
Connection timed out: connect
This means that your client application cannot even talk to the Web Service. This is not a programmatic issue.
Check and see whether you can access the end-point through your web browser. If not, then that service is not available. So it doesn't work.
If your browser can access it, and if you are connecting to Internet through a proxy, then you need to specify the proxy details to Java Client. To do that, you can use -Dhttp.proxyHost=10.2.240.11 and -Dhttp.proxyPort=8080 (replace with your values) system properties when you start up your client application.
Download the soapui software and get installed it.
then load the wsdl file and create the project.
Then test your web service via soap ui.
you can edit the connection timeout value of the soap ui. chane it for big vlue and test.still your getiong time out ping to the ip addres of the service
Related
Description:
Trying to send requests to an application that tries to access a Netopeer2 server, but a problem happens and the key exchange fails. There are solutions out there how to configure it on the server side in /etc/ssh/sshd_config, but we want it to be on the client side that is in the application.
The application uses Apache MINA SSHD to establish the connection (GitHub). By default, certain algorithms are disabled. We want to enable them in that Main class below to be able to exchange rsa-sha2-512, rsa-sha2-256 with the server. Any idea on how to do that with Apache MINA SSHD?
The full error message says:
java.lang.IllegalStateException: Unable to negotiate key exchange for server host key algorithms
(client: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,ssh-rsa,ssh-dss /
server: rsa-sha2-512,rsa-sha2-256)
The code that throws the error:
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.session.ClientSession;
import java.io.IOException;
public class Main{
public static void main(String[] args) {
SshClient client = SshClient.setUpDefaultClient();
client.start();
try {
ClientSession session = client.connect("root", "172.17.0.2", 830).verify(10000).getSession();
session.addPasswordIdentity("root");
session.auth().verify(9999);
// error 'Unable to negotiate key exchange for server host key algorithms' is thrown
}
catch (IOException e){
e.printStackTrace();
}
}
}
I'm also not solving my own problem but I am in the same zone as you. But for me, looking at SSHD log I think I see the client offering rsa_sha2_512 and the (one) server rejecting that and dropping the connection request.
Here is a little Scala snippet that didn't change anything for me. I think this is what you get if you don't set it; every default factory (that I found).
import org.apache.sshd.common.kex.{BuiltinDHFactories, KeyExchangeFactory}
val kexList: util.List[KeyExchangeFactory] = {
val kex = List(
BuiltinDHFactories.dhg1,
BuiltinDHFactories.dhg14,
BuiltinDHFactories.dhgex,
BuiltinDHFactories.dhg14_256,
BuiltinDHFactories.dhg15_512,
BuiltinDHFactories.dhg16_512,
BuiltinDHFactories.dhg17_512,
BuiltinDHFactories.dhg18_512,
BuiltinDHFactories.dhgex256,
BuiltinDHFactories.ecdhp256,
BuiltinDHFactories.ecdhp384,
BuiltinDHFactories.ecdhp521)
val dh2kex = kex.map(k => ClientBuilder.DH2KEX(k))
dh2kex.asJava
}
session.setKeyExchangeFactories(kexList)
Or this in Java:
List<KeyExchangeFactory> kexList =
BuiltinDHFactories.VALUES.stream().map(ClientBuilder.DH2KEX).collect(Collectors.toList());
Below should solve the problem.
client.setKeyExchangeFactories(NamedFactory.setUpTransformedFactories(
false,
BuiltinDHFactories.VALUES,
ClientBuilder.DH2KEX
));
client.setSignatureFactories(new ArrayList<>(BuiltinSignatures.VALUES))
For putty support
https://github.com/apache/mina-sshd/blob/master/docs/files-parsing.md
Simply add the following
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-common</artifactId>
<version>...same version as the rest of the artifacts...</version>
</dependency>
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-putty</artifactId>
<version>...same version as the rest of the artifacts...</version>
</dependency>
I have a standalone zookeeper server running.
client = CuratorFrameworkFactory.newClient(zkHostPorts, retryPolicy);
client.start();
assertThat(client.checkExists().forPath("/")).isNotNull(); // working
listener = new LeaderSelectorListenerAdapter() {
#Override
public void takeLeadership(CuratorFramework client) throws Exception {
System.out.println("This method is never called! :( ");
Thread.sleep(5000);
}
};
String path = "/somepath";
leaderSelector = new LeaderSelector(client, path, listener);
leaderSelector.autoRequeue();
leaderSelector.start();
I am connecting to the server successfully, defining a listener and starting leader election.
Note: There is only 1 client.
But my client app is never taking leadership. I am not able to figure out what I am doing wrong. Also this is a trivial single client scenario. Shouldn't the client already be a leader
EDIT:
It works if I use TestingServer from curator-test library instead of starting my Zookeeper server, like below -
TestingServer server = new TestingServer();
client = CuratorFrameworkFactory.newClient(server.getConnectString(), retryPolicy);
...
Does this mean there is something wrong with my zookeeper server.
This is my zoo.cfg -
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/tmp/zookeeper/ex1
clientPort=2181
Also, the server appears to be working fine as I am able to connect to it using cli and am able to create/delete zNodes.
I need to build a (standalone Java) restlet-based service that only listens on localhost, i.e. no requests from network are allowed.
I was trying to do the obvious:
Server srv = new Server(Protocol.HTTPS, "localhost", httpsPort);
component.getServers().add(srv);
But the service still listens on 0.0.0.0. :-(
I went into the code and found that HttpsServerHelper ignores the hostname when creating the service:
this.server = HttpsServer.create(new InetSocketAddress(getHelped().getPort()), 0);
Similar code exists in plain HTTP's HttpServerHelper, where it is even more clear.
My question then is this:
How can I configure Restlet component/service to only listen on localhost?
I don't know which server you use under the hood within your standalone Restlet application. You should use a server connector other than the default one and I recommend you to use the Jetty one.
To do that, simply put the jar of the extension org.restlet.ext.jetty in your classpath.
In this case, using the following code should correspond to your needs:
component.getServers().add(Protocol.HTTP, "localhost", 8182);
Here is the corresponding trace at application startup:
2015-09-03 09:47:22.180:INFO::jetty-7.1.6.v20100715
2015-09-03 09:47:22.211:INFO::Started SelectChannelConnector#localhost:8182
In addition, here is the link in the Restlet documentation regarding Restlet connectors: http://restlet.com/technical-resources/restlet-framework/guide/2.3/core/base/connectors.
Hope it helps you,
Thierry
The easier way to achieve that is to use virtual hosts.
Virtual hosts are the first routing barrier when handling a request, especially it helps routing on a domain.
Here is a sample code that illustrates this:
Component c = new Component();
c.getServers().add(Protocol.HTTP, 8182);
VirtualHost host = new VirtualHost();
host.setHostDomain("localhost");
c.getHosts().add(host);
host.attach(new Restlet() {
#Override
public void handle(Request request, Response response) {
response.setEntity("hello, world", MediaType.TEXT_PLAIN);
}
});
c.start();
Usually, applications are attached on the default host of a component. This default host does nothing, except routing requests based on the context path of the attached application:
c.getDefaultHost().attach("/contextPath1", new Test1Application());
c.getDefaultHost().attach("/contextPath2", new Test2Application());
When you would like to filter calls based on other data than the request's path, virtual host may be the solution.
Here is a diagram that may help you:
http://restlet.com/technical-resources/restlet-framework/tutorials/2.3#part05
We are building a websocket webapp for a school project and would like to store the incoming information to MySQL. Currently we are using netbeans and the Server Endpoint is written in Java. The info sent from the client side is a JSON obj. We can decode it but dont't know how to insert it into the table
Problems we are facing
1.We are used to programming Java application and using mysql JDBC but this time we cannot find the library to add, like we use to do.
2.We have tried AJAX but since the PHP is on a different server we cant do it, and I can't find the option to add a PHP file to the current project in netbeans. -- Currently I'm trying to learn how to do AJAX with JSP
3.We think we need to spin a thread so that the reply doesn't have to wait for the insert to complete but when we try to spin a thread the Endpoint no longer works, so we commented it out
4.We are trying to keep third party Frame works to a minimum
Below is the code to our Server Endpoint
public void onMessage(String message, Session session) {
// Create JsonObject from message
JsonObject jsonObject = new Message(message).getJObject();
// Decode JsonObject
message = Decoder(jsonObject);
for (Session peer : peers) {
try {
if (!peer.equals(session)) {
peer.getBasicRemote().sendText(message);
}
} catch (IOException ex) {
Logger.getLogger(ServerEndpoint.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
This is our current decoder. We wanted to spin a thread from this function, I don't know if that is a good idea or not
public String Decoder(JsonObject jObject) {
String message;
message = jObject.getString("msg");
return message;
}
Since Netbeans use Glassfish, I downloaded the MySQL JDBC and put it in the lib folder as I would if I was running Tomcat. Then I go into the Admin console and added the JDBC Connector then added the JDBC Resource. Next restart the server then redeploy the app.
I am novice in soap and jax-ws.
After reading many information I knew that eclipse can catch soap messages, But I have problem with it.
my publisher
public static void main(String[] args) {
Endpoint.publish("http://localhost:8081/WS/Greeting",
new GreetingImpl());
}
my cient
public static void main(String[] args) {
GreetingImplService service = new GreetingImplService();
Greeting greeting = service.getGreetingImplPort();
System.out.println("------->> Call Started");
System.out.println(greeting.sayHello("friend !!!"));
System.out.println("------->> Call Ended");
}
When I invoke client in Console I see
------->> Call Started
Hello, Welcom to jax-ws friend !!!
------->> Call Ended
Therefore it is working service.
But in TCP|IP monitor I see empty list.
my configuration of TCP|IP monitor
What Do I make wrong?
please, help)
I think that the probelm is that your client is pointing directly to port 8081 (the port of the ws) so the tcp/ip monitor does not come into play. Since the monitor is listening on port 8080, your client should use this endpoint:
http://localhost:8080/WS/Greeting
The TCP/IP monitor will receive the http request and then it will forward the message to
http://localhost:8081/WS/Greeting
To alter the endpoint used by the client you have 2 possibilities:
If the client uses a local wsdl document (for example you have saved a copy of the wsdl on your file system and used it to call wsimport), you can modify the endpoint in it (look at the element service at the end of the wsdl). The stub returned by service.getGreetingImplPort() reads the endpoint from the wsdl.
You can use this instruction in the main method of the client
((BindingProvider) greeting).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,"http://localhost:8080/WS/Greeting");