使用此配置:
server {
listen 8080;
location / {
if ($http_cookie ~* "mycookie") {
proxy_set_header X-Request $request;
proxy_pass http://localhost:8081;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我重新加载nginx服务时出现此错误:
Reloading nginx configuration: nginx: [emerg] "proxy_set_header" directive is not allowed here in /etc/nginx/conf.d/check_cookie.conf:5
nginx: configuration file /etc/nginx/nginx.conf test failed
Run Code Online (Sandbox Code Playgroud)
这个配置工作正常,但它没有做我想要的:
server {
listen 8080;
location / {
proxy_set_header X-Request $request;
if ($http_cookie ~* "mycookie") {
proxy_pass http://localhost:8081;
}
}
}
Run Code Online (Sandbox Code Playgroud)
为什么我不能将proxy_set_header指令放在if子句中?
我必须写一个包含很多东西的bash脚本.我想打印与init脚本一样好的消息.例如:
Doing A... [OK]
Doing B... [ERROR]
....
Run Code Online (Sandbox Code Playgroud)
你知道怎么做这个吗?
提前致谢
我正在尝试生成搜索资源的链接.所以,我想创建一个提供我的搜索链接的资源:
POST /resourcesearch
{param1: "value1",param2:"value2"}
Run Code Online (Sandbox Code Playgroud)
答复应该是:
{"links":[
{
"rel":"self",
"href":"http://localhost:8080/resourcesearch"
},
{
"rel":"resources",
"href":"http://localhost:8080/resources?param1=value1¶m2=value2"
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
@Controller
@RequestMapping("/resourcesearch")
public class ResourceSearchController{
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<ResourceSupport> createResourceSearch(@RequestBody ResourceDTO dto){
ResourceSupport resource = new ResourceSupport();
//... do something here to build query string based on "dto"
resource.add(linkTo(ResourceController.class).withRel("resources"));
return new ResponseEntity<ResourceSupport>(resource, HttpStatus.CREATED);
}
}
===========================================
@Controller
@RequestMapping("/resources")
public class ResourceController{
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<CollectionDTO> listResources(@RequestParam("param1") String param1, @RequestParam("param2") String param2){
...
}
}
Run Code Online (Sandbox Code Playgroud)
问题是我无法弄清楚如何将查询字符串参数添加到行中的url:
resource.add(linkTo(ResourceController.class).withRel("resources"));
Run Code Online (Sandbox Code Playgroud)
因为该行的结果是:
{
"links" : [ …Run Code Online (Sandbox Code Playgroud) 我有一段代码非常类似于这个http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#JavaMailFetching
我的区别在于我需要将"TO"地址作为字符串.我在API中找不到如何将"TO"收件人作为每个邮件的字符串.
任何人都可以指导我如何做到这一点?至少有人已经做过的链接.
我正在使用Spring 3来管理数据库事务.每当引发异常时,我都会捕获异常并返回相应的消息.但是当Spring提交事务时,异常会再次引发并包含在org.springframework.dao.DataIntegrityValidationException.我该如何处理该异常?我应该使用拦截器还是其他东西?有没有人以前有这个问题?
提前致谢
我在同一个数组上迭代两次有问题:
<? $indice=0 ?>
<?php foreach ($comisiones as $comision1):?>
<tr>
<td><?php echo ++$indice ?></td>
<td><?php echo tag('select',array('name'=>'comision_'.$indice),true)?>
<?php foreach ($comisiones as $comision2):?>
<option value="<?php echo $comision2->getId()?>">
<?php echo $comision2->getNombre()." - ".$comision2->getDescripcion()?>
</option>
<?php endforeach?>
</select>
</td>
</tr>
<?php endforeach?>
Run Code Online (Sandbox Code Playgroud)
上面的代码打印:
代码结果http://img440.imageshack.us/img440/7732/res.png
而且我期待看到类似的东西(图像中的组合标签不一样,但我认为这个想法很清楚):
预期结果http://img229.imageshack.us/img229/7969/esperado.png
提前致谢
我有一个Map<A,B> fieldOfCC类的字段.当我尝试用Jackson反序列化C时,会抛出异常,因为它找不到Map的密钥A的反序列化器.所以,我想解决方法是扩展StdJsonDeserializer并执行它手动.
我的问题是我找不到一个关于如何使用解析器和我必须实现的方法"反序列化"的上下文的示例.
任何人都可以为这个简单的例子编写代码,这样我就可以用它作为开始构建我真正的反序列化器吗?
public class A{
private String a1;
private Integer a2;
}
public class B{
private String b1;
}
public class C{
@JsonDeserialize(keyUsing=ADeserializer.class)
//also tried this: @JsonDeserialize(keyAs=A.class) without success
private Map<A,B> fieldOfC;
private String c1;
}
public class ADeserializer extends StdKeyDeserializer {
protected ADeserializer(Class<A> cls) {
super(cls);
}
protected Object _parse(String key, DeserializationContext ctxt) throws Exception {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(key, A.class);
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
编辑:谷歌搜索,我发现了我遇到的同样问题的测试.这正是我的问题
编辑:改变扩展类从StdDeserializer到StdKeyDeserializer当我读到这里的方法 …
我有以下示例:
这是请求正文:
public class UserLoginData
implements Serializable {
private static final long serialVersionUID = 1L;
private String username;
private String password;
//... getter and setters
}
Run Code Online (Sandbox Code Playgroud)
这是控制器:
@RequestMapping(value = {"/login"}, method = RequestMethod.POST)
@ResponseBody
public LoginResponse login(@RequestBody(required = true) UserLoginData loginData){
//... some code
}
Run Code Online (Sandbox Code Playgroud)
这就是我调用服务的方式:
POST /login
{"username":"neuquino"}
Run Code Online (Sandbox Code Playgroud)
我希望Spring返回HTTP 400 BAD REQUEST错误,因为密码丢失了.但不是这样,它返回HTTP 500 INTERNAL SERVER错误,带有以下堆栈跟踪:
java.lang.NullPointerException
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948) ~[spring-webmvc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838) ~[spring-webmvc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)
...
Run Code Online (Sandbox Code Playgroud)
如何向Spring指定用户名和密码是请求正文中的必填字段?
如何将带有下划线的json映射到案例类中的camelCase字段?
import org.json4s.jackson.JsonMethods.parse
import org.json4s.DefaultFormats
object Testing {
implicit val formats = DefaultFormats.withBigDecimal
def test = {
val json = parse("""{"some_field":"a value"}""")
json.extract[ThingDTO]
}
}
case class ThingDTO(someField:String)
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
someField没有可用值没有找到可以转换为java.lang.String的值
嗨,我有以下型号:
@Entity
class Flight{
private Airport airportFrom;
private Airport airportTo;
@OneToOne(fetch=FetchType.LAZY,optional=false)
public Airport getAirportFrom(){
return this.airportFrom;
}
@OneToOne(fetch=FetchType.LAZY,optional=false)
public Airport getAirportTo(){
return this.airportTo;
}
}
@Entity
class Airport{
private Integer airportId;
@Id
public Integer getAirportId(){
this.airportId;
}
}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
org.hibernate.MappingException: Repeated column in mapping for entity: model.entities.Flight column: airportId (should be mapped with insert="false" update="false")
Run Code Online (Sandbox Code Playgroud)