2015-05-15 45 views
0

這個Spring JSON端點在Jboss/Tomcat中有什麼用處?我試圖將其添加到現有的應用程序,直到我開始重構代碼,現在錯誤並沒有指向任何對我來說合乎邏輯的東西。這個Spring JSON端點在Jboss/Tomcat中打破了什麼?

這是我的代碼控制器和助手類,保持乾淨。 Controller.Java

import java.io.IOException; 
import java.util.Properties; 

import javax.annotation.Nonnull; 

import org.apache.commons.configuration.ConfigurationException; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.ResponseBody; 

@Controller 
public class PropertiesDisplayController { 

@Nonnull 
private final PropertiesDisplayHelper propertiesHelper; 

/** 
* @param propertiesHelper 
*/ 
@Nonnull 
@Autowired 
public PropertiesDisplayController(@Nonnull final PropertiesDisplayHelper propertiesHelper) { 
    super(); 
    this.propertiesHelper = propertiesHelper; 
} 


@Nonnull 
@RequestMapping("/localproperties") 
public @ResponseBody Properties localProperties() throws ConfigurationException, IOException { 
    return propertiesHelper.getLocalProperties(); 
} 

@Nonnull 
@RequestMapping("/properties") 
public @ResponseBody Properties applicationProperties() throws IOException, 
     ConfigurationException { 
    return propertiesHelper.getApplicationProperties(); 

} 

} 

這將是Helper.java

import java.io.FileInputStream; 
import java.io.IOException; 
import java.util.Iterator; 
import java.util.Map; 
import java.util.Properties; 
import java.util.TreeMap; 

import javax.annotation.Nonnull; 

import org.apache.commons.configuration.Configuration; 
import org.apache.commons.configuration.ConfigurationException; 
import org.apache.commons.io.IOUtils; 
import org.apache.commons.lang.StringEscapeUtils; 
import org.apache.commons.lang.StringUtils; 

public class PropertiesDisplayHelper { 

/** Static location of properties in for SSO */ 
private static String LOCAL_PROPERTIES_LOCATION = 
    "local.properties"; 

/** Static strings for masking the passwords and blank values */ 
private static String NOVALUE = "**NO VALUE**"; 
/** Static strings for masking the passwords and blank values */ 
private static String MASKED = "**MASKED**"; 


@Nonnull 
public Properties getApplicationProperties() throws ConfigurationException { 

    final Properties properties = new Properties(); 
    final Configuration configuration = AppConfiguration.Factory.getConfiguration(); 

    // create a map of properties 
    final Iterator<?> propertyKeys = configuration.getKeys(); 
    final Map<String, String> sortedProperties = new TreeMap<String, String>(); 

    // loops the configurations and builds the properties 
    while (propertyKeys.hasNext()) { 
     final String key = propertyKeys.next().toString(); 
     final String value = configuration.getProperty(key).toString(); 
     sortedProperties.put(key, value); 
    } 
    properties.putAll(sortedProperties); 
    // output of the result 
    formatsPropertiesData(properties); 
    return properties; 
} 


@Nonnull 
public Properties getLocalProperties() throws ConfigurationException, IOException { 
    FileInputStream fis = null; 
    final Properties properties = new Properties(); 
    // imports file local.properties from specified location 
    // desinated when the update to openAM12 
    try { 
     fis = new FileInputStream(LOCAL_PROPERTIES_LOCATION); 
     properties.load(fis); 
    } finally { 
     // closes file input stream 
     IOUtils.closeQuietly(fis); 
    } 
    formatsPropertiesData(properties); 
    return properties; 
} 

void formatsPropertiesData(@Nonnull final Properties properties) { 
    for (final String key : properties.stringPropertyNames()) { 
     String value = properties.getProperty(key); 

     if (StringUtils.isEmpty(value)) { 
      value = NOVALUE; 
     } else if (key.endsWith("ssword")) { 
      value = MASKED; 
     } else { 
      value = StringEscapeUtils.escapeHtml(value); 
     } 
     // places data to k,v paired properties object 
     properties.put(key, value); 
     } 
    } 
} 

它們設置的屬性的JSON顯示在應用程序並從用於記錄一個文件。但是現在這個沒有侵入性的代碼似乎破壞了我的整個應用程序構建。

下面是從Jboss的

誤差

20:33:41559 ERROR [org.jboss.as.server](DeploymentScanner線程 - 1)JBAS015870:部署部署 「openam.war」 的用回滾以下失敗消息: {「JBAS014671:Failed services」=> {「jboss.deployment.unit。\」APPLICATION.war \「。STRUCTURE」=>「org.jboss.msc.service.StartException in service jboss.deployment .UNIT。\「APPLICATION.war \」。結構:JBAS018733:無法處理部署結構部署\「APPLICATION.war \」 導致:org.jboss.as.server.deployment.DeploymentUnitProcessingException:JBAS018740:無法安裝部署內容 導致:java.io.FileNotFoundException:APPLICATION.war(Ac塞斯被拒絕)「}}

,並從Tomcat

http://pastebin.com/PXdcpqvc

的錯誤,我在這裏丟失,覺得有什麼我只是不明白。

+0

似乎更多的是配置問題,而不是編碼問題。你能發佈一些你的相關配置文件嗎? – EricF

+0

Spring配置像XML文件或服務器配置像Jboss/Tomcat? – whatkai

回答

0

一個簡單的解決方案就在眼前。缺少的組件是幫助器類上的@Component註釋。

相關問題