So I have been working on a web service which communicates between the client and server. It fully works on my computer and am able to send requests from client to server while not in the same package.
I am hosting my service like:
public class WebServiceServer {
public static void main(String[] args) {
String bindingURI = "http://localhost:4040/absolute/uploadService";
FileReceive service = new FileReceiveImpl();
Endpoint.publish(bindingURI, service);
System.out.println("Server started at: " + bindingURI);
}
}
And my client connects to my service like:
public static void main(String args[]) throws Exception {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(FileReceive.class);
factory.setAddress
("http://localhost:4040/absolute/uploadService");
FileReceive client =(FileReceive) factory.create();
From this point I would like to make the web-service public(able to connect from outside of the local-host). I installed ruby and ruby gems only to find out the local-tunnel is no longer available. I have then moved to using ngrok which forwarded a URL for me, but I cannot get any post requests to go through to it(as if it was my web-service) only get methods as I type the URL into my web-browser. Is anyone aware of any easier to use hosting services so that someone (outside of local-host) can post a file to my web-service? Thanks.
Related
I'm trying to use cloudrail SDK in my java desktop app for testing ,
but I have problem with runing the sample code in cloudrailsite;
the following codes are main class:
public class DropboxWithCloudRail {
private static String REDIRECT_URL = "http://localhost:3000/";
InputStream inputStream = null;
public void loadDropbox() throws FileNotFoundException, ParseException {
CloudRail.setAppKey("*************");
Dropbox service = new Dropbox(new LocalReceiver(8082),
"*************",
"*************",
REDIRECT_URL,
"Dropbox"
);
service.createFolder(
"/myFolder1"
);
}
}
I set the Redirect URIs in dropbox console http://localhost:3000/
but when I run the project , I get this page:
This site can’t be reached
localhost refused to connect.
Did you mean http://localhost3000.org/?
Search Google for localhost 3000
ERR_CONNECTION_REFUSED
The issue seems to be that you configure your LocalRedirect receiver with the port 8082 which makes it wait for incoming redirects on http://localhost:8082. So this is the URL you have to use as a redirect uri for Dropbox and not http://localhost:3000.
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);
I'm testing PHP/Java Bridge connection. And I have a simple example yet.
The php file is:
require_once("http://localhost:8087/JavaBridge/java/Java.inc");
$world = new java("HelloWorld");
echo $world->hello(array("from PHP"));
And the java file:
import javax.swing.JOptionPane;
public class HelloWorld {
public static final String JAVABRIDGE_PORT="8087";
static final php.java.bridge.JavaBridgeRunner runner =
php.java.bridge.JavaBridgeRunner.getInstance(JAVABRIDGE_PORT);
public static void main(String args[]) throws Exception {
runner.waitFor();
System.exit(0);
}
public void hello(String args[]) throws Exception {
JOptionPane.showMessageDialog(null, "hello " + args[0]);
}
}
Everything works fine on one pc. But I have to implement connection from PHP server to java desktop application which is on the another server not on localhost, so "localhost:8087/JavaBridge/java/Java.inc" won't work. In future this java app will print on printer some data from php website.
So I need to call java function remotely. It should be a desktop App because I will write usb connection in future. Please help me, thanks.
You can't use require_once to include files from another host.
If this option is available, a lot of websites will be at risk.
Why don't you use it from another way, Here are some points that may help:
make java calls PHP.
write your result to some file in the destination server.
Make server reads that file.
If you don't like that, please read about web service, it may have what you need.
I am pretty new to java and REST, in an application I am currently working on resources/tasks such as bug tracking are to be consumed from launchpad.net in a restful manner. There is an official python library (launchpadlib) that supports such interactions, but I want to do this using Java. I have looked around for samples to get me running to no avail. Does anyone have experience this in Java? Any insights is highly appreciated.
public class LaunchPad_Gatherer {
public static void main(String[] args) {
Client client = ClientBuilder.newClient();
ClientConfig config = new ClientConfig();
//WebTarget target = client.target("http://api.launchpad.net/1.0");
//WebTarget target = client.target("https://api.launchpad.net/1.0/bugs/cve/2015-5223/bugs");
WebTarget target = client.target("https://api.launchpad.net/1.0/bugs/cve");
System.out.println(target.request(MediaType.APPLICATION_JSON).get(String.class));
}
}
What is the method call to figure out what is the url and port a jetty servlet is running on? So that I can just print it on the screen, and use it in the client to connect:
url = new URL("trying to figure this out");
I am running both the client and the server locally, in eclipse, this is a school project.
Relevant code:
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
public class ServerMain {
public static void main(String[] args){
Server server = new Server();
ServletContextHandler context =
new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("Servlet");
context.setResourceBase("etc/docroot");
server.setHandler(context);
context.addServlet(new ServletHolder(new MyServer()), "/game");
DefaultServlet staticFileServlet = new DefaultServlet();
context.addServlet(new ServletHolder(staticFileServlet), "/*");
System.out.println("context: " + context.getContextPath());
//System.out.println("One valid Port = "
+ context.getServer().getConnectors()[0].getPort());
try {
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Since you are doing this embedded you have a couple of options.
Server server = new Server(8080);
This will start the server on port 8080, which is fine if that is what you want but in unit tests you generally want this to be a random port to avoid issues with things like CI's or parallel tests tripping on each other.
Server server = new Server(0);
This will start the connector on a random port, but how to get that port?
server.getConnectors()[0].getLocalPort();
The port is really coming from the connector, and typically you only are setting up one connector here, so this gets you that port.
Now localhost works for testing well, but if you wanted the name of the host that the connector is on you can use this:
server.getConnectors()[0].getHost();
Chain that stuff up and you get how we do most of our unit testing in jetty itself, spinning up the server itself, wiring up whatever handler or webapps we want and then assert behaviors, requests, responses, etc.
We have a number of embedded examples here that you can look at for different ways to wire up jetty inside code, and the jetty.xml format is just a thin layer of xml over java so you can map the startup of jetty easily through the code by reading the xml file with a java hat on. There is an embedded example in here for bootstrapping jetty based on that xml format as well if you want to keep the config there.
http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded
For a good page on embedding jetty, look here: http://www.eclipse.org/jetty/documentation/current/embedding-jetty.html
Most likely the jetty server is running on 8080 as default. If not you can go and check the server.xml file which should tell you what the port configuration is.
I'm not sure what you're asking here but if you had some servlet i.e Hello :
public final class Hello extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
writer.println("URL is " + request.getRequestURL() + " port is " request.getServerPort());
}
}
Additionally if this is not info what you're looking for please see this :
http://docs.oracle.com/javaee/1.4/api/javax/servlet/http/HttpServletRequest.html
http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.6/api/javax/servlet/http/HttpServletRequest.html