I am trying to make a HTTP POST request to a server with https. When I was testing making the call I did it on a standalone java program (not deployed on a server) and initaially got the error:
unable to find valid certification path to requested target
however I fixed this with creating a cacert using a tool online called InstallCert and pointing java there with:
System.setProperty("javax.net.ssl.trustStore", "C:\\Users\\...\\jssecacerts");
However, when I implement the same fix in the code that I deploy on Apache Tomcat it doesnt work and I get the same error as before. So my question is do .war files deployed on Apache Tomcat use a different trust store than the java one? Or do they not use the system properties? How can I get Apache Tomcat to use the cacert?
Thanks
EDIT:
So I've tried to do some more research and get it fixed with no success. I tried following http://andyarismendi.blogspot.co.uk/2012/01/changing-tomcats-ca-trust-keystore-file.html to try and get it fixed.
Changing the server.xml file made no difference. However, changing the Tomcat Java Options with
-Djavax.next.ssl.trustStore="myFile"
Altered the response that I got, with this I get:
java.io.IOException: Server returned response code 500 for URL websitesURL
I also saw in some places that copying the jssecacerts file into my jre\lib\security directory could fix this. However this just cause the response code 500 error...
This is the code that is being used to make the POST Request:
//System.setProperty("javax.net.ssl.trustStore", "C:\\file\\path\\jssecacerts");
try
{
OAuthClient client = new OAuthClient(new URLConnectionClient());
//grant_type=password
OAuthClientRequest.TokenRequestBuilder trb = new OAuthClientRequest.TokenRequestBuilder(TOKEN_URL)
.setGrantType(GrantType.PASSWORD)
.setClientId(CLIENT_ID)
.setUsername(username)
.setPassword(password);
OAuthClientRequest ocr = trb.buildBodyMessage();
ocr.setHeader("Authorization", base64EncodedBasicAuthentication(CLIENT_ID, CLIENT_SECRET));
String responseBody = client.accessToken(ocr, OAuthJSONAccessTokenResponse.class).getBody();
return responseBody;
}
catch(Exception e)
{
e.printStackTrace();
return e.getMessage();
}
Related
I have a Java program that makes reports from Google AdWords, the authentications are working correctly since I have no issues issuing my reports with the Java API, but now when I run my Java API on the localhost with mvn appengine:devserver, it gives me this exception:
Client ID must be set as api.adwords.clientId in ads.properties.
If you do not have a client ID or secret, please create one in the API console: https://console.developers.google.com/project caused by: [clientId]
Only thing I change from the Java app to the GAE app is the doGet method, I comment it out and change my run() that is called by the doGet to main(String args[]).
Fixed, here's how:
This issue is due to the path of properties file.
First when deploying app, I was using a server so it doesn't read the properties file from the same directory as when it's run (ran?) on eclipse with the play button or with javac your_java_app.java
I moved my ads.properties from resources to src/main/webapp/WEB-INF and changed the OAuth2Credential from
..fromFile().. to
..fromFile("WEB-INF/ads.properties")..
I am developing rest service using ReastEasy 3.0.10 API with tomcat 8 and jAVA 8. My code is working fine on window machine but when I deployed WAR file on Linux machine, It gives error org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoSuchMethodError: javax.ws.rs.core.Response.close()V
The no of jar files are same as it is on local. I am having two jar files javax.ws.rs-api-2.0.1 and jaxrs-api-3.0.10.Final in my lib folder. Both are having Response class and close method. But Still it is giving error on Linux server. Any suggestion?
The client code is
try {
Client client = ClientBuilder.newClient();
String targetUrl = "http://xxx.xxx.xxx.xxx:xxxx/appname/rest/resturl"
WebTarget target = client.target(targetUrl);
response = target.request(MediaType.APPLICATION_JSON).header("AUTHENTICATED", true)
.post(Entity.entity(RestUtil.convertObjectToJSONString(object), MediaType.APPLICATION_JSON));
responseString = response.readEntity(String.class);
}catch(Exception e){
e.printStackTrace();
} finally {
response.close();
}
Also I have noticed one thing, It calls the rest service and print data which rest is returning but After that it prints Internal Server Error 500 in log before printing above mentioned error.
Ok. After investing one day finally I found that this error comes when some other jar having same class with same package structure. I used a tool JARMINATOR to scan all of my jar files. Now I have fixed this issue but still it is a question why window machine was not loading that jar but linux machine was loading into Linux machine.
I have resolved it by excluding the below.
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
Using asadmin --port 8080 multimode, I created and started a domain on the localhost; so far, everything is fine. Then I try list-commands, and I get: HTTP Status 404: The requested resource is not available. If I try list-commands --localonly it works fine. I completely took down my firewall to see if that was the problem, but that didn't fix it.
This wouldn't be such a big deal, since I can look up the commands elsewhere, but I'm getting the same error when I try to deploy a WAR file, and I'm guessing that both problems have the same cause (after all, deploy isn't listed under the local commands).
I'm using GlassFish 4.1
I create web service
#WebService(serviceName = "DynamipsService2")
#Stateless()
public class DynamipsService2 {
#WebMethod(operationName = "StartSession")
public static String StartSession(#WebParam(name = "key") String key) {
try {
return "100-Session started";
} catch (Exception ex) {
return null;
}
}
}
I want to test but on the page
http://localhost:8080/DynamipsService2/DynamipsService2?Tester crash bug
Error generating artifacts for the
following WSDL
http://localhost:8080/DynamipsService2/DynamipsService2?WSDL
Possible causes can be invoking https
when the application is not configured
for security
I created other Web services in the same assembly and it works.
I just experienced this problem as well. The solution for me was to use my hostname rather than localhost in the URL for the Tester.
So in my case, the following, which is what NetBeans/Glassfish did by default when I clicked Test Web Service in the NetBeans UI, did not work:
http://localhost:8080/Calculator/Calculator?Tester
However, when I paste the following into a browser, it does work:
http://david-pc:8080/Calculator/Calculator?Tester
I couldn't figure out how to change the hostname that NetBeans uses for the built-in Test dialog (nor could I cut+paste the URL from the error dialog). So I had to visually copy the URL from the error message into a browser, replacing the hostname along the way.
I had the same problem and the reason apeared in the Server's log. I'm useing Glassfish 3.1 with netBeans 7. And the error I got in the Glassfish output was:
INFO: [ERROR] com.sun.tools.javac.Main is not available in the classpath, requires Suns JDK version 5.0 or latter.
I googled a bit and it appeared to be because the glassfish server was working with the openjdk that came with ubuntu. If your problem is the same the solution I found was to remove the openjdk jre, like this:
sudo apt-get remove openjdk-6-jre
sudo apt-get autoremove
Hope this is useful.
PS: I assigned /usr/lib/jvm/java-6-sun/bin/java in the java tab at the servers configuration wizard in netBeans but don't know if that was part of the solution (I'm afraid to change it back :p)
I had the same problem with Glassfish
but it was more compilcated because of the NAT
I have GF in NAT - do MYDOMAIN and port is redirected to internal machine
the problem in GF is that it tries to connect to itself by the domain name which again redirects to inside network
(the ?wsdl works properly)
I have made temp solution adding to /etc/hosts (127.0.0.1 domainname)
be aware that it's only a temp solution
try to check if you have "localhost" in your hosts file (in windows c:/windows/system32/drivers/etc/hosts )
and ping localhost
I will add GF log - maybe someone in future will search it by google :) :)
moreover I looked GF logs there was something like ->
Connection timed out
Failed to read the WSDL document: http://MYDOMAIN:8080/MYSERVICE?WSDL, because 1) could not find the document; /2) the document could not be read; 3) the root element of the document is not <wsdl:definitions>.
failed.noservice=Could not find wsdl:service in the provided WSDL(s):
At least one WSDL with at least one service definition needs to be provided.
Failed to parse the WSDL.
Which web server do you use? If you use glassfish you can open server admin page and select Configurations===>server-config===>Security
and make Security Manager enabled
Check your domains/{YOUR_DOMAIN}/config/domain.xml
If you setup Glassfish using Eclipse, all will be done for you automatically.
Now I am surprised if I start the domain from the command line, it gave me that error, but starting Glassfish 4 from Eclipse, it is not showing any problem.
One cause could be that you don't have correctly configured the environment variable JAVA_HOME (with the correct path) and the JAVA_HOME/bin directory added to global PATH environment variable as well. For some processes the glassfish look for the classpath of the JDK installed.
Hope this help.
I had the exact same problem and it is because you have a static method, I realised after debugging for some while. Just remove static from the method and it should work.
#WebMethod(operationName = "StartSession")
public String StartSession(#WebParam(name = "key") String key) {
try {
return "100-Session started";
} catch (Exception ex) {
return null;
}
}
I am having trouble setting up the Php-Java Bridge setup properly.
I will explain what I have done.
My site is in pure php
For our payment transaction process we need to set up a php-java bridge
I followed this link to setup the bridge PHP-JAVA BRIDGE INSTALATION.
Here I learned that I need to have a private jvm to install the bridge.
So 1st i installed apache-tomcat-6.0.14 in Private JVM using my c-panel. After instalation it asked me to Map a domain to private JVM. So I mapped my domain example.com (which is the only option available) to it.
Then it asked to enable a traffic redirection from Apache web server to my Java application server (there was a check box and i clicked it)
Finally it asked me to deploy the WAR File (JavaBridge.WAR was my file) and everthing seems fine
Now when i go to http://example.com/JavaBridge/ I could see the javabridge examples and it works fine.
SO FAR SO GOOD
Now my problem starts here when I try to access a java class file from php. A sample test.php is what I create and put the following code into it.
<?php
require_once("http://example.com:portnumber/JavaBridge/java/Java.inc");
$System = java("java.lang.System");
echo $System->getProperties(); //This Part echo's correctly and shows the data so it means i can access Java.inc Correctly
$path_e24class = getcwd(). '/e24PaymentPipe.class'; //This part fails both test.php and java class file e24PaymentPipe.class are in the same directory in publich_html folder
java_require($path_e24class);
$pipe = new Java("e24PaymentPipe");
$pipe->setAction("1");
?>
My site contents reside in the public_html folder and the WAR file are deployed in private jvm.
These are the error message am getting.
1) Warning: java_require() not supported anymore. Please use tomcat or jee hot deployment instead
Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: CreateInstance failed: new e24PaymentPipe. Cause: java.lang.ClassNotFoundException: e24PaymentPipe VM: 1.6.0_22#http://java.sun.com/" at: #-10
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358) #-9
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204) #-8
java.lang.Class.forName0(Native Method) #-7
java.lang.Class.forName(Class.java:247) #-6
php.java.bridge.Util.classForName(Util.java:1518) #-5
php.java.bridge.JavaBridge.CreateObject(JavaBridge.java:445) #-4
php.java.bridge.Request.handleRequest(Request.java:458) #-3
php.java.bridge.Request.handleRequests(Request.java:500) #-2
php.java.bridge.http.ContextRunner.run(ContextRunner.java:145) #-1
php.java.bridge.ThreadPool$Delegate.run(ThreadPool.java:60) #0
http://example.com:portnumber/JavaBridge/java/Java.inc(232): java_ThrowExceptionProxyFactory->getProxy(3, 'java.util.Prope...', 'T', false) #1
Finally I don't know much about the java. So am stuck here not knowing what to do.
Here is a great step by step tutorial you can follow, which shows everything required! It is a little old (2007) but helped me a while ago.
There is also another option. You can install Apache Tomcat and deploy your war there. You can have even multiple tomcat instances simultaneously with your httpd running at the same time on the same machine, as long as you respect the port settings. You can even front them with Apache httpd.
you can try this:
package your code to jar, and copy it to java.ext.dirs which you can found in JavaBridge.log
copy the related class libraries to java.ext.dirs
restart the service of JavaBridge
good luck!
<?php require_once("JavaBridge/java/Java.inc");
try {
$hd = new java("hdfs.HDFS");
$hd->get("hdfs://master:9000/user/hadoop/test-in/logo_cn.png", "/home/hadoop/1.png");
} catch (JavaException $ex) { echo "An exception occured: "; echo $ex; echo "<br>\n";}
?>
You can use this php implementation on github that works with php 5.3.
See credits on the git readme for more information.
You can try this; put the JavaBridge.jar in tomcat's lib folder e.g. apache-tomcat-7.0.12/lib.
Restart tomcat server and then,
$pipe = new java("com.aciworldwide.commerce.gateway.plugins.e24PaymentPipe");
$pipe->setAction("1");
This way I created the php version of the object.
Why don't you put the e24PaymentPipe class in your Java application's classpath and skip the two lines below:
// $path_e24class = getcwd(). '/e24PaymentPipe.class';
// java_require($path_e24class);
$pipe = new java("fully.qualified.classpath.e24PaymentPipe");
You are mixing PHP side and Java side operations. in theory the java_require (which is deprecated) was designed to work on the Java side. You are specifying a PHP side path.
You can save yourself a lot of grief by using a pure PHP implementation of the e24PaymentPipe library.
Disclaimer
The link is to my github repo of the library, but I did not write it. See the readme in for original credits.