2016-02-28 11 views
2

Я новичок в джерси. Я сделал сайт, который является главным образом статичным, за исключением того, что мы используем функцию javamail api и recaptcha. Мой проект отлично работает в eclipse. Но когда я загрузил его в производство, я столкнулся с этой проблемой. Говорят, что не удалось инициализировать класс com.sun.proxy.$Proxy13. Я пробовал различные решения, но дело в том, что мое приложение работает как ожидается в тестовой среде (eclipse), но дает исключение в производственной среде. Вот трассировки стека:

Stack trace error from production

web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!-- This web.xml file is not required when using Servlet 3.0 container, 
    see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e194 --> 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 


    <servlet> 
     <servlet-name>Jersey Web Application</servlet-name> 
     <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> 
     <init-param> 
      <param-name>com.sun.jersey.config.property.packages</param-name> 
      <param-value>co.in.****</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Jersey Web Application</servlet-name> 
     <url-pattern>/webresources/*</url-pattern> 
    </servlet-mapping> 
</web-app> 

Форма

\t <form class="form" action="webresources/check/validate" name="contactus" method="get"> 
 
\t \t \t \t \t \t \t \t \t \t <input class="name" type="text" placeholder="Name" name = "name" id="name" required="required"> 
 
\t \t \t \t \t \t \t \t \t \t <input class="email" type="email" placeholder="Email" name="email" id="email" required="required"> 
 
\t \t \t \t \t \t \t \t \t \t <input class="phone" type="text" placeholder="Phone No:" name="phone" id="phone"> 
 
\t \t \t \t \t \t \t \t \t \t <textarea class="message" name="message" id="message" cols="30" rows="10" placeholder="Message" required="required"></textarea> 
 
\t \t \t \t \t \t \t \t \t \t <div class="g-recaptcha" data-sitekey="*************"></div> 
 
\t \t \t \t \t \t \t \t \t \t <input class="submit-btn" type="submit" value="SUBMIT"> 
 
\t \t \t \t \t \t \t \t \t </form>

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>co.in.******</groupId> 
    <artifactId>meshtechnologies</artifactId> 
    <packaging>war</packaging> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>**** Jersey Webapp</name> 
    <build> 
     <finalName>*****</finalName> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <inherited>true</inherited> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
      </plugin> 
      <!-- Run the application using "mvn embedded-glassfish:run" --> 
      <plugin> 
       <groupId>org.glassfish</groupId> 
       <artifactId>maven-embedded-glassfish-plugin</artifactId> 
       <version>${glassfish.version}</version> 
       <configuration> 
        <goalPrefix>embedded-glassfish</goalPrefix> 
        <app>D:/Projects/target/${project.build.finalName}.war</app> 
        <autoDelete>true</autoDelete> 
        <port>8080</port> 
       </configuration> 
       <dependencies> 
        <dependency> 
         <groupId>com.sun.jersey</groupId> 
         <artifactId>jersey-servlet</artifactId> 
         <version>${project.version}</version> 
        </dependency> 
        <dependency> 
         <groupId>javax.servlet</groupId> 
         <artifactId>javax.servlet-api</artifactId> 
         <version>3.0.1</version> 
        </dependency> 
       </dependencies> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
      <groupId>com.sun.jersey</groupId> 
      <artifactId>jersey-servlet</artifactId> 
      <version>${jersey.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>com.sun.jersey</groupId> 
      <artifactId>jersey-json</artifactId> 
      <version>${jersey.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.8.2</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.sun.jersey</groupId> 
      <artifactId>jersey-client</artifactId> 
      <version>${jersey.version}</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.extras</groupId> 
      <artifactId>glassfish-embedded-web</artifactId> 
      <version>${glassfish.version}</version> 
      <scope>test</scope> 
     </dependency> 

     <dependency> 
      <groupId>javax.mail</groupId> 
      <artifactId>javax.mail-api</artifactId> 
      <version>1.5.5</version> 
     </dependency> 

     <dependency> 
      <groupId>org.apache.commons</groupId> 
      <artifactId>commons-collections4</artifactId> 
      <version>4.1</version> 
     </dependency> 


     <dependency> 
      <groupId>com.octo.captcha</groupId> 
      <artifactId>jcaptcha-all</artifactId> 
      <version>1.0-RC6</version> 
     </dependency> 

     <dependency> 
      <groupId>commons-logging</groupId> 
      <artifactId>commons-logging</artifactId> 
      <version>1.2</version> 
     </dependency> 



     <dependency> 
      <groupId>org.glassfish</groupId> 
      <artifactId>javax.json</artifactId> 
      <version>1.0.4</version> 
     </dependency> 

     <dependency> 
      <groupId>javax.ws.rs</groupId> 
      <artifactId>javax.ws.rs-api</artifactId> 
      <version>2.0.1</version> 
      <scope>provided</scope> 
     </dependency> 

     <dependency> 
      <groupId>org.glassfish.jersey.core</groupId> 
      <artifactId>jersey-client</artifactId> 
      <version>2.22.2</version> 
     </dependency> 

     <dependency> 
      <groupId>org.glassfish.jersey.connectors</groupId> 
      <artifactId>jersey-apache-connector</artifactId> 
      <version>2.22.2</version> 
     </dependency> 

     <dependency> 
      <groupId>org.glassfish.jersey.containers</groupId> 
      <artifactId>jersey-container-jdk-http</artifactId> 
      <version>2.22.2</version> 
     </dependency> 

     <dependency> 
      <groupId>javax.mail</groupId> 
      <artifactId>mail</artifactId> 
      <version>1.4.7</version> 
     </dependency> 


    </dependencies> 
    <properties> 
     <jersey.version>1.19</jersey.version> 
     <glassfish.version>3.1.1</glassfish.version> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
</project> 

Класс

package co.in.******; 

import java.io.IOException; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.net.URL; 
import java.util.Date; 
import java.util.Properties; 

import javax.ws.rs.GET; 
import javax.ws.rs.POST; 
import javax.ws.rs.Path; 
import javax.ws.rs.Produces; 
import javax.ws.rs.QueryParam; 
import javax.ws.rs.core.MediaType; 
import javax.ws.rs.core.Response; 
import javax.mail.*; 
import javax.mail.internet.*; 

/** Example resource class hosted at the URI path "/myresource" 
*/ 

@Path("/check") 
public class MyResource { 

    @GET 
    @Produces(MediaType.TEXT_HTML) 
    @Path("/validate") 
    public Response getData(@QueryParam("name") String name,@QueryParam("email") String email, 
      @QueryParam("message") String msg, @QueryParam("phone") String mob 
      ,@QueryParam("g-recaptcha-response") String gRecaptchaResponse) throws IOException, URISyntaxException 
    { 

     // get reCAPTCHA request param 

     System.out.println(gRecaptchaResponse); 
     boolean verify = VerifyRecaptcha.verify(gRecaptchaResponse); 
     if(verify) 
     { 
      System.out.println("VALID"); 

      try 
      { 
       String smtpServer="smtp.gmail.com"; 
       String to="**********"; 
       String from= "***************"; 
       String subject="Contact Request "+email; 
       String body= name+" : "+mob+" : "+msg; 
       send(smtpServer, to, from, subject, body); 
      } 
      catch (Exception ex) 
      { 
       System.out.println("Usage: java com.lotontech.mail.SimpleSender" 
       +" smtpServer toAddress fromAddress subjectText bodyText"); 
      } 

      URI u = new URI("*************"); 

      return Response.temporaryRedirect(u).build(); 

     } 
     else 
     { 

      URI u = new URI("*******"); 
      return Response.temporaryRedirect(u).build(); 


     } 


    } 

    protected static void send(String smtpServer, String to, String from 
       , String subject, String body) 
       { 
       try 
       { 
        Properties props = System.getProperties(); 
        // -- Attaching to default Session, or we could start a new one -- 
       props.put("mail.smtp.host", smtpServer); 
        Session session = Session.getDefaultInstance(props, null); 
        // -- Create a new message -- 
        Message msg = new MimeMessage(session); 
        // -- Set the FROM and TO fields -- 
        msg.setFrom(new InternetAddress(from)); 
        msg.setRecipients(Message.RecipientType.TO, 
        InternetAddress.parse(to, false)); 
        // -- We could include CC recipients too -- 
        // if (cc != null) 
        // msg.setRecipients(Message.RecipientType.CC 
        // ,InternetAddress.parse(cc, false)); 
        // -- Set the subject and body text -- 
        msg.setSubject(subject); 
        msg.setText(body); 
        // -- Set some other header information -- 
        msg.setHeader("X-Mailer", "LOTONtechEmail"); 
        msg.setSentDate(new Date()); 
        // -- Send the message -- 
       // Transport.send(msg); 

        Transport transport = session.getTransport("smtps"); 
        transport.connect(smtpServer, 465, "******","*******"); 

        transport.sendMessage(msg, msg.getAllRecipients()); 
        transport.close(); 
        System.out.println("Message sent OK."); 
       } 
       catch (Exception ex) 
       { 
        ex.printStackTrace(); 
       } 
       } 

} 

Пожалуйста, помогите мне с этим. Спасибо

+0

Он даже не загружает ваш код. Это заставляет меня думать, что это связано с настройкой сервера. Вы пробовали использовать простой «Hello world!». веб-приложение? –

+0

Luks как проблема, связанная с [несовместимым банком] (http://stackoverflow.com/a/12226362/452708) – Abhijeet

+0

@MadsNielsen - Да, я проверил с миром приветствия по умолчанию, предоставленным jersey, он работает нормально. – Nikhil

ответ

0

Проблема была в самом проекте, когда я сделал чистую сборку для maven, тогда я узнал, что проект не работает, и я не получаю новую копию во время написания этого вопроса. Но затем я сделал новый проект и только что скопировал мои предыдущие данные, и теперь он работает нормально. Я думаю, что конфликт в добавленных зависимостях.