0

I have added a new action to the Document Library. My java class extends

ActionExecuterAbstractBase

. Inside code I make an HttpsURLConnection and read response like this :

URL url = new URL("https://...................................Get?username="+Name+"&password="+Password);
        HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();


        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : "
                    + conn.getResponseCode());
        }

        BufferedReader br = new BufferedReader(new InputStreamReader(
            (conn.getInputStream())));

Outside Alfresco the java script works perfectly but inside it throws the following error :

Web Script Status 405 - Method Not Allowed

The Web Script /alfresco/s/api/action/cosign/formprocessor has responded with a status of 405 - Method Not Allowed.

405 Description:    The method specified in the Request-Line is not allowed for the resource identified by the Request-URI.

Message:    08060002 Script url /api/action/cosign/formprocessor does not support the method GET

Exception:  org.springframework.extensions.webscripts.WebScriptException - 08060002 Script url /api/action/cosign/formprocessor does not support the method GET

org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:179)
org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:745)

Server: Community v5.0.0 (d r99759-b2) schema 8.022
Time:   6 Σεπ 2016 11:25:36 πμ

How can I resolve this ?

mr antoni
  • 595
  • 1
  • 6
  • 17
  • Send it a `POST` instead of a `GET` ? – Gagravarr Sep 06 '16 at 09:31
  • If I add this "conn.setRequestMethod("POST");" java throws org.json.JSONException: JSONObject["Data"] not found. – mr antoni Sep 06 '16 at 09:40
  • A post request normally includes some data, and it looks like the form processor is expecting some to know what form to give you. What happens if you take a look at one of the many similar actions in the Alfresco source tree, and see how they do it? – Gagravarr Sep 06 '16 at 12:42
  • I looked and the only example which extends 'ActionExecuterAbstractBase ' is this one [link](https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/COMMUNITYTAGS/V4.0b/root/modules/mediawiki-integration/source/java/org/alfresco/module/mediawikiintegration/action/MediaWikiActionExecuter.java) I used the same code but ones again I receive the same error – mr antoni Sep 07 '16 at 08:43
  • That code is for talking to media wiki, so won't be sending the data that the form processor expects. However, it does show how to post a body, which your code lacks – Gagravarr Sep 07 '16 at 10:51
  • If I make a post request I failed to receive data. The service is third party and I can't modified. I can use only get request to pull data. Is there any trick can I do ? – mr antoni Sep 07 '16 at 11:50

1 Answers1

0

Finally the problem came from SSL certificate. Alfresco in order to make https url connection should trust the ssl certificate. You can add an SSL in Alfresco/java folder with the following command:

keytool -import -alias test.com -file ../test.cer -keystore ../lib/security/cacerts
mr antoni
  • 595
  • 1
  • 6
  • 17