小编Les*_*ova的帖子

java.lang.NoSuchMethodException:userAuth.User.<init>()

我有一个验证类:

public class User {
    @Size(min=3, max=20, message="User name must be between 3 and 20 characters long")
    @Pattern(regexp="^[a-zA-Z0-9]+$", message="User name must be alphanumeric with no spaces")
    private String name;

    @Size(min=6, max=20, message="Password must be between 6 and 20 characters long")
    @Pattern(regexp="^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$", message="Password must contains at least one number")
    private String password;

    public User(String _name, String _password){
        super();
        name = _name;
        password = _password;
    }

    public String getName(){
        return name;
    }

    public String getPassword(){
        return password;
    }

    public void setPassword(String newPassword){ …
Run Code Online (Sandbox Code Playgroud)

java validation spring hibernate-validator

35
推荐指数
4
解决办法
6万
查看次数

即使httpCon.setRequestMethod("GET"),HttpURLConnection也会发送POST请求; 已设定

这是我的代码:

String addr = "http://172.26.41.18:8080/domain/list";

URL url = new URL(addr);
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setDoInput(true);
httpCon.setUseCaches(false);
httpCon.setAllowUserInteraction(false);
httpCon.setRequestMethod("GET");
httpCon.addRequestProperty("Authorization", "Basic YWRtaW4fYFgjkl5463");

httpCon.connect();

OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream());

System.out.println(httpCon.getResponseCode());
System.out.println(httpCon.getResponseMessage());

out.close();
Run Code Online (Sandbox Code Playgroud)

我在回应中看到了什么:

500服务器错误

我打开我的httpConvar,以及我看到的内容:

POST/rest/platform/domain/list HTTP/1.1

为什么它设置为POST,即使我已经习惯httpCon.setRequestMethod("GET");将其设置为GET?

java http urlconnection

28
推荐指数
1
解决办法
3万
查看次数

如何捕获浏览器活动?

我有一个应用程序,它是下一个方式启动浏览器:

 Uri uri = Uri.parse(getURL());
    Context context = widget.getContext();
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    context.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

我有另一个AndroidJUnit项目,我希望在其中捕获该活动.

接下来的步骤,我可以捕获运行浏览器的MYProjectActivity,但我无法捕获浏览器.

 Instrumentation instrumentation = getInstrumentation();

  // Register we are interested in the authentication activiry...
  Instrumentation.ActivityMonitor monitor = instrumentation.addMonitor(MYProjectActivity.class.getName(), null, false);

  // Start the authentication activity as the first activity...
  Intent intent = new Intent(Intent.ACTION_MAIN);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  intent.setClassName(instrumentation.getTargetContext(), MYProjectActivity.class.getName());
  instrumentation.startActivitySync(intent);

  // Wait for it to start...
  Activity currentActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 5);
Run Code Online (Sandbox Code Playgroud)

有人知道怎么做这个吗?

android

6
推荐指数
1
解决办法
592
查看次数

spock测试中的上下文配置

我有这样的Application课:

@Configuration
@EnableAutoConfiguration
@ComponentScan
@ImportResource("classpath:applicationContext.xml")
@EnableJpaRepositories("ibd.jpa")
public class Application {

public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)

我也有UserService课(它被发现 @EnableJpaRepositories("ibd.jpa")):

@RestController
@RequestMapping("/user")
public class UserService {

@Autowired
private UserRepository userRepository;

@RequestMapping(method = RequestMethod.POST)
public User createUser(@RequestParam String login, @RequestParam String password){
    return userRepository.save(new User(login,password));
} 
Run Code Online (Sandbox Code Playgroud)

我试着测试UserService:

@ContextConfiguration
class UserServiceTest extends Specification {

@Autowired
def UserService userService


def "if User not exists 404 status in response sent and corresponding message shown"() { …
Run Code Online (Sandbox Code Playgroud)

java spring spock applicationcontext

6
推荐指数
2
解决办法
6660
查看次数

SOAP 授权

我的肥皂连接代码:

MessageFactory msgFactory     = MessageFactory.newInstance();  
SOAPMessage message           = msgFactory.createMessage();  
String loginPassword = "user:password";
message.getMimeHeaders().addHeader("Authorization", "Basic " + Base64.encode(loginPassword.getBytes()).toString());
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();

// Send SOAP Message to SOAP Server
String url = "http://servername/name1";
SOAPMessage soapResponse = soapConnection.call(message, url);
Run Code Online (Sandbox Code Playgroud)

我总是得到例外:

CAUSE:

com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (401Unauthorized
Run Code Online (Sandbox Code Playgroud)

怎么了?

要求:

        String soapText =  
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
               +"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
               +"<soap:Body>"
               +"<ReceiveOrder xmlns=\"http://url/server/name\">"
               +"<Order xmlns=\"http://url/name\">"
               +"<Order_Number>54321</Order_Number>"
               +"<Order_Date>2013-07-26</Order_Date>"
               +"<Supply_Date>2013-07-27</Supply_Date>"
               +"<Supply_Time>12:00</Supply_Time>"
               +"<Version>1</Version>"
               +"<Autor>????</Autor>"
               +"<Type>B</Type>"
               +"<Supplyer>3032</Supplyer>"
               +"<Mag_Number>138</Mag_Number>"
               +"<Transaction>54321</Transaction>"
               +"<Rows>"
               +"<Row>"
               +"<Row_Number>1</Row_Number>"
               +"<Ware>29</Ware>"
               +"<?ount>10</?ount>" …
Run Code Online (Sandbox Code Playgroud)

java soap

1
推荐指数
1
解决办法
6229
查看次数