0

I'm hoping someone can help figure this out. I've got a problem trying to run some backend php code from java that extracts sql data and sends it back via gson. I've used posting from java to php and inserting it into mysql database as a model, but, I can't seem to get beyond the HTTP 400 response code that is returned. I've edited the following java console to remove identifying names, but, the context should remain the same.

security: JSS is not configured
network: Connecting https://secure.justhost.com/<server>/<folder>/<php program name>.php with proxy=DIRECT
network: Cache entry not found [url: http://secure.justhost.com:443/crossdomain.xml, version: null]
network: Connecting http://secure.justhost.com:443/crossdomain.xml with proxy=DIRECT
network: Connecting http://secure.justhost.com:443/ with proxy=DIRECT
java.io.IOException: Server returned HTTP response code: 400 for URL: http://secure.justhost.com:443/crossdomain.xml
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at com.sun.deploy.net.CrossDomainXML.check(Unknown Source)
    at com.sun.deploy.net.CrossDomainXML.check(Unknown Source)
    at sun.plugin2.applet.SecurityManagerHelper.checkConnectHelper(Unknown Source)
    at sun.plugin2.applet.AWTAppletSecurityManager.checkConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at java.net.HttpURLConnection.getResponseCode(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
    at newposting.GetCategories(newposting.java:864)
    at newposting.<init>(newposting.java:170)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter$1.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
basic: exception: java.lang.reflect.InvocationTargetException.
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.runOnEDTAndWait(Unknown Source)
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.instantiateApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
    at com.sun.deploy.uitoolkit.impl.awt.OldPluginAWTUtil.invokeAndWait(Unknown Source)
    ... 5 more
Caused by: java.lang.RuntimeException: java.security.AccessControlException: access denied ("java.net.SocketPermission" "secure.justhost.com:443" "connect,resolve")
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(Unknown Source)
    at java.net.HttpURLConnection.getResponseCode(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
    at newposting.GetCategories(newposting.java:864)
    at newposting.<init>(newposting.java:170)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter$1.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied ("java.net.SocketPermission" "secure.justhost.com:443" "connect,resolve")
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkConnect(Unknown Source)
    at sun.plugin2.applet.SecurityManagerHelper.checkConnectHelper(Unknown Source)
    at sun.plugin2.applet.AWTAppletSecurityManager.checkConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    ... 29 more
security: Reset deny session certificate store

The url for the php code has no spaces. It does use underlines ("_") to join words. The request that is show in the console does not pass any parameters to the url because the php code has all it needs to retrieve the data. The java code is simply calling the backend php code. Here's a look at what I've got for the java code.

private ArrayList<String> GetCategories ()
    {
    ArrayList<String> cats = new ArrayList<String> ();

    //  preparation
    String charset = "UTF-8";
    String szURL = new String ();
    if (!debugConfiguration)
        szURL = "https://secure.justhost.com/<server>/<folder>/<php program name>.php";
    else
        szURL = "http://localhost/<php program name>.php";
    //  HTTP Post request
    URL object = null;
    try 
        {
        object = new URL(szURL);
        }
    catch (MalformedURLException e) 
        {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }

    HttpsURLConnection con = null;
    try 
        {
        con = (HttpsURLConnection) object.openConnection();
        }
    catch (IOException e)
        {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }

    //add request header
    try 
        {
        con.setRequestMethod("POST");
        }
    catch (ProtocolException e) 
        {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }

    con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
    con.setRequestProperty(charset, "utf-8");
    con.setRequestProperty("User-Agent", USER_AGENT);
    con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
    // Send post request
    //con.setDoOutput(true);
    /*
    DataOutputStream wr = null;
    try 
        {
        wr = new DataOutputStream (con.getOutputStream());
        }
    catch (IOException e) 
        {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }
    try 
        {
        wr.close();
        }
    catch (IOException e) 
        {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }
    */
    try 
        {
        int responseCode = con.getResponseCode();
        }
    catch (IOException e) 
        {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }

    BufferedReader in = null;
    try 
        {
        in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        }
    catch (IOException e) 
        {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }

    String inputLine;
    StringBuffer response = new StringBuffer();

    try 
        {
        while ((inputLine = in.readLine()) != null)
            {
            response.append(inputLine);
            }
        }
    catch (IOException e) 
        {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }

    try 
        {
        in.close();
        }
    catch (IOException e) 
        {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }

    Gson gson = new Gson ();    
    jsonArticleCategories[] enums = gson.fromJson(response.toString(), jsonArticleCategories[].class);
    for (int i=0; i<enums.length; ++i)
        {
        jsonArticleCategories jac = enums[i];
        cats.add(jac.get_category());
        }

    return cats;
    }

Again, I've edited the code sample to remove some names, but the context is valid. There are not spaces in any of the names for the server, folder, or program name. Lastly, let me add that the java code is digitally signed with a code signing certificate and run through jnlp. The php code runs correctly if executed manually from a browser.

Thanks for any help.

Community
  • 1
  • 1
rrirower
  • 4,338
  • 4
  • 27
  • 45
  • The error says it can't find file http://secure.justhost.com:443/crossdomain.xml. Try creating a file on your server at that location called crossdomain.xml like shown here http://stackoverflow.com/questions/213251/can-someone-post-a-well-formed-crossdomain-xml-sample and retry. – Ashley Swatton Jan 01 '14 at 21:01
  • 1
    If you read the stack trace it tells you the issue; the security manager is preventing you from opening a socket. Is this an applet? – Brian Roach Jan 01 '14 at 21:02
  • @AshleySwatton That's not the real cause and is a result of the lower level socket operation not being allowed by the security manager. – Brian Roach Jan 01 '14 at 21:03
  • @BrianRoach Yes, this is applet code. – rrirower Jan 01 '14 at 21:14
  • @BrianRoach Thanks for the help on the stack trace. Your second pair of eyes has allowed me to narrow down the real cause of the problem. I've added the correct permissions to the jnlp file and I am narrowing in on the cause. – rrirower Jan 01 '14 at 21:39
  • Yeah - sorry - I literally haven't mucked with applets in years so I don't have a solution, but I saw that was the cause. – Brian Roach Jan 01 '14 at 21:40

0 Answers0