09-22-2010 08:21 AM
09-22-2010 12:43 PM
How can I send the file's content from the applet to the backing bean?
09-23-2010 04:28 AM
Hey,
I'm trying to change a file's content through an applet (so i can do it on the client's side). My idea is to have a jsp where you press a button and the backing bean sends the file's noderef to an applet and it changes the file and sends back the new file's content to the backing bean.
1- Is this possible?
2- How can I access the file's content in the applet (send it's inputStream has a parameter?)
3- How can I send the file's content from the applet to the backing bean?
I believe I solve the second problem with information from this post http://forums.alfresco.com/en/viewtopic.php?f=48&t=18828&hilit=applet, but how can I solve the third problem?
Best reguards,
Pedro
09-24-2010 07:19 AM
09-27-2010 07:10 AM
package aTest;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextArea;
import java.io.ObjectOutputStream;
import java.net.URL;
import java.net.URLConnection;
public class appletTest extends Applet{
private static final long serialVersionUID = 1L;
private String webServerStr = null;
private String hostName = "localhost";
private int port = 8080;
private String servletPath = "/alfresco/test";
private TextArea statusTextArea;
private Panel statusBarPanel;
private Label statusLabel;
public void init() {
this.setLayout(new BorderLayout());
statusBarPanel = new Panel();
statusTextArea = new TextArea(3, 50);
statusBarPanel.setLayout(new FlowLayout());
this.add(BorderLayout.SOUTH, statusBarPanel);
statusLabel = new Label("Status Messages");
statusBarPanel.add(statusLabel);
statusTextArea = new TextArea(3, 50);
statusBarPanel.add(statusTextArea);
// get the host name and port of the applet's web server
URL hostURL = getCodeBase();
hostName = hostURL.getHost();
port = hostURL.getPort();
if (port == -1){
port = 80;
}
log("Web Server host name: " + hostName);
webServerStr = "http://" + hostName + ":" + port + servletPath;
log("Web String full = " + webServerStr);
post();
}
protected void log(String msg)
{
statusTextArea.append(msg + "\n");
}
public void post(){
// String webServerStr = "http://10.50.104.67:8080/test";
URL studentDBservlet;
try {
studentDBservlet = new URL( webServerStr );
URLConnection servletConnection = studentDBservlet.openConnection();
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
// Don't use a cached version of URL connection.
servletConnection.setUseCaches (false);
servletConnection.setDefaultUseCaches (false);
// Specify the content type that we will send binary data
servletConnection.setRequestProperty ("Content-Type", "application/octet-stream");
// send the student object to the servlet using serialization
ObjectOutputStream outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
String output = "Communication Achieved.";
// serialize the object
outputToServlet.writeObject(output);
outputToServlet.flush();
outputToServlet.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
package aTest;
import java.io.IOException;
import java.io.ObjectInputStream;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.web.app.servlet.BaseServlet;
public class servTest extends BaseServlet{
private static final long serialVersionUID = 1L;
public void init(ServletConfig config) throws ServletException{
System.out.println("customServletInitiated");
super.init(config);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ObjectInputStream inputFromApplet = null;
String input = null;
try {
inputFromApplet = new ObjectInputStream(request.getInputStream());
input = (String) inputFromApplet.readObject();
inputFromApplet.close();
System.out.println(input);
} catch (Exception e) {
e.printStackTrace();
}
}
}
<servlet>
<servlet-name>testServlet</servlet-name>
<servlet-class>aTest.servTest</servlet-class>
</servlet>
.
.
<servlet-mapping>
<servlet-name>testServlet</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
09-27-2010 12:45 PM
Application.getCurrentUser(FacesContext.getCurrentInstance()).getTicket()
NodeRef nodeRef = new NodeRef(Repository.getStoreRef(), id);
Node node = new Node(nodeRef);
and with content writer you can set new content to the node…09-28-2010 08:21 AM
String ticket = Application.getCurrentUser(FacesContext.getCurrentInstance()).getTicket();
and sending "ticket" back to the applet so i could then do POSTs.09-28-2010 08:31 AM
09-28-2010 08:41 AM
Application.getCurrentUser(request.getSession()).getTicket();
thanks savic 09-28-2010 09:20 AM
public void sendInfoToServer(){
URL servlet;
try {
String output = "Info from applet.";
// gets ticket
String ticket = getTicket();
servlet = new URL( webServerStr + "?" + "alf_ticket" + "=" + ticket);
URLConnection servletConnection = servlet.openConnection();
log("Connected at: " + servletConnection.getURL());
// inform the connection that we will send output and accept input
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
// Don't use a cached version of URL connection.
servletConnection.setUseCaches (false);
servletConnection.setRequestProperty ("Content=length", String.valueOf(output.getBytes().length));
ObjectOutputStream outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
// "sends" output to servlet
outputToServlet.writeObject(output);
outputToServlet.flush();
outputToServlet.close();
log("Sent information to server");
} catch (Exception e) {
e.printStackTrace();
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.