如何配置jetty以使用我的jersey servlet和HTTPS协议

时间:2012-05-19 15:18:47

标签: java ssl https jetty jersey

请帮帮我。 我开始http://wiki.eclipse.org/Jetty/Howto/Configure_SSL,我需要配置$Jetty_Home/etc/jetty.xml并指定我的密钥库

<Call name="addConnector">
  <Arg>
    <New class="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
      <Arg>
        <New class="org.eclipse.jetty.http.ssl.SslContextFactory">
          <Set name="keyStore"><SystemProperty name="jetty.home" default="." />/etc/keystore</Set>
          <Set name="keyStorePassword">OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4</Set>
          <Set name="keyManagerPassword">OBF:1u2u1wml1z7s1z7a1wnl1u2g</Set>
          <Set name="trustStore"><SystemProperty name="jetty.home" default="." />/etc/keystore</Set>
          <Set name="trustStorePassword">OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4</Set>
        </New>
      </Arg>
      <Set name="port">8443</Set>
      <Set name="maxIdleTime">30000</Set>
    </New>
  </Arg>
</Call>

但我不明白如何指定我的jersey servlet需要使用https 可能需要在web.xml中指定吗?

这是我的源代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataParam;
@Path("/")
public class Uploader {

        //post method
    @POST
        //full path is: https://localhost:8443/loguploadservice/uploader
    @Path("/uploader")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces("text/plain")
    public Response upload(
        @FormDataParam("file") InputStream uploadedInputStream,
        @FormDataParam("file") FormDataContentDisposition fileDetail) {

        String uploadedFileLocation = "d://uploaded/"
            + fileDetail.getFileName();

        // save it
        writeToFile(uploadedInputStream, uploadedFileLocation);

        String output = "File uploaded to : " + uploadedFileLocation;

        return Response
                .status(200)
                .entity(output).build();

    }
        /**
        *write data to file
        */
    private void writeToFile(InputStream uploadedInputStream,
        String uploadedFileLocation) {

         try {
            OutputStream out = new FileOutputStream(new File(
                    uploadedFileLocation));
            int read = 0;
            byte[] bytes = new byte[1024];

            while ((read = uploadedInputStream.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }

            out.flush(); //flush data
            out.close(); //close output stream
            uploadedInputStream.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

        }
  }

0 个答案:

没有答案